Scrutinizer fixes

This commit is contained in:
troosan 2017-11-26 22:55:37 +01:00
parent 23bc837666
commit ca25eba8aa
13 changed files with 45 additions and 33 deletions

13
phpstan.neon Normal file
View File

@ -0,0 +1,13 @@
includes:
- vendor/phpstan/phpstan/conf/config.level1.neon
parameters:
memory-limit: 200000
autoload_directories:
- tests
autoload_files:
- tests/bootstrap.php
excludes_analyse:
- */pclzip.lib.php
- src/PhpWord/Shared/OLERead.php
- src/PhpWord/Reader/MsDoc.php
- src/PhpWord/Writer/PDF/MPDF.php

View File

@ -17,8 +17,6 @@
namespace PhpOffice\PhpWord\Element; namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\Style\Paragraph;
/** /**
* Endnote element * Endnote element
* *
@ -38,6 +36,6 @@ class Endnote extends Footnote
*/ */
public function __construct($paragraphStyle = null) public function __construct($paragraphStyle = null)
{ {
$this->paragraphStyle = $this->setNewStyle(new Paragraph(), $paragraphStyle); parent::__construct($paragraphStyle);
} }
} }

View File

@ -98,7 +98,7 @@ class Field extends AbstractElement
* @param string $type * @param string $type
* @param array $properties * @param array $properties
* @param array $options * @param array $options
* @param TextRun|string $text * @param TextRun|string|null $text
*/ */
public function __construct($type = null, $properties = array(), $options = array(), $text = null) public function __construct($type = null, $properties = array(), $options = array(), $text = null)
{ {
@ -209,7 +209,7 @@ class Field extends AbstractElement
* @param string|TextRun $text * @param string|TextRun $text
* *
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
* @return string|TextRun * @return null|string|TextRun
*/ */
public function setText($text) public function setText($text)
{ {

View File

@ -137,7 +137,7 @@ class Image extends AbstractElement
$this->setIsWatermark($watermark); $this->setIsWatermark($watermark);
$this->style = $this->setNewStyle(new ImageStyle(), $style, true); $this->style = $this->setNewStyle(new ImageStyle(), $style, true);
$this->checkImage($source); $this->checkImage();
} }
/** /**

View File

@ -18,7 +18,6 @@
namespace PhpOffice\PhpWord\Element; namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\Style\ListItem as ListItemStyle; use PhpOffice\PhpWord\Style\ListItem as ListItemStyle;
use PhpOffice\PhpWord\Style\Paragraph;
/** /**
* List item element * List item element
@ -61,7 +60,7 @@ class ListItemRun extends TextRun
} else { } else {
$this->style = $this->setNewStyle(new ListItemStyle(), $listStyle, true); $this->style = $this->setNewStyle(new ListItemStyle(), $listStyle, true);
} }
$this->paragraphStyle = $this->setNewStyle(new Paragraph(), $paragraphStyle); parent::__construct($paragraphStyle);
} }
/** /**

View File

@ -142,7 +142,7 @@ class Section extends AbstractContainer
/** /**
* Get the footnote properties * Get the footnote properties
* *
* @return \PhpOffice\PhpWord\Element\FooterProperties * @return FootnoteProperties
*/ */
public function getFootnotePropoperties() public function getFootnotePropoperties()
{ {

View File

@ -410,7 +410,7 @@ class DocInfo
* Get a Custom Property Value * Get a Custom Property Value
* *
* @param string $propertyName * @param string $propertyName
* @return string * @return mixed
*/ */
public function getCustomPropertyValue($propertyName) public function getCustomPropertyValue($propertyName)
{ {

View File

@ -3790,7 +3790,7 @@ class PclZip
} }
// ----- Write gz file format header // ----- Write gz file format header
$v_binary_data = pack('va1a1Va1a1', 0x8b1f, Chr($p_entry['compression']), Chr(0x00), time(), Chr(0x00), Chr(3)); $v_binary_data = pack('va1a1Va1a1', 0x8b1f, chr($p_entry['compression']), chr(0x00), time(), chr(0x00), chr(3));
@fwrite($v_dest_file, $v_binary_data, 10); @fwrite($v_dest_file, $v_binary_data, 10);
// ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks
@ -4383,7 +4383,7 @@ class PclZip
//$v_bytes = ($v_bytes << 8) | Ord($v_byte); //$v_bytes = ($v_bytes << 8) | Ord($v_byte);
// Note we mask the old value down such that once shifted we can never end up with more than a 32bit number // Note we mask the old value down such that once shifted we can never end up with more than a 32bit number
// Otherwise on systems where we have 64bit integers the check below for the magic number will fail. // Otherwise on systems where we have 64bit integers the check below for the magic number will fail.
$v_bytes = (($v_bytes & 0xFFFFFF) << 8) | Ord($v_byte); $v_bytes = (($v_bytes & 0xFFFFFF) << 8) | ord($v_byte);
// ----- Compare the bytes // ----- Compare the bytes
if ($v_bytes == 0x504b0506) { if ($v_bytes == 0x504b0506) {

View File

@ -40,7 +40,6 @@ class TCPDF extends AbstractRenderer implements WriterInterface
* Save PhpWord to file. * Save PhpWord to file.
* *
* @param string $filename Name of the file to save as * @param string $filename Name of the file to save as
* @return vois
*/ */
public function save($filename = null) public function save($filename = null)
{ {
@ -55,21 +54,21 @@ class TCPDF extends AbstractRenderer implements WriterInterface
$pdf->setFontSubsetting(false); $pdf->setFontSubsetting(false);
$pdf->setPrintHeader(false); $pdf->setPrintHeader(false);
$pdf->setPrintFooter(false); $pdf->setPrintFooter(false);
$pdf->addPage(); $pdf->AddPage();
$pdf->setFont($this->getFont()); $pdf->SetFont($this->getFont());
$pdf->writeHTML($this->getContent()); $pdf->writeHTML($this->getContent());
// Write document properties // Write document properties
$phpWord = $this->getPhpWord(); $phpWord = $this->getPhpWord();
$docProps = $phpWord->getDocInfo(); $docProps = $phpWord->getDocInfo();
$pdf->setTitle($docProps->getTitle()); $pdf->SetTitle($docProps->getTitle());
$pdf->setAuthor($docProps->getCreator()); $pdf->SetAuthor($docProps->getCreator());
$pdf->setSubject($docProps->getSubject()); $pdf->SetSubject($docProps->getSubject());
$pdf->setKeywords($docProps->getKeywords()); $pdf->SetKeywords($docProps->getKeywords());
$pdf->setCreator($docProps->getCreator()); $pdf->SetCreator($docProps->getCreator());
// Write to file // Write to file
fwrite($fileHandle, $pdf->output($filename, 'S')); fwrite($fileHandle, $pdf->Output($filename, 'S'));
parent::restoreStateAfterSave($fileHandle); parent::restoreStateAfterSave($fileHandle);
} }

View File

@ -101,7 +101,7 @@ class SDT extends Text
*/ */
private function writeDropDownList(XMLWriter $xmlWriter, SDTElement $element) private function writeDropDownList(XMLWriter $xmlWriter, SDTElement $element)
{ {
$this->writecomboBox($xmlWriter, $element); $this->writeComboBox($xmlWriter, $element);
} }
/** /**

View File

@ -73,7 +73,7 @@ class ConverterTest extends \PHPUnit\Framework\TestCase
$result = Converter::pixelToPoint($value); $result = Converter::pixelToPoint($value);
$this->assertEquals($value / 96 * 72, $result); $this->assertEquals($value / 96 * 72, $result);
$result = Converter::pixelToEMU($value); $result = Converter::pixelToEmu($value);
$this->assertEquals(round($value * 9525), $result); $this->assertEquals(round($value * 9525), $result);
$result = Converter::pointToTwip($value); $result = Converter::pointToTwip($value);
@ -82,7 +82,7 @@ class ConverterTest extends \PHPUnit\Framework\TestCase
$result = Converter::pointToPixel($value); $result = Converter::pointToPixel($value);
$this->assertEquals($value / 72 * 96, $result); $this->assertEquals($value / 72 * 96, $result);
$result = Converter::pointToEMU($value); $result = Converter::pointToEmu($value);
$this->assertEquals(round($value / 72 * 96 * 9525), $result); $this->assertEquals(round($value / 72 * 96 * 9525), $result);
$result = Converter::emuToPixel($value); $result = Converter::emuToPixel($value);
@ -111,7 +111,7 @@ class ConverterTest extends \PHPUnit\Framework\TestCase
$values[] = array('0F9D', false); // 4 characters $values[] = array('0F9D', false); // 4 characters
// Conduct test // Conduct test
foreach ($values as $value) { foreach ($values as $value) {
$result = Converter::htmlToRGB($value[0]); $result = Converter::htmlToRgb($value[0]);
$this->assertEquals($value[1], $result); $this->assertEquals($value[1], $result);
} }
} }

View File

@ -29,21 +29,21 @@ class NumberingTest extends \PHPUnit\Framework\TestCase
*/ */
public function testGetSetProperties() public function testGetSetProperties()
{ {
$this->object = new Numbering(); $object = new Numbering();
$this->properties = array( $properties = array(
'numId' => array(null, 1), 'numId' => array(null, 1),
'type' => array(null, 'singleLevel'), 'type' => array(null, 'singleLevel'),
); );
foreach ($this->properties as $property => $value) { foreach ($properties as $property => $value) {
list($default, $expected) = $value; list($default, $expected) = $value;
$get = "get{$property}"; $get = "get{$property}";
$set = "set{$property}"; $set = "set{$property}";
$this->assertEquals($default, $this->object->$get()); // Default value $this->assertEquals($default, $object->$get()); // Default value
$this->object->$set($expected); $object->$set($expected);
$this->assertEquals($expected, $this->object->$get()); // New value $this->assertEquals($expected, $object->$get()); // New value
} }
} }
@ -52,8 +52,8 @@ class NumberingTest extends \PHPUnit\Framework\TestCase
*/ */
public function testGetLevels() public function testGetLevels()
{ {
$this->object = new Numbering(); $object = new Numbering();
$this->assertEmpty($this->object->getLevels()); $this->assertEmpty($object->getLevels());
} }
} }

View File

@ -99,6 +99,7 @@ class TableTest extends \PHPUnit\Framework\TestCase
$value = 'FF0000'; $value = 'FF0000';
$object->setBorderColor($value); $object->setBorderColor($value);
$values = array();
foreach ($parts as $part) { foreach ($parts as $part) {
$get = "getBorder{$part}Color"; $get = "getBorder{$part}Color";
$values[] = $value; $values[] = $value;
@ -121,6 +122,7 @@ class TableTest extends \PHPUnit\Framework\TestCase
$value = 4; $value = 4;
$object->setBorderSize($value); $object->setBorderSize($value);
$values = array();
foreach ($parts as $part) { foreach ($parts as $part) {
$get = "getBorder{$part}Size"; $get = "getBorder{$part}Size";
$values[] = $value; $values[] = $value;
@ -143,6 +145,7 @@ class TableTest extends \PHPUnit\Framework\TestCase
$value = 240; $value = 240;
$object->setCellMargin($value); $object->setCellMargin($value);
$values = array();
foreach ($parts as $part) { foreach ($parts as $part) {
$get = "getCellMargin{$part}"; $get = "getCellMargin{$part}";
$values[] = $value; $values[] = $value;