Applying Scrutinizer Suggestions
I do not understand one suggestion, and I believe one is wrong. I will add comments to my ticket once this is pushed. One that I can discuss up front PhpWord/Style/Paragraph indicates that Indentation must be of type \PhpOffice\PhpWord\Style\Indentation, but it can also be null. My test for instanceof ... is one of the Scrutinizer reports. I did not change PhpWord/Style/Paragraph, but this commit does so by updating @var for indentation.
This commit is contained in:
parent
e24b2e1ba7
commit
cfa29cc1c2
|
|
@ -85,7 +85,7 @@ class Paragraph extends Border
|
||||||
/**
|
/**
|
||||||
* Indentation
|
* Indentation
|
||||||
*
|
*
|
||||||
* @var \PhpOffice\PhpWord\Style\Indentation
|
* @var \PhpOffice\PhpWord\Style\Indentation|null
|
||||||
*/
|
*/
|
||||||
private $indentation;
|
private $indentation;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ class Field extends Text
|
||||||
|
|
||||||
$type = strtolower($element->getType());
|
$type = strtolower($element->getType());
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
case 'date': // Owen 2020-01-02
|
case 'date':
|
||||||
case 'page':
|
case 'page':
|
||||||
case 'numpages':
|
case 'numpages':
|
||||||
$this->writeDefault($element, $type);
|
$this->writeDefault($element, $type);
|
||||||
|
|
@ -61,7 +61,7 @@ class Field extends Text
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
case 'date': // Owen 2019-01-02
|
case 'date':
|
||||||
$xmlWriter->startElement('text:date');
|
$xmlWriter->startElement('text:date');
|
||||||
$xmlWriter->writeAttribute('text:fixed', 'false');
|
$xmlWriter->writeAttribute('text:fixed', 'false');
|
||||||
$xmlWriter->endElement();
|
$xmlWriter->endElement();
|
||||||
|
|
|
||||||
|
|
@ -186,7 +186,8 @@ class Content extends AbstractPart
|
||||||
$styleWriter->write();
|
$styleWriter->write();
|
||||||
|
|
||||||
$sects = $this->getParentWriter()->getPhpWord()->getSections();
|
$sects = $this->getParentWriter()->getPhpWord()->getSections();
|
||||||
for ($i = 0; $i < count($sects); ++$i) {
|
$countsects = count($sects);
|
||||||
|
for ($i = 0; $i < $countsects; ++$i) {
|
||||||
$iplus1 = $i + 1;
|
$iplus1 = $i + 1;
|
||||||
$style = new Paragraph();
|
$style = new Paragraph();
|
||||||
$style->setStyleName("SB$iplus1");
|
$style->setStyleName("SB$iplus1");
|
||||||
|
|
@ -297,7 +298,7 @@ class Content extends AbstractPart
|
||||||
/**
|
/**
|
||||||
* Get style of individual element
|
* Get style of individual element
|
||||||
*
|
*
|
||||||
* @param \PhpOffice\PhpWord\Element\Text $element
|
* @param \PhpOffice\PhpWord\Element\Text|\PhpOffice\PhpWord\Element\TextRun $element
|
||||||
* @param int $paragraphStyleCount
|
* @param int $paragraphStyleCount
|
||||||
* @param int $fontStyleCount
|
* @param int $fontStyleCount
|
||||||
*/
|
*/
|
||||||
|
|
@ -331,7 +332,7 @@ class Content extends AbstractPart
|
||||||
} else {
|
} else {
|
||||||
$element->setParagraphStyle($name);
|
$element->setParagraphStyle($name);
|
||||||
}
|
}
|
||||||
} elseif (is_string($paragraphStyle)) {
|
} else {
|
||||||
$paragraphStyleCount++;
|
$paragraphStyleCount++;
|
||||||
$parstylename = "P$paragraphStyleCount" . "_$paragraphStyle";
|
$parstylename = "P$paragraphStyleCount" . "_$paragraphStyle";
|
||||||
$style = $phpWord->addParagraphStyle($parstylename, $paragraphStyle);
|
$style = $phpWord->addParagraphStyle($parstylename, $paragraphStyle);
|
||||||
|
|
|
||||||
|
|
@ -140,16 +140,12 @@ class Styles extends AbstractPart
|
||||||
/**
|
/**
|
||||||
* Convert int in twips to inches/cm then to string and append unit
|
* Convert int in twips to inches/cm then to string and append unit
|
||||||
*
|
*
|
||||||
* @param int $twips
|
* @param int|float $twips
|
||||||
* @param string $dflt
|
|
||||||
* @param float $factor
|
* @param float $factor
|
||||||
* return string
|
* return string
|
||||||
*/
|
*/
|
||||||
private static function cvttwiptostr($twips, $dflt, $factor = 1.0) // Owen 2019-08-06
|
private static function cvttwiptostr($twips, $factor = 1.0)
|
||||||
{
|
{
|
||||||
if ($twips === null) {
|
|
||||||
return $dflt;
|
|
||||||
}
|
|
||||||
$ins = (string) ($twips * $factor / Converter::INCH_TO_TWIP) . 'in';
|
$ins = (string) ($twips * $factor / Converter::INCH_TO_TWIP) . 'in';
|
||||||
$cms = (string) ($twips * $factor * Converter::INCH_TO_CM / Converter::INCH_TO_TWIP) . 'cm';
|
$cms = (string) ($twips * $factor * Converter::INCH_TO_CM / Converter::INCH_TO_TWIP) . 'cm';
|
||||||
|
|
||||||
|
|
@ -161,10 +157,11 @@ class Styles extends AbstractPart
|
||||||
*
|
*
|
||||||
* @param \PhpOffice\Common\XMLWriter $xmlWriter
|
* @param \PhpOffice\Common\XMLWriter $xmlWriter
|
||||||
*/
|
*/
|
||||||
private function writePageLayout(XMLWriter $xmlWriter) // Owen 2019-06-19
|
private function writePageLayout(XMLWriter $xmlWriter)
|
||||||
{
|
{
|
||||||
$sections = $this->getParentWriter()->getPhpWord()->getSections();
|
$sections = $this->getParentWriter()->getPhpWord()->getSections();
|
||||||
for ($i = 0; $i < count($sections); ++$i) {
|
$countsects = count($sections);
|
||||||
|
for ($i = 0; $i < $countsects; ++$i) {
|
||||||
$this->writePageLayoutIndiv($xmlWriter, $sections[$i], $i + 1);
|
$this->writePageLayoutIndiv($xmlWriter, $sections[$i], $i + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -189,23 +186,13 @@ class Styles extends AbstractPart
|
||||||
} else {
|
} else {
|
||||||
$botfactor = 1.0;
|
$botfactor = 1.0;
|
||||||
}
|
}
|
||||||
$pwidth = '21.001cm';
|
$orient = $sty->getOrientation();
|
||||||
$pheight = '29.7cm';
|
$pwidth = self::cvttwiptostr($sty->getPageSizeW());
|
||||||
$orient = 'portrait';
|
$pheight = self::cvttwiptostr($sty->getPageSizeH());
|
||||||
$mtop = $mleft = $mright = '2.501cm';
|
$mtop = self::cvttwiptostr($sty->getMarginTop(), $topfactor);
|
||||||
$mbottom = '2cm';
|
$mbottom = self::cvttwiptostr($sty->getMarginBottom(), $botfactor);
|
||||||
if ($sty instanceof \PhpOffice\PhpWord\Style\Section) {
|
$mleft = self::cvttwiptostr($sty->getMarginRight());
|
||||||
$ori = $sty->getOrientation();
|
$mright = self::cvttwiptostr($sty->getMarginLeft());
|
||||||
if ($ori !== null) {
|
|
||||||
$orient = $ori;
|
|
||||||
}
|
|
||||||
$pwidth = self::cvttwiptostr($sty->getPageSizeW(), $pwidth);
|
|
||||||
$pheight = self::cvttwiptostr($sty->getPageSizeH(), $pheight);
|
|
||||||
$mtop = self::cvttwiptostr($sty->getMarginTop(), $mtop, $topfactor);
|
|
||||||
$mbottom = self::cvttwiptostr($sty->getMarginBottom(), $mbottom, $botfactor);
|
|
||||||
$mleft = self::cvttwiptostr($sty->getMarginRight(), $mleft);
|
|
||||||
$mright = self::cvttwiptostr($sty->getMarginLeft(), $mright);
|
|
||||||
}
|
|
||||||
|
|
||||||
$xmlWriter->startElement('style:page-layout');
|
$xmlWriter->startElement('style:page-layout');
|
||||||
$xmlWriter->writeAttribute('style:name', "Mpm$sectionNbr");
|
$xmlWriter->writeAttribute('style:name', "Mpm$sectionNbr");
|
||||||
|
|
@ -253,7 +240,7 @@ class Styles extends AbstractPart
|
||||||
$xmlWriter->endElement(); // style:header-style
|
$xmlWriter->endElement(); // style:header-style
|
||||||
|
|
||||||
$xmlWriter->startElement('style:footer-style');
|
$xmlWriter->startElement('style:footer-style');
|
||||||
if ($botfactor < 1.0) { // Owen 2019-08-03
|
if ($botfactor < 1.0) {
|
||||||
$xmlWriter->startElement('style:header-footer-properties');
|
$xmlWriter->startElement('style:header-footer-properties');
|
||||||
$xmlWriter->writeAttribute('fo:min-height', $mbottom);
|
$xmlWriter->writeAttribute('fo:min-height', $mbottom);
|
||||||
$xmlWriter->writeAttribute('fo:margin-top', $mbottom);
|
$xmlWriter->writeAttribute('fo:margin-top', $mbottom);
|
||||||
|
|
@ -275,7 +262,8 @@ class Styles extends AbstractPart
|
||||||
$xmlWriter->startElement('office:master-styles');
|
$xmlWriter->startElement('office:master-styles');
|
||||||
|
|
||||||
$sections = $this->getParentWriter()->getPhpWord()->getSections();
|
$sections = $this->getParentWriter()->getPhpWord()->getSections();
|
||||||
for ($i = 0; $i < count($sections); ++$i) {
|
$countsects = count($sections);
|
||||||
|
for ($i = 0; $i < $countsects; ++$i) {
|
||||||
$iplus1 = $i + 1;
|
$iplus1 = $i + 1;
|
||||||
$xmlWriter->startElement('style:master-page');
|
$xmlWriter->startElement('style:master-page');
|
||||||
$xmlWriter->writeAttribute('style:name', "Standard$iplus1");
|
$xmlWriter->writeAttribute('style:name', "Standard$iplus1");
|
||||||
|
|
|
||||||
|
|
@ -56,9 +56,7 @@ class Paragraph extends AbstractStyle
|
||||||
$styleAuto = true;
|
$styleAuto = true;
|
||||||
$mpm = 'Standard' . substr($styleName, 2);
|
$mpm = 'Standard' . substr($styleName, 2);
|
||||||
$psn = $style->getNumLevel();
|
$psn = $style->getNumLevel();
|
||||||
if (is_numeric($psn)) {
|
$pagestart = $psn;
|
||||||
$pagestart = (int) $psn;
|
|
||||||
}
|
|
||||||
} elseif (substr($styleName, 0, 2) === 'HD') {
|
} elseif (substr($styleName, 0, 2) === 'HD') {
|
||||||
$styleAuto = true;
|
$styleAuto = true;
|
||||||
$psm = 'Heading_' . substr($styleName, 2);
|
$psm = 'Heading_' . substr($styleName, 2);
|
||||||
|
|
@ -117,7 +115,7 @@ class Paragraph extends AbstractStyle
|
||||||
$xmlWriter->writeAttributeIf($temp !== '', 'fo:text-align', $temp);
|
$xmlWriter->writeAttributeIf($temp !== '', 'fo:text-align', $temp);
|
||||||
$temp = $style->getLineHeight();
|
$temp = $style->getLineHeight();
|
||||||
$xmlWriter->writeAttributeIf($temp !== null, 'fo:line-height', ((string) ($temp * 100) . '%'));
|
$xmlWriter->writeAttributeIf($temp !== null, 'fo:line-height', ((string) ($temp * 100) . '%'));
|
||||||
$xmlWriter->writeAttributeIf($style->getPageBreakBefore() === true, 'fo:break-before', 'page');
|
$xmlWriter->writeAttributeIf($style->hasPageBreakBefore() === true, 'fo:break-before', 'page');
|
||||||
|
|
||||||
$tabs = $style->getTabs();
|
$tabs = $style->getTabs();
|
||||||
if ($tabs !== null && count($tabs) > 0) {
|
if ($tabs !== null && count($tabs) > 0) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue