Skip to content

Commit

Permalink
Scrutinizer fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
troosan committed Nov 26, 2017
1 parent 23bc837 commit ca25eba
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 33 deletions.
13 changes: 13 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -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
4 changes: 1 addition & 3 deletions src/PhpWord/Element/Endnote.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

namespace PhpOffice\PhpWord\Element;

use PhpOffice\PhpWord\Style\Paragraph;

/**
* Endnote element
*
Expand All @@ -38,6 +36,6 @@ class Endnote extends Footnote
*/
public function __construct($paragraphStyle = null)
{
$this->paragraphStyle = $this->setNewStyle(new Paragraph(), $paragraphStyle);
parent::__construct($paragraphStyle);
}
}
4 changes: 2 additions & 2 deletions src/PhpWord/Element/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -209,7 +209,7 @@ public function getOptions()
* @param string|TextRun $text
*
* @throws \InvalidArgumentException
* @return string|TextRun
* @return null|string|TextRun
*/
public function setText($text)
{
Expand Down
2 changes: 1 addition & 1 deletion src/PhpWord/Element/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public function __construct($source, $style = null, $watermark = false)
$this->setIsWatermark($watermark);
$this->style = $this->setNewStyle(new ImageStyle(), $style, true);

$this->checkImage($source);
$this->checkImage();
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/PhpWord/Element/ListItemRun.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
namespace PhpOffice\PhpWord\Element;

use PhpOffice\PhpWord\Style\ListItem as ListItemStyle;
use PhpOffice\PhpWord\Style\Paragraph;

/**
* List item element
Expand Down Expand Up @@ -61,7 +60,7 @@ public function __construct($depth = 0, $listStyle = null, $paragraphStyle = nul
} else {
$this->style = $this->setNewStyle(new ListItemStyle(), $listStyle, true);
}
$this->paragraphStyle = $this->setNewStyle(new Paragraph(), $paragraphStyle);
parent::__construct($paragraphStyle);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/PhpWord/Element/Section.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public function getFooters()
/**
* Get the footnote properties
*
* @return \PhpOffice\PhpWord\Element\FooterProperties
* @return FootnoteProperties
*/
public function getFootnotePropoperties()
{
Expand Down
2 changes: 1 addition & 1 deletion src/PhpWord/Metadata/DocInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ public function isCustomPropertySet($propertyName)
* Get a Custom Property Value
*
* @param string $propertyName
* @return string
* @return mixed
*/
public function getCustomPropertyValue($propertyName)
{
Expand Down
4 changes: 2 additions & 2 deletions src/PhpWord/Shared/PCLZip/pclzip.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -3790,7 +3790,7 @@ public function privExtractFileUsingTempFile(&$p_entry, &$p_options)
}

// ----- 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
Expand Down Expand Up @@ -4383,7 +4383,7 @@ public function privReadEndCentralDir(&$p_central_dir)
//$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) {
Expand Down
17 changes: 8 additions & 9 deletions src/PhpWord/Writer/PDF/TCPDF.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -55,21 +54,21 @@ public function save($filename = null)
$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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/PhpWord/Writer/Word2007/Element/SDT.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private function writeComboBox(XMLWriter $xmlWriter, SDTElement $element)
*/
private function writeDropDownList(XMLWriter $xmlWriter, SDTElement $element)
{
$this->writecomboBox($xmlWriter, $element);
$this->writeComboBox($xmlWriter, $element);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions tests/PhpWord/Shared/ConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function testUnitConversions()
$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);
Expand All @@ -82,7 +82,7 @@ public function testUnitConversions()
$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);
Expand Down Expand Up @@ -111,7 +111,7 @@ public function testHtmlToRGB()
$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);
}
}
Expand Down
16 changes: 8 additions & 8 deletions tests/PhpWord/Style/NumberingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand All @@ -52,8 +52,8 @@ public function testGetSetProperties()
*/
public function testGetLevels()
{
$this->object = new Numbering();
$object = new Numbering();

$this->assertEmpty($this->object->getLevels());
$this->assertEmpty($object->getLevels());
}
}
3 changes: 3 additions & 0 deletions tests/PhpWord/Style/TableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public function testBorderColor()

$value = 'FF0000';
$object->setBorderColor($value);
$values = array();
foreach ($parts as $part) {
$get = "getBorder{$part}Color";
$values[] = $value;
Expand All @@ -121,6 +122,7 @@ public function testBorderSize()

$value = 4;
$object->setBorderSize($value);
$values = array();
foreach ($parts as $part) {
$get = "getBorder{$part}Size";
$values[] = $value;
Expand All @@ -143,6 +145,7 @@ public function testCellMargin()

$value = 240;
$object->setCellMargin($value);
$values = array();
foreach ($parts as $part) {
$get = "getCellMargin{$part}";
$values[] = $value;
Expand Down

0 comments on commit ca25eba

Please sign in to comment.