diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 6f982d8e89..c8fe57cf63 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -15,7 +15,7 @@ tools: ruleset: phpmd.xml.dist external_code_coverage: enabled: true - timeout: 900 + timeout: 1200 php_cpd: true # php_sim: # Temporarily disabled to allow focus on things other than duplicates # min_mass: 40 diff --git a/.travis.yml b/.travis.yml index 0ec84081e1..d63b7bb22c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,14 +9,14 @@ php: - 5.6 - 7.0 - 7.1 + - 7.2 matrix: include: - php: 5.6 env: COVERAGE=1 allow_failures: - - php: 7.0 - - php: 7.1 + - php: 7.2 cache: directories: diff --git a/CHANGELOG.md b/CHANGELOG.md index 47567dfcad..93945189a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,10 +3,10 @@ Change Log All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). -v0.14.0 (28 Dec 2017) +v0.14.0 (29 Dec 2017) ---------------------- This release fixes several bugs and adds some new features. -This is the last version to support PHP 5.3 +This version brings compatibility with PHP 7.0 & 7.1 ### Added - Possibility to control the footnote numbering - @troosan #1068 diff --git a/composer.json b/composer.json index 2774ad98a9..3cc4b131cf 100644 --- a/composer.json +++ b/composer.json @@ -46,23 +46,22 @@ ] }, "require": { - "php": ">=5.3.3", + "php": "^5.3.3 || ^7.0", "ext-xml": "*", "zendframework/zend-escaper": "^2.2", "zendframework/zend-stdlib": "^2.2 || ^3.0", "phpoffice/common": "^0.2" }, "require-dev": { - "phpunit/phpunit": "^4.8.36", + "phpunit/phpunit": "^4.8.36 || ^5.0", "phpdocumentor/phpdocumentor":"2.*", - "twig/twig":"1.27", "squizlabs/php_codesniffer": "^2.7", "friendsofphp/php-cs-fixer": "^2.0", "phpmd/phpmd": "2.*", - "phploc/phploc": "2.*", + "phploc/phploc": "2.* || 3.* || 4.*", "dompdf/dompdf":"0.8.*", "tecnickcom/tcpdf": "6.*", - "mpdf/mpdf": "5.*" + "mpdf/mpdf": "5.* || 6.* || 7.*" }, "suggest": { "ext-zip": "Allows writing OOXML and ODF", diff --git a/docs/ISSUE_TEMPLATE.md b/docs/ISSUE_TEMPLATE.md index 58981f8eca..ee811b00a4 100644 --- a/docs/ISSUE_TEMPLATE.md +++ b/docs/ISSUE_TEMPLATE.md @@ -1,28 +1,35 @@ -Issue tracker is **ONLY** used for reporting bugs. NO NEW FEATURE ACCEPTED! Use [stackoverflow](https://stackoverflow.com/questions/tagged/phpword) for supporting issues. +This is: + +- [ ] a bug report +- [ ] a feature request +- [ ] **not** a usage question (ask them on https://stackoverflow.com/questions/tagged/phpword) # Expected Behavior Please describe the behavior you are expecting. -# Current Behavior +### Current Behavior What is the current behavior? -# Failure Information +### Failure Information Please help provide information about the failure. -## How to Reproduce +### How to Reproduce Please provide a code sample that reproduces the issue. ```php +addSection(); $section->... ``` -## Context +### Context * PHP version: * PHPWord version: 0.14 diff --git a/docs/PULL_REQUEST_TEMPLATE.md b/docs/PULL_REQUEST_TEMPLATE.md index ad9788c436..cff513a356 100644 --- a/docs/PULL_REQUEST_TEMPLATE.md +++ b/docs/PULL_REQUEST_TEMPLATE.md @@ -1,12 +1,11 @@ -# Description +### Description Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. Fixes # (issue) -# Checklist: +### Checklist: -- [ ] I have commented my code, particularly in hard-to-understand areas -- [ ] I have run phpunit, phpcs, php-cs-fixer, phpmd +- [ ] I have run `composer check` and no errors were reported - [ ] The new code is covered by unit tests - [ ] I have update the documentation to describe the changes diff --git a/run_tests.sh b/run_tests.sh deleted file mode 100755 index a5d94259b8..0000000000 --- a/run_tests.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash -echo "Running composer update" -composer update - -## PHP_CodeSniffer -echo "Running CodeSniffer" -./vendor/bin/phpcs src/ tests/ --standard=PSR2 -n --ignore=src/PhpWord/Shared/PCLZip - -## PHP-CS-Fixer -echo "Running CS Fixer" -./vendor/bin/php-cs-fixer fix --diff --verbose --dry-run - -## PHP Mess Detector -echo "Running Mess Detector" -./vendor/bin/phpmd src/,tests/ text ./phpmd.xml.dist --exclude pclzip.lib.php - -## PHPUnit -echo "Running PHPUnit" -./vendor/bin/phpunit -c ./ - diff --git a/src/PhpWord/Element/AbstractElement.php b/src/PhpWord/Element/AbstractElement.php index 81e185289d..a65c50f4d2 100644 --- a/src/PhpWord/Element/AbstractElement.php +++ b/src/PhpWord/Element/AbstractElement.php @@ -228,7 +228,7 @@ public function setElementIndex($value) /** * Get element unique ID * - * @return int + * @return string */ public function getElementId() { @@ -425,18 +425,18 @@ protected function setNewStyle($styleObject, $styleValue = null, $returnObject = /** * Set enum value * - * @param mixed $value - * @param array $enum - * @param mixed $default + * @param string|null $value + * @param string[] $enum + * @param string|null $default * * @throws \InvalidArgumentException - * @return mixed + * @return string|null * * @todo Merge with the same method in AbstractStyle */ protected function setEnumVal($value = null, $enum = array(), $default = null) { - if ($value != null && trim($value) != '' && !empty($enum) && !in_array($value, $enum)) { + if ($value !== null && trim($value) != '' && !empty($enum) && !in_array($value, $enum)) { throw new \InvalidArgumentException("Invalid style value: {$value}"); } elseif ($value === null || trim($value) == '') { $value = $default; diff --git a/src/PhpWord/Element/Field.php b/src/PhpWord/Element/Field.php index 6ea63c6b68..7b33a4799d 100644 --- a/src/PhpWord/Element/Field.php +++ b/src/PhpWord/Element/Field.php @@ -211,7 +211,7 @@ public function getOptions() * @throws \InvalidArgumentException * @return null|string|TextRun */ - public function setText($text) + public function setText($text = null) { if (isset($text)) { if (is_string($text) || $text instanceof TextRun) { diff --git a/src/PhpWord/Element/TrackChange.php b/src/PhpWord/Element/TrackChange.php index d14fc201db..44327f263f 100644 --- a/src/PhpWord/Element/TrackChange.php +++ b/src/PhpWord/Element/TrackChange.php @@ -52,8 +52,6 @@ public function __construct($author, \DateTime $date = null) { $this->author = $author; $this->date = $date; - - return $this; } /** diff --git a/src/PhpWord/Metadata/Protection.php b/src/PhpWord/Metadata/Protection.php index 35391cb20b..39ebc3dead 100644 --- a/src/PhpWord/Metadata/Protection.php +++ b/src/PhpWord/Metadata/Protection.php @@ -182,7 +182,7 @@ public function getSalt() /** * Set salt. Salt HAS to be 16 characters, or an exception will be thrown. * - * @param $salt + * @param string $salt * @throws \InvalidArgumentException * @return self */ diff --git a/src/PhpWord/Reader/Word2007/Settings.php b/src/PhpWord/Reader/Word2007/Settings.php index c116425ef3..ccdbed2542 100644 --- a/src/PhpWord/Reader/Word2007/Settings.php +++ b/src/PhpWord/Reader/Word2007/Settings.php @@ -152,7 +152,7 @@ protected function setRevisionView(XMLReader $xmlReader, PhpWord $phpWord, \DOME $revisionView = new TrackChangesView(); $revisionView->setMarkup(filter_var($xmlReader->getAttribute('w:markup', $node), FILTER_VALIDATE_BOOLEAN)); $revisionView->setComments($xmlReader->getAttribute('w:comments', $node)); - $revisionView->setInsDel($xmlReader->getAttribute('w:insDel', $node)); + $revisionView->setInsDel(filter_var($xmlReader->getAttribute('w:insDel', $node), FILTER_VALIDATE_BOOLEAN)); $revisionView->setFormatting(filter_var($xmlReader->getAttribute('w:formatting', $node), FILTER_VALIDATE_BOOLEAN)); $revisionView->setInkAnnotations(filter_var($xmlReader->getAttribute('w:inkAnnotations', $node), FILTER_VALIDATE_BOOLEAN)); $phpWord->getSettings()->setRevisionView($revisionView); diff --git a/src/PhpWord/Shared/Converter.php b/src/PhpWord/Shared/Converter.php index bae8985d37..56687c986a 100644 --- a/src/PhpWord/Shared/Converter.php +++ b/src/PhpWord/Shared/Converter.php @@ -33,7 +33,7 @@ class Converter /** * Convert centimeter to twip * - * @param int $centimeter + * @param float $centimeter * @return float */ public static function cmToTwip($centimeter = 1) @@ -44,7 +44,7 @@ public static function cmToTwip($centimeter = 1) /** * Convert centimeter to inch * - * @param int $centimeter + * @param float $centimeter * @return float */ public static function cmToInch($centimeter = 1) @@ -55,7 +55,7 @@ public static function cmToInch($centimeter = 1) /** * Convert centimeter to pixel * - * @param int $centimeter + * @param float $centimeter * @return float */ public static function cmToPixel($centimeter = 1) @@ -66,7 +66,7 @@ public static function cmToPixel($centimeter = 1) /** * Convert centimeter to point * - * @param int $centimeter + * @param float $centimeter * @return float */ public static function cmToPoint($centimeter = 1) @@ -77,8 +77,8 @@ public static function cmToPoint($centimeter = 1) /** * Convert centimeter to EMU * - * @param int $centimeter - * @return int + * @param float $centimeter + * @return float */ public static function cmToEmu($centimeter = 1) { @@ -88,8 +88,8 @@ public static function cmToEmu($centimeter = 1) /** * Convert inch to twip * - * @param int $inch - * @return int + * @param float $inch + * @return float */ public static function inchToTwip($inch = 1) { @@ -99,7 +99,7 @@ public static function inchToTwip($inch = 1) /** * Convert inch to centimeter * - * @param int $inch + * @param float $inch * @return float */ public static function inchToCm($inch = 1) @@ -110,8 +110,8 @@ public static function inchToCm($inch = 1) /** * Convert inch to pixel * - * @param int $inch - * @return int + * @param float $inch + * @return float */ public static function inchToPixel($inch = 1) { @@ -121,8 +121,8 @@ public static function inchToPixel($inch = 1) /** * Convert inch to point * - * @param int $inch - * @return int + * @param float $inch + * @return float */ public static function inchToPoint($inch = 1) { @@ -132,8 +132,8 @@ public static function inchToPoint($inch = 1) /** * Convert inch to EMU * - * @param int $inch - * @return int + * @param float $inch + * @return float */ public static function inchToEmu($inch = 1) { @@ -144,7 +144,7 @@ public static function inchToEmu($inch = 1) * Convert pixel to twip * * @param int $pixel - * @return int + * @return float */ public static function pixelToTwip($pixel = 1) { @@ -188,7 +188,7 @@ public static function pixelToEmu($pixel = 1) * Convert point to twip unit * * @param int $point - * @return int + * @return float */ public static function pointToTwip($point = 1) { @@ -210,7 +210,7 @@ public static function pointToPixel($point = 1) * Convert point to EMU * * @param int $point - * @return int + * @return float */ public static function pointToEmu($point = 1) { @@ -221,7 +221,7 @@ public static function pointToEmu($point = 1) * Convert EMU to pixel * * @param int $emu - * @return int + * @return float */ public static function emuToPixel($emu = 1) { diff --git a/src/PhpWord/Shared/Html.php b/src/PhpWord/Shared/Html.php index 8310e515c2..d8a10b5702 100644 --- a/src/PhpWord/Shared/Html.php +++ b/src/PhpWord/Shared/Html.php @@ -518,6 +518,7 @@ private static function parseStyle($attribute, $styles) private static function parseImage($node, $element) { $style = array(); + $src = null; foreach ($node->attributes as $attribute) { switch ($attribute->name) { case 'src': diff --git a/src/PhpWord/Shared/Microsoft/PasswordEncoder.php b/src/PhpWord/Shared/Microsoft/PasswordEncoder.php index d3a03d9740..1c7b4c6c8e 100644 --- a/src/PhpWord/Shared/Microsoft/PasswordEncoder.php +++ b/src/PhpWord/Shared/Microsoft/PasswordEncoder.php @@ -165,7 +165,7 @@ private static function getAlgorithm($algorithmName) /** * Returns the algorithm ID * - * @param sting $algorithmName + * @param string $algorithmName * @return int */ public static function getAlgorithmId($algorithmName) diff --git a/src/PhpWord/Shared/ZipArchive.php b/src/PhpWord/Shared/ZipArchive.php index bb42a92aff..3d8d0a4133 100644 --- a/src/PhpWord/Shared/ZipArchive.php +++ b/src/PhpWord/Shared/ZipArchive.php @@ -161,7 +161,7 @@ public function close() { if (!$this->usePclzip) { if ($this->zip->close() === false) { - throw new Exception("Could not close zip file {$this->filename}."); + throw new Exception("Could not close zip file {$this->filename}: "); } } diff --git a/src/PhpWord/Style/Paper.php b/src/PhpWord/Style/Paper.php index 2fbf59d282..09e4769e90 100644 --- a/src/PhpWord/Style/Paper.php +++ b/src/PhpWord/Style/Paper.php @@ -118,14 +118,14 @@ class Paper extends AbstractStyle /** * Width * - * @var int (twip) + * @var float (twip) */ private $width; /** * Height * - * @var int (twip) + * @var float (twip) */ private $height; @@ -175,7 +175,7 @@ public function setSize($size) /** * Get width * - * @return int + * @return float */ public function getWidth() { @@ -185,7 +185,7 @@ public function getWidth() /** * Get height * - * @return int + * @return float */ public function getHeight() { diff --git a/src/PhpWord/Writer/PDF/MPDF.php b/src/PhpWord/Writer/PDF/MPDF.php index 80c2eccf90..e238057b1f 100644 --- a/src/PhpWord/Writer/PDF/MPDF.php +++ b/src/PhpWord/Writer/PDF/MPDF.php @@ -17,6 +17,8 @@ namespace PhpOffice\PhpWord\Writer\PDF; +use PhpOffice\PhpWord\PhpWord; +use PhpOffice\PhpWord\Settings; use PhpOffice\PhpWord\Writer\WriterInterface; /** @@ -27,12 +29,14 @@ */ class MPDF extends AbstractRenderer implements WriterInterface { - /** - * Name of renderer include file - * - * @var string - */ - protected $includeFile = 'mpdf.php'; + public function __construct(PhpWord $phpWord) + { + if (file_exists(Settings::getPdfRendererPath() . '/mpdf.php')) { + // MPDF version 5.* needs this file to be included, later versions not + $this->includeFile = 'mpdf.php'; + } + parent::__construct($phpWord); + } /** * Save PhpWord to file. @@ -48,7 +52,13 @@ public function save($filename = null) $orientation = strtoupper('portrait'); // Create PDF - $pdf = new \mpdf(); + if ($this->includeFile != null) { + // MPDF version 5.* + $pdf = new \mpdf(); + } else { + // MPDF version > 6.* + $pdf = new \Mpdf\Mpdf(); + } $pdf->_setPageSize($paperSize, $orientation); $pdf->addPage($orientation); diff --git a/src/PhpWord/Writer/Word2007/Part/Comments.php b/src/PhpWord/Writer/Word2007/Part/Comments.php index 4551ca921e..2b8f9267a2 100644 --- a/src/PhpWord/Writer/Word2007/Part/Comments.php +++ b/src/PhpWord/Writer/Word2007/Part/Comments.php @@ -29,7 +29,7 @@ class Comments extends AbstractPart /** * Comments collection to be written * - * @var \PhpOffice\PhpWord\Collection\Comments + * @var \PhpOffice\PhpWord\Element\Comment[] */ protected $elements; @@ -92,7 +92,7 @@ protected function writeComment(XMLWriter $xmlWriter, Comment $comment) /** * Set element * - * @param \PhpOffice\PhpWord\Collection\Comments $elements + * @param \PhpOffice\PhpWord\Element\Comment[] $elements * @return self */ public function setElements($elements) diff --git a/tests/PhpWord/Shared/ZipArchiveTest.php b/tests/PhpWord/Shared/ZipArchiveTest.php index 91f0f030b1..cb095127a6 100644 --- a/tests/PhpWord/Shared/ZipArchiveTest.php +++ b/tests/PhpWord/Shared/ZipArchiveTest.php @@ -27,34 +27,34 @@ */ class ZipArchiveTest extends \PHPUnit\Framework\TestCase { - /** - * Test close method exception: Working in local, not working in Travis - * - * expectedException \PhpOffice\PhpWord\Exception\Exception - * expectedExceptionMessage Could not close zip file - * covers ::close - */ - public function testCloseException() - { - // $zipFile = __DIR__ . "/../_files/documents/ziptest.zip"; - - // $object = new ZipArchive(); - // $object->open($zipFile, ZipArchive::CREATE); - // $object->addFromString('content/string.txt', 'Test'); - - // // Lock the file - // $resource = fopen($zipFile, "w"); - // flock($resource, LOCK_EX); - - // // Closing the file should throws an exception - // $object->close(); - - // // Unlock the file - // flock($resource, LOCK_UN); - // fclose($resource); - - // @unlink($zipFile); - } +// /** +// * Test close method exception: Working in local, not working in Travis +// * +// * expectedException \PhpOffice\PhpWord\Exception\Exception +// * expectedExceptionMessage Could not close zip file +// * covers ::close +// */ +// public function testCloseException() +// { +// $zipFile = __DIR__ . "/../_files/documents/ziptest.zip"; + +// $object = new ZipArchive(); +// $object->open($zipFile, ZipArchive::CREATE); +// $object->addFromString('content/string.txt', 'Test'); + +// // Lock the file +// $resource = fopen($zipFile, "w"); +// flock($resource, LOCK_EX); + +// // Closing the file should throws an exception +// $object->close(); + +// // Unlock the file +// flock($resource, LOCK_UN); +// fclose($resource); + +// @unlink($zipFile); +// } /** * Test all methods diff --git a/tests/PhpWord/Writer/ODTextTest.php b/tests/PhpWord/Writer/ODTextTest.php index bb1b953821..1984de0f07 100644 --- a/tests/PhpWord/Writer/ODTextTest.php +++ b/tests/PhpWord/Writer/ODTextTest.php @@ -110,6 +110,7 @@ public function testSavePhpOutput() $section->addText('Test'); $writer = new ODText($phpWord); $writer->save('php://output'); + $this->assertNotNull($this->getActualOutput()); } /** diff --git a/tests/PhpWord/Writer/RTFTest.php b/tests/PhpWord/Writer/RTFTest.php index f444204354..803087e567 100644 --- a/tests/PhpWord/Writer/RTFTest.php +++ b/tests/PhpWord/Writer/RTFTest.php @@ -111,5 +111,6 @@ public function testSavePhpOutput() $section->addText(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8')); $writer = new RTF($phpWord); $writer->save('php://output'); + $this->assertNotNull($this->getActualOutput()); } } diff --git a/tests/PhpWord/Writer/Word2007/Part/DocumentTest.php b/tests/PhpWord/Writer/Word2007/Part/DocumentTest.php index 42c098cda7..6998e717ee 100644 --- a/tests/PhpWord/Writer/Word2007/Part/DocumentTest.php +++ b/tests/PhpWord/Writer/Word2007/Part/DocumentTest.php @@ -58,7 +58,8 @@ public function testWriteCustomProps() $docInfo->setCustomProperty('key6', new \DateTime()); $docInfo->setCustomProperty('key7', time(), DocInfo::PROPERTY_TYPE_DATE); - TestHelperDOCX::getDocument($phpWord); + $doc = TestHelperDOCX::getDocument($phpWord); + $this->assertNotNull($doc); // $this->assertTrue($doc->elementExists('/Properties/property[name="key1"]/vt:lpwstr')); // $this->assertTrue($doc->elementExists('/Properties/property[name="key2"]/vt:bool'));