Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update requirement to PHP 7.2 #1951

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 3 additions & 21 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,19 @@ language: php
dist: xenial

php:
- 5.3
- 5.4
- 5.5
- 5.6
- 7.0
- 7.1
- 7.2
- 7.3
- 7.4snapshot
- 7.4

matrix:
include:
- php: 5.3
dist: precise
env: COMPOSER_MEMORY_LIMIT=3G
- php: 5.4
dist: trusty
- php: 5.5
dist: trusty
- php: 7.0
- php: 7.2
env: COVERAGE=1
- php: 7.3
env: DEPENDENCIES="--ignore-platform-reqs"
exclude:
- php: 5.3
- php: 5.4
- php: 5.5
- php: 7.0
- php: 7.2
- php: 7.3
allow_failures:
- php: 7.4snapshot

cache:
directories:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ With PHPWord, you can create OOXML, ODF, or RTF documents dynamically using your

PHPWord requires the following:

- PHP 5.3.3+
- A [supported version of PHP](https://www.php.net/supported-versions.php)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's ambiguous. I would rather give a specific version number as before - PHP 7.2+

- [XML Parser extension](http://www.php.net/manual/en/xml.installation.php)
- [Zend\Escaper component](http://framework.zend.com/manual/current/en/modules/zend.escaper.introduction.html)
- [Zend\Stdlib component](http://framework.zend.com/manual/current/en/modules/zend.stdlib.hydrator.html)
Expand Down
9 changes: 5 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"fix": "Fixes issues found by PHP-CS"
},
"require": {
"php": "^5.3.3 || ^7.0",
"php": "^7.2",
"ext-xml": "*",
"zendframework/zend-escaper": "^2.2",
"phpoffice/common": "^0.2.9"
Expand All @@ -67,13 +67,14 @@
"ext-zip": "*",
"ext-gd": "*",
"phpunit/phpunit": "^4.8.36 || ^7.0",
"squizlabs/php_codesniffer": "^2.9",
"squizlabs/php_codesniffer": "^3.5",
"friendsofphp/php-cs-fixer": "^2.2",
"phpmd/phpmd": "2.*",
"phploc/phploc": "2.* || 3.* || 4.*",
"phploc/phploc": "2.* || 3.* || 4.* || 5.*",
"dompdf/dompdf":"0.8.*",
"tecnickcom/tcpdf": "6.*",
"mpdf/mpdf": "5.7.4 || 6.* || 7.*",
"mpdf/mpdf": "7.* || 8.*",
"rector/rector": "^0.8",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You only used rector library for conversion. Now, in my opinion, not needed as require-dev, including the following rector.php file. Remove it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In think this could be useful to add other rules as well. See Rector as a phpcsfixer-like tool.

Thanks for the feedback, I'll work on it as soon as your PR has been merged.

"php-coveralls/php-coveralls": "1.1.0 || ^2.0"
},
"suggest": {
Expand Down
22 changes: 22 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove file, explained above.


declare(strict_types=1);

use Rector\Core\Configuration\Option;
use Rector\Set\ValueObject\SetList;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $containerConfigurator) : void {
$parameters = $containerConfigurator->parameters();

$parameters->set(Option::SETS, [
SetList::PHP_52,
SetList::PHP_53,
SetList::PHP_54,
SetList::PHP_55,
SetList::PHP_56,
SetList::PHP_70,
SetList::PHP_71,
SetList::PHP_72,
]);
};
10 changes: 5 additions & 5 deletions src/PhpWord/ComplexType/TrackChangesView.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function hasMarkup()
*/
public function setMarkup($markup)
{
$this->markup = $markup === null ? true : $markup;
$this->markup = $markup ?? true;
}

/**
Expand All @@ -98,7 +98,7 @@ public function hasComments()
*/
public function setComments($comments)
{
$this->comments = $comments === null ? true : $comments;
$this->comments = $comments ?? true;
}

/**
Expand All @@ -119,7 +119,7 @@ public function hasInsDel()
*/
public function setInsDel($insDel)
{
$this->insDel = $insDel === null ? true : $insDel;
$this->insDel = $insDel ?? true;
}

/**
Expand All @@ -140,7 +140,7 @@ public function hasFormatting()
*/
public function setFormatting($formatting = null)
{
$this->formatting = $formatting === null ? true : $formatting;
$this->formatting = $formatting ?? true;
}

/**
Expand All @@ -161,6 +161,6 @@ public function hasInkAnnotations()
*/
public function setInkAnnotations($inkAnnotations)
{
$this->inkAnnotations = $inkAnnotations === null ? true : $inkAnnotations;
$this->inkAnnotations = $inkAnnotations ?? true;
}
}
5 changes: 3 additions & 2 deletions src/PhpWord/Element/AbstractContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
* @method Image addImage(string $source, mixed $style = null, bool $isWatermark = false, $name = null)
* @method OLEObject addOLEObject(string $source, mixed $style = null)
* @method TextBox addTextBox(mixed $style = null)
* @method Field addField(string $type = null, array $properties = array(), array $options = array(), mixed $text = null)
* @method Field addField(string $type = null, array $properties = [], array $options = [], mixed $text = null)
* @method Line addLine(mixed $lineStyle = null)
* @method Shape addShape(string $type, mixed $style = null)
* @method Chart addChart(string $type, array $categories, array $values, array $style = null, $seriesName = null)
Expand Down Expand Up @@ -99,7 +99,7 @@ public function __call($function, $args)
// Special case for TextBreak
// @todo Remove the `$count` parameter in 1.0.0 to make this element similiar to other elements?
if ($element == 'TextBreak') {
list($count, $fontStyle, $paragraphStyle) = array_pad($args, 3, null);
[$count, $fontStyle, $paragraphStyle] = array_pad($args, 3, null);
if ($count === null) {
$count = 1;
}
Expand All @@ -109,6 +109,7 @@ public function __call($function, $args)
} else {
// All other elements
array_unshift($args, $element); // Prepend element name to the beginning of args array

return call_user_func_array(array($this, 'addElement'), $args);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/PhpWord/Element/AbstractElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ public function getElementId()
*/
public function setElementId()
{
$this->elementId = substr(md5(rand()), 0, 6);
$this->elementId = substr(md5(random_int(0, mt_getrandmax())), 0, 6);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/PhpWord/Element/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ public function getImageStringData($base64 = false)
// Return null if not found
if ($this->sourceType == self::SOURCE_ARCHIVE) {
$source = substr($source, 6);
list($zipFilename, $imageFilename) = explode('#', $source);
[$zipFilename, $imageFilename] = explode('#', $source);

$zip = new ZipArchive();
if ($zip->open($zipFilename) !== false) {
Expand Down Expand Up @@ -417,7 +417,7 @@ private function checkImage()
if (!is_array($imageData)) {
throw new InvalidImageException(sprintf('Invalid image: %s', $this->source));
}
list($actualWidth, $actualHeight, $imageType) = $imageData;
[$actualWidth, $actualHeight, $imageType] = $imageData;

// Check image type support
$supportedTypes = array(IMAGETYPE_JPEG, IMAGETYPE_GIF, IMAGETYPE_PNG);
Expand Down Expand Up @@ -478,7 +478,7 @@ private function getArchiveImageSize($source)
{
$imageData = null;
$source = substr($source, 6);
list($zipFilename, $imageFilename) = explode('#', $source);
[$zipFilename, $imageFilename] = explode('#', $source);

$tempFilename = tempnam(Settings::getTempDir(), 'PHPWordImage');
if (false === $tempFilename) {
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 @@ -217,7 +217,7 @@ private function addHeaderFooter($type = Header::AUTO, $header = true)
$collection = &$this->$collectionArray;

if (in_array($type, array(Header::AUTO, Header::FIRST, Header::EVEN))) {
$index = count($collection);
$index = is_countable($collection) ? count($collection) : 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is_countable check? Properties $this->headers and $this->footers is array.

/** @var \PhpOffice\PhpWord\Element\AbstractContainer $container Type hint */
$container = new $containerClass($this->sectionId, ++$index, $type);
$container->setPhpWord($this->phpWord);
Expand Down
14 changes: 7 additions & 7 deletions src/PhpWord/Metadata/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public function hasHideSpellingErrors()
*/
public function setHideSpellingErrors($hideSpellingErrors)
{
$this->hideSpellingErrors = $hideSpellingErrors === null ? true : $hideSpellingErrors;
$this->hideSpellingErrors = $hideSpellingErrors ?? true;
}

/**
Expand All @@ -233,7 +233,7 @@ public function hasHideGrammaticalErrors()
*/
public function setHideGrammaticalErrors($hideGrammaticalErrors)
{
$this->hideGrammaticalErrors = $hideGrammaticalErrors === null ? true : $hideGrammaticalErrors;
$this->hideGrammaticalErrors = $hideGrammaticalErrors ?? true;
}

/**
Expand All @@ -249,7 +249,7 @@ public function hasEvenAndOddHeaders()
*/
public function setEvenAndOddHeaders($evenAndOddHeaders)
{
$this->evenAndOddHeaders = $evenAndOddHeaders === null ? true : $evenAndOddHeaders;
$this->evenAndOddHeaders = $evenAndOddHeaders ?? true;
}

/**
Expand Down Expand Up @@ -285,7 +285,7 @@ public function hasTrackRevisions()
*/
public function setTrackRevisions($trackRevisions)
{
$this->trackRevisions = $trackRevisions === null ? true : $trackRevisions;
$this->trackRevisions = $trackRevisions ?? true;
}

/**
Expand All @@ -301,7 +301,7 @@ public function hasDoNotTrackMoves()
*/
public function setDoNotTrackMoves($doNotTrackMoves)
{
$this->doNotTrackMoves = $doNotTrackMoves === null ? true : $doNotTrackMoves;
$this->doNotTrackMoves = $doNotTrackMoves ?? true;
}

/**
Expand All @@ -317,7 +317,7 @@ public function hasDoNotTrackFormatting()
*/
public function setDoNotTrackFormatting($doNotTrackFormatting)
{
$this->doNotTrackFormatting = $doNotTrackFormatting === null ? true : $doNotTrackFormatting;
$this->doNotTrackFormatting = $doNotTrackFormatting ?? true;
}

/**
Expand Down Expand Up @@ -391,7 +391,7 @@ public function hasUpdateFields()
*/
public function setUpdateFields($updateFields)
{
$this->updateFields = $updateFields === null ? false : $updateFields;
$this->updateFields = $updateFields ?? false;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/PhpWord/PhpWord.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,12 @@ public function __call($function, $args)
/** @var \PhpOffice\PhpWord\Collection\AbstractCollection $collectionObject */
$collectionObject = $this->collections[$key];

return $collectionObject->addItem(isset($args[0]) ? $args[0] : null);
return $collectionObject->addItem($args[0] ?? null);
}

// Run add style method
if (in_array($function, $addStyle)) {
return forward_static_call_array(array('PhpOffice\\PhpWord\\Style', $function), $args);
return forward_static_call_array(array(\PhpOffice\PhpWord\Style::class, $function), $args);
}

// Exception
Expand Down
10 changes: 5 additions & 5 deletions src/PhpWord/Reader/RTF/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ private function flush($isControl = false)
private function flushControl($isControl = false)
{
if (1 === preg_match('/^([A-Za-z]+)(-?[0-9]*) ?$/', $this->control, $match)) {
list(, $control, $parameter) = $match;
[, $control, $parameter] = $match;
$this->parseControl($control, $parameter);
}

Expand Down Expand Up @@ -337,7 +337,7 @@ private function parseControl($control, $parameter)
);

if (isset($controls[$control])) {
list($function) = $controls[$control];
[$function] = $controls[$control];
if (method_exists($this, $function)) {
$directives = $controls[$control];
array_shift($directives); // remove the function variable; we won't need it
Expand All @@ -353,7 +353,7 @@ private function parseControl($control, $parameter)
*/
private function readParagraph($directives)
{
list($property, $value) = $directives;
[$property, $value] = $directives;
$this->textrun = $this->section->addTextRun();
$this->flags[$property] = $value;
}
Expand All @@ -365,7 +365,7 @@ private function readParagraph($directives)
*/
private function readStyle($directives)
{
list($style, $property, $value) = $directives;
[$style, $property, $value] = $directives;
$this->flags['styles'][$style][$property] = $value;
}

Expand All @@ -376,7 +376,7 @@ private function readStyle($directives)
*/
private function readSkip($directives)
{
list($property) = $directives;
[$property] = $directives;
$this->flags['property'] = $property;
$this->flags['skipped'] = true;
}
Expand Down
4 changes: 2 additions & 2 deletions src/PhpWord/Reader/Word2007/AbstractPart.php
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ protected function readStyleDefs(XMLReader $xmlReader, \DOMElement $parentNode =
$styles = array();

foreach ($styleDefs as $styleProp => $styleVal) {
list($method, $element, $attribute, $expected) = array_pad($styleVal, 4, null);
[$method, $element, $attribute, $expected] = array_pad($styleVal, 4, null);

$element = $this->findPossibleElement($xmlReader, $parentNode, $element);
if ($element === null) {
Expand All @@ -644,7 +644,7 @@ protected function readStyleDefs(XMLReader $xmlReader, \DOMElement $parentNode =
$attribute = $this->findPossibleAttribute($xmlReader, $node, $attribute);

// Use w:val as default if no attribute assigned
$attribute = ($attribute === null) ? 'w:val' : $attribute;
$attribute = $attribute ?? 'w:val';
$attributeValue = $xmlReader->getAttribute($attribute, $node);

$styleValue = $this->readStyleDef($method, $attributeValue, $expected);
Expand Down
2 changes: 1 addition & 1 deletion src/PhpWord/Reader/Word2007/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private function readHeaderFooter($settings, Section &$section)
if (is_array($settings) && isset($settings['hf'])) {
foreach ($settings['hf'] as $rId => $hfSetting) {
if (isset($this->rels['document'][$rId])) {
list($hfType, $xmlFile, $docPart) = array_values($this->rels['document'][$rId]);
[$hfType, $xmlFile, $docPart] = array_values($this->rels['document'][$rId]);
$addMethod = "add{$hfType}";
$hfObject = $section->$addMethod($hfSetting['type']);

Expand Down
2 changes: 1 addition & 1 deletion src/PhpWord/Reader/Word2007/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ protected function setZoom(XMLReader $xmlReader, PhpWord $phpWord, \DOMElement $
$val = $xmlReader->getAttribute('w:val', $node);

if ($percent !== null || $val !== null) {
$phpWord->getSettings()->setZoom($percent === null ? $val : $percent);
$phpWord->getSettings()->setZoom($percent ?? $val);
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/PhpWord/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ class Settings
*
* @const string
*/
const ZIPARCHIVE = 'ZipArchive';
const PCLZIP = 'PclZip';
const OLD_LIB = 'PhpOffice\\PhpWord\\Shared\\ZipArchive'; // @deprecated 0.11
const ZIPARCHIVE = \ZipArchive::class;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Class \ZipArchive is part of ext-zip extension. In production install PHPWord does not require ext-zip. Class \ZipArchive may not exist.

const PCLZIP = \PclZip::class;
const OLD_LIB = \PhpOffice\PhpWord\Shared\ZipArchive::class; // @deprecated 0.11

/**
* PDF rendering libraries
*
* @const string
*/
const PDF_RENDERER_DOMPDF = 'DomPDF';
const PDF_RENDERER_TCPDF = 'TCPDF';
const PDF_RENDERER_TCPDF = \TCPDF::class;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This contant is not a class designation. Class \TCPDF may not exist.

const PDF_RENDERER_MPDF = 'MPDF';

/**
Expand Down
Loading