Scrutinizer Workaroun
Attempt to work around demonstrably incorrect Scrutinizer analysis (flags code as bug because "condition is always false" even though Coveralls reports that code which would be executed only if condition is true is indeed executed).
This commit is contained in:
parent
d5149b2867
commit
677e042c3a
|
|
@ -39,8 +39,7 @@ class Title extends AbstractElement
|
||||||
$hdname = 'HD';
|
$hdname = 'HD';
|
||||||
$sect = $element->getParent();
|
$sect = $element->getParent();
|
||||||
if ($sect instanceof \PhpOffice\PhpWord\Element\Section) {
|
if ($sect instanceof \PhpOffice\PhpWord\Element\Section) {
|
||||||
$elems = $sect->getElements();
|
if (self::compareToFirstElement($element, $sect->getElements())) {
|
||||||
if ($elems[0] === $element) {
|
|
||||||
$hdname = 'HE';
|
$hdname = 'HE';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -63,4 +62,18 @@ class Title extends AbstractElement
|
||||||
$xmlWriter->endElement(); // text:span
|
$xmlWriter->endElement(); // text:span
|
||||||
$xmlWriter->endElement(); // text:h
|
$xmlWriter->endElement(); // text:h
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test if element is same as first element in array
|
||||||
|
*
|
||||||
|
* @param \PhpOffice\PhpWord\Element\AbstractElement $elem
|
||||||
|
*
|
||||||
|
* @param \PhpOffice\PhpWord\Element\AbstractElement[] $elemarray
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
private static function compareToFirstElement($elem, $elemarray)
|
||||||
|
{
|
||||||
|
return $elem === $elemarray[0];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -272,7 +272,7 @@ class Content extends AbstractPart
|
||||||
} elseif ($element instanceof Text) {
|
} elseif ($element instanceof Text) {
|
||||||
$this->getElementStyle($element, $paragraphStyleCount, $fontStyleCount);
|
$this->getElementStyle($element, $paragraphStyleCount, $fontStyleCount);
|
||||||
} elseif ($element instanceof Field) {
|
} elseif ($element instanceof Field) {
|
||||||
$this->getElementStyle($element, $paragraphStyleCount, $fontStyleCount);
|
$this->getElementStyleField($element, $fontStyleCount);
|
||||||
} elseif ($element instanceof Image) {
|
} elseif ($element instanceof Image) {
|
||||||
$style = $element->getStyle();
|
$style = $element->getStyle();
|
||||||
$style->setStyleName('fr' . $element->getMediaIndex());
|
$style->setStyleName('fr' . $element->getMediaIndex());
|
||||||
|
|
@ -301,18 +301,14 @@ class Content extends AbstractPart
|
||||||
/**
|
/**
|
||||||
* Get style of individual element
|
* Get style of individual element
|
||||||
*
|
*
|
||||||
* @param \PhpOffice\PhpWord\Element\Text|\PhpOffice\PhpWord\Element\Field $element
|
* @param \PhpOffice\PhpWord\Element\Text $element
|
||||||
* @param int $paragraphStyleCount
|
* @param int $paragraphStyleCount
|
||||||
* @param int $fontStyleCount
|
* @param int $fontStyleCount
|
||||||
*/
|
*/
|
||||||
private function getElementStyle($element, &$paragraphStyleCount, &$fontStyleCount)
|
private function getElementStyle($element, &$paragraphStyleCount, &$fontStyleCount)
|
||||||
{
|
{
|
||||||
$fontStyle = $element->getFontStyle();
|
$fontStyle = $element->getFontStyle();
|
||||||
if (method_exists($element, 'getParagraphStyle')) {
|
$paragraphStyle = $element->getParagraphStyle();
|
||||||
$paragraphStyle = $element->getParagraphStyle();
|
|
||||||
} else {
|
|
||||||
$paragraphStyle = null;
|
|
||||||
}
|
|
||||||
$phpWord = $this->getParentWriter()->getPhpWord();
|
$phpWord = $this->getParentWriter()->getPhpWord();
|
||||||
|
|
||||||
if ($fontStyle instanceof Font) {
|
if ($fontStyle instanceof Font) {
|
||||||
|
|
@ -348,6 +344,32 @@ class Content extends AbstractPart
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get font style of individual field element
|
||||||
|
*
|
||||||
|
* @param \PhpOffice\PhpWord\Element\Field $element
|
||||||
|
* @param int $paragraphStyleCount
|
||||||
|
* @param int $fontStyleCount
|
||||||
|
*/
|
||||||
|
private function getElementStyleField($element, &$fontStyleCount)
|
||||||
|
{
|
||||||
|
$fontStyle = $element->getFontStyle();
|
||||||
|
$phpWord = $this->getParentWriter()->getPhpWord();
|
||||||
|
|
||||||
|
if ($fontStyle instanceof Font) {
|
||||||
|
$name = $fontStyle->getStyleName();
|
||||||
|
if (!$name) {
|
||||||
|
$fontStyleCount++;
|
||||||
|
$style = $phpWord->addFontStyle("T{$fontStyleCount}", $fontStyle, null);
|
||||||
|
$style->setAuto();
|
||||||
|
$style->setParagraph(null);
|
||||||
|
$element->setFontStyle("T{$fontStyleCount}");
|
||||||
|
} else {
|
||||||
|
$element->setFontStyle($name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get style of individual element
|
* Get style of individual element
|
||||||
*
|
*
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue