From ca25eba8aa6b2e07d0d345d2104c21014ccc0e92 Mon Sep 17 00:00:00 2001 From: troosan Date: Sun, 26 Nov 2017 22:55:37 +0100 Subject: [PATCH] Scrutinizer fixes --- phpstan.neon | 13 +++++++++++++ src/PhpWord/Element/Endnote.php | 4 +--- src/PhpWord/Element/Field.php | 4 ++-- src/PhpWord/Element/Image.php | 2 +- src/PhpWord/Element/ListItemRun.php | 3 +-- src/PhpWord/Element/Section.php | 2 +- src/PhpWord/Metadata/DocInfo.php | 2 +- src/PhpWord/Shared/PCLZip/pclzip.lib.php | 4 ++-- src/PhpWord/Writer/PDF/TCPDF.php | 17 ++++++++--------- src/PhpWord/Writer/Word2007/Element/SDT.php | 2 +- tests/PhpWord/Shared/ConverterTest.php | 6 +++--- tests/PhpWord/Style/NumberingTest.php | 16 ++++++++-------- tests/PhpWord/Style/TableTest.php | 3 +++ 13 files changed, 45 insertions(+), 33 deletions(-) create mode 100644 phpstan.neon diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 00000000..5ae6d0f2 --- /dev/null +++ b/phpstan.neon @@ -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 \ No newline at end of file diff --git a/src/PhpWord/Element/Endnote.php b/src/PhpWord/Element/Endnote.php index 6565c039..b6e94fba 100644 --- a/src/PhpWord/Element/Endnote.php +++ b/src/PhpWord/Element/Endnote.php @@ -17,8 +17,6 @@ namespace PhpOffice\PhpWord\Element; -use PhpOffice\PhpWord\Style\Paragraph; - /** * Endnote element * @@ -38,6 +36,6 @@ class Endnote extends Footnote */ public function __construct($paragraphStyle = null) { - $this->paragraphStyle = $this->setNewStyle(new Paragraph(), $paragraphStyle); + parent::__construct($paragraphStyle); } } diff --git a/src/PhpWord/Element/Field.php b/src/PhpWord/Element/Field.php index 4481f16b..6ea63c6b 100644 --- a/src/PhpWord/Element/Field.php +++ b/src/PhpWord/Element/Field.php @@ -98,7 +98,7 @@ class Field extends AbstractElement * @param string $type * @param array $properties * @param array $options - * @param TextRun|string $text + * @param TextRun|string|null $text */ public function __construct($type = null, $properties = array(), $options = array(), $text = null) { @@ -209,7 +209,7 @@ class Field extends AbstractElement * @param string|TextRun $text * * @throws \InvalidArgumentException - * @return string|TextRun + * @return null|string|TextRun */ public function setText($text) { diff --git a/src/PhpWord/Element/Image.php b/src/PhpWord/Element/Image.php index a5bd7283..f1f6bab5 100644 --- a/src/PhpWord/Element/Image.php +++ b/src/PhpWord/Element/Image.php @@ -137,7 +137,7 @@ class Image extends AbstractElement $this->setIsWatermark($watermark); $this->style = $this->setNewStyle(new ImageStyle(), $style, true); - $this->checkImage($source); + $this->checkImage(); } /** diff --git a/src/PhpWord/Element/ListItemRun.php b/src/PhpWord/Element/ListItemRun.php index 5286f662..e311dc24 100644 --- a/src/PhpWord/Element/ListItemRun.php +++ b/src/PhpWord/Element/ListItemRun.php @@ -18,7 +18,6 @@ namespace PhpOffice\PhpWord\Element; use PhpOffice\PhpWord\Style\ListItem as ListItemStyle; -use PhpOffice\PhpWord\Style\Paragraph; /** * List item element @@ -61,7 +60,7 @@ class ListItemRun extends TextRun } else { $this->style = $this->setNewStyle(new ListItemStyle(), $listStyle, true); } - $this->paragraphStyle = $this->setNewStyle(new Paragraph(), $paragraphStyle); + parent::__construct($paragraphStyle); } /** diff --git a/src/PhpWord/Element/Section.php b/src/PhpWord/Element/Section.php index 8238277e..06acf1f9 100644 --- a/src/PhpWord/Element/Section.php +++ b/src/PhpWord/Element/Section.php @@ -142,7 +142,7 @@ class Section extends AbstractContainer /** * Get the footnote properties * - * @return \PhpOffice\PhpWord\Element\FooterProperties + * @return FootnoteProperties */ public function getFootnotePropoperties() { diff --git a/src/PhpWord/Metadata/DocInfo.php b/src/PhpWord/Metadata/DocInfo.php index e5dee659..09714f9e 100644 --- a/src/PhpWord/Metadata/DocInfo.php +++ b/src/PhpWord/Metadata/DocInfo.php @@ -410,7 +410,7 @@ class DocInfo * Get a Custom Property Value * * @param string $propertyName - * @return string + * @return mixed */ public function getCustomPropertyValue($propertyName) { diff --git a/src/PhpWord/Shared/PCLZip/pclzip.lib.php b/src/PhpWord/Shared/PCLZip/pclzip.lib.php index 0a69f687..5620c754 100644 --- a/src/PhpWord/Shared/PCLZip/pclzip.lib.php +++ b/src/PhpWord/Shared/PCLZip/pclzip.lib.php @@ -3790,7 +3790,7 @@ class PclZip } // ----- 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); // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks @@ -4383,7 +4383,7 @@ class PclZip //$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 // 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 if ($v_bytes == 0x504b0506) { diff --git a/src/PhpWord/Writer/PDF/TCPDF.php b/src/PhpWord/Writer/PDF/TCPDF.php index 3b82511a..85e3614c 100644 --- a/src/PhpWord/Writer/PDF/TCPDF.php +++ b/src/PhpWord/Writer/PDF/TCPDF.php @@ -40,7 +40,6 @@ class TCPDF extends AbstractRenderer implements WriterInterface * Save PhpWord to file. * * @param string $filename Name of the file to save as - * @return vois */ public function save($filename = null) { @@ -55,21 +54,21 @@ class TCPDF extends AbstractRenderer implements WriterInterface $pdf->setFontSubsetting(false); $pdf->setPrintHeader(false); $pdf->setPrintFooter(false); - $pdf->addPage(); - $pdf->setFont($this->getFont()); + $pdf->AddPage(); + $pdf->SetFont($this->getFont()); $pdf->writeHTML($this->getContent()); // Write document properties $phpWord = $this->getPhpWord(); $docProps = $phpWord->getDocInfo(); - $pdf->setTitle($docProps->getTitle()); - $pdf->setAuthor($docProps->getCreator()); - $pdf->setSubject($docProps->getSubject()); - $pdf->setKeywords($docProps->getKeywords()); - $pdf->setCreator($docProps->getCreator()); + $pdf->SetTitle($docProps->getTitle()); + $pdf->SetAuthor($docProps->getCreator()); + $pdf->SetSubject($docProps->getSubject()); + $pdf->SetKeywords($docProps->getKeywords()); + $pdf->SetCreator($docProps->getCreator()); // Write to file - fwrite($fileHandle, $pdf->output($filename, 'S')); + fwrite($fileHandle, $pdf->Output($filename, 'S')); parent::restoreStateAfterSave($fileHandle); } diff --git a/src/PhpWord/Writer/Word2007/Element/SDT.php b/src/PhpWord/Writer/Word2007/Element/SDT.php index 8899a1d8..6a202564 100644 --- a/src/PhpWord/Writer/Word2007/Element/SDT.php +++ b/src/PhpWord/Writer/Word2007/Element/SDT.php @@ -101,7 +101,7 @@ class SDT extends Text */ private function writeDropDownList(XMLWriter $xmlWriter, SDTElement $element) { - $this->writecomboBox($xmlWriter, $element); + $this->writeComboBox($xmlWriter, $element); } /** diff --git a/tests/PhpWord/Shared/ConverterTest.php b/tests/PhpWord/Shared/ConverterTest.php index c7e0483d..752b9a8a 100644 --- a/tests/PhpWord/Shared/ConverterTest.php +++ b/tests/PhpWord/Shared/ConverterTest.php @@ -73,7 +73,7 @@ class ConverterTest extends \PHPUnit\Framework\TestCase $result = Converter::pixelToPoint($value); $this->assertEquals($value / 96 * 72, $result); - $result = Converter::pixelToEMU($value); + $result = Converter::pixelToEmu($value); $this->assertEquals(round($value * 9525), $result); $result = Converter::pointToTwip($value); @@ -82,7 +82,7 @@ class ConverterTest extends \PHPUnit\Framework\TestCase $result = Converter::pointToPixel($value); $this->assertEquals($value / 72 * 96, $result); - $result = Converter::pointToEMU($value); + $result = Converter::pointToEmu($value); $this->assertEquals(round($value / 72 * 96 * 9525), $result); $result = Converter::emuToPixel($value); @@ -111,7 +111,7 @@ class ConverterTest extends \PHPUnit\Framework\TestCase $values[] = array('0F9D', false); // 4 characters // Conduct test foreach ($values as $value) { - $result = Converter::htmlToRGB($value[0]); + $result = Converter::htmlToRgb($value[0]); $this->assertEquals($value[1], $result); } } diff --git a/tests/PhpWord/Style/NumberingTest.php b/tests/PhpWord/Style/NumberingTest.php index 0103c503..4ec12366 100644 --- a/tests/PhpWord/Style/NumberingTest.php +++ b/tests/PhpWord/Style/NumberingTest.php @@ -29,21 +29,21 @@ class NumberingTest extends \PHPUnit\Framework\TestCase */ public function testGetSetProperties() { - $this->object = new Numbering(); - $this->properties = array( + $object = new Numbering(); + $properties = array( 'numId' => array(null, 1), 'type' => array(null, 'singleLevel'), ); - foreach ($this->properties as $property => $value) { + foreach ($properties as $property => $value) { list($default, $expected) = $value; $get = "get{$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() { - $this->object = new Numbering(); + $object = new Numbering(); - $this->assertEmpty($this->object->getLevels()); + $this->assertEmpty($object->getLevels()); } } diff --git a/tests/PhpWord/Style/TableTest.php b/tests/PhpWord/Style/TableTest.php index ff813927..2d57b1b8 100644 --- a/tests/PhpWord/Style/TableTest.php +++ b/tests/PhpWord/Style/TableTest.php @@ -99,6 +99,7 @@ class TableTest extends \PHPUnit\Framework\TestCase $value = 'FF0000'; $object->setBorderColor($value); + $values = array(); foreach ($parts as $part) { $get = "getBorder{$part}Color"; $values[] = $value; @@ -121,6 +122,7 @@ class TableTest extends \PHPUnit\Framework\TestCase $value = 4; $object->setBorderSize($value); + $values = array(); foreach ($parts as $part) { $get = "getBorder{$part}Size"; $values[] = $value; @@ -143,6 +145,7 @@ class TableTest extends \PHPUnit\Framework\TestCase $value = 240; $object->setCellMargin($value); + $values = array(); foreach ($parts as $part) { $get = "getCellMargin{$part}"; $values[] = $value;