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
|
||||
*
|
||||
* @var \PhpOffice\PhpWord\Style\Indentation
|
||||
* @var \PhpOffice\PhpWord\Style\Indentation|null
|
||||
*/
|
||||
private $indentation;
|
||||
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ class Field extends Text
|
|||
|
||||
$type = strtolower($element->getType());
|
||||
switch ($type) {
|
||||
case 'date': // Owen 2020-01-02
|
||||
case 'date':
|
||||
case 'page':
|
||||
case 'numpages':
|
||||
$this->writeDefault($element, $type);
|
||||
|
|
@ -61,7 +61,7 @@ class Field extends Text
|
|||
}
|
||||
}
|
||||
switch ($type) {
|
||||
case 'date': // Owen 2019-01-02
|
||||
case 'date':
|
||||
$xmlWriter->startElement('text:date');
|
||||
$xmlWriter->writeAttribute('text:fixed', 'false');
|
||||
$xmlWriter->endElement();
|
||||
|
|
|
|||
|
|
@ -186,7 +186,8 @@ class Content extends AbstractPart
|
|||
$styleWriter->write();
|
||||
|
||||
$sects = $this->getParentWriter()->getPhpWord()->getSections();
|
||||
for ($i = 0; $i < count($sects); ++$i) {
|
||||
$countsects = count($sects);
|
||||
for ($i = 0; $i < $countsects; ++$i) {
|
||||
$iplus1 = $i + 1;
|
||||
$style = new Paragraph();
|
||||
$style->setStyleName("SB$iplus1");
|
||||
|
|
@ -297,7 +298,7 @@ class Content extends AbstractPart
|
|||
/**
|
||||
* 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 $fontStyleCount
|
||||
*/
|
||||
|
|
@ -331,7 +332,7 @@ class Content extends AbstractPart
|
|||
} else {
|
||||
$element->setParagraphStyle($name);
|
||||
}
|
||||
} elseif (is_string($paragraphStyle)) {
|
||||
} else {
|
||||
$paragraphStyleCount++;
|
||||
$parstylename = "P$paragraphStyleCount" . "_$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
|
||||
*
|
||||
* @param int $twips
|
||||
* @param string $dflt
|
||||
* @param int|float $twips
|
||||
* @param float $factor
|
||||
* 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';
|
||||
$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
|
||||
*/
|
||||
private function writePageLayout(XMLWriter $xmlWriter) // Owen 2019-06-19
|
||||
private function writePageLayout(XMLWriter $xmlWriter)
|
||||
{
|
||||
$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);
|
||||
}
|
||||
}
|
||||
|
|
@ -189,23 +186,13 @@ class Styles extends AbstractPart
|
|||
} else {
|
||||
$botfactor = 1.0;
|
||||
}
|
||||
$pwidth = '21.001cm';
|
||||
$pheight = '29.7cm';
|
||||
$orient = 'portrait';
|
||||
$mtop = $mleft = $mright = '2.501cm';
|
||||
$mbottom = '2cm';
|
||||
if ($sty instanceof \PhpOffice\PhpWord\Style\Section) {
|
||||
$ori = $sty->getOrientation();
|
||||
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);
|
||||
}
|
||||
$orient = $sty->getOrientation();
|
||||
$pwidth = self::cvttwiptostr($sty->getPageSizeW());
|
||||
$pheight = self::cvttwiptostr($sty->getPageSizeH());
|
||||
$mtop = self::cvttwiptostr($sty->getMarginTop(), $topfactor);
|
||||
$mbottom = self::cvttwiptostr($sty->getMarginBottom(), $botfactor);
|
||||
$mleft = self::cvttwiptostr($sty->getMarginRight());
|
||||
$mright = self::cvttwiptostr($sty->getMarginLeft());
|
||||
|
||||
$xmlWriter->startElement('style:page-layout');
|
||||
$xmlWriter->writeAttribute('style:name', "Mpm$sectionNbr");
|
||||
|
|
@ -253,7 +240,7 @@ class Styles extends AbstractPart
|
|||
$xmlWriter->endElement(); // style:header-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->writeAttribute('fo:min-height', $mbottom);
|
||||
$xmlWriter->writeAttribute('fo:margin-top', $mbottom);
|
||||
|
|
@ -275,7 +262,8 @@ class Styles extends AbstractPart
|
|||
$xmlWriter->startElement('office:master-styles');
|
||||
|
||||
$sections = $this->getParentWriter()->getPhpWord()->getSections();
|
||||
for ($i = 0; $i < count($sections); ++$i) {
|
||||
$countsects = count($sections);
|
||||
for ($i = 0; $i < $countsects; ++$i) {
|
||||
$iplus1 = $i + 1;
|
||||
$xmlWriter->startElement('style:master-page');
|
||||
$xmlWriter->writeAttribute('style:name', "Standard$iplus1");
|
||||
|
|
|
|||
|
|
@ -56,9 +56,7 @@ class Paragraph extends AbstractStyle
|
|||
$styleAuto = true;
|
||||
$mpm = 'Standard' . substr($styleName, 2);
|
||||
$psn = $style->getNumLevel();
|
||||
if (is_numeric($psn)) {
|
||||
$pagestart = (int) $psn;
|
||||
}
|
||||
$pagestart = $psn;
|
||||
} elseif (substr($styleName, 0, 2) === 'HD') {
|
||||
$styleAuto = true;
|
||||
$psm = 'Heading_' . substr($styleName, 2);
|
||||
|
|
@ -117,7 +115,7 @@ class Paragraph extends AbstractStyle
|
|||
$xmlWriter->writeAttributeIf($temp !== '', 'fo:text-align', $temp);
|
||||
$temp = $style->getLineHeight();
|
||||
$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();
|
||||
if ($tabs !== null && count($tabs) > 0) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue