Skip to content

Commit 0ab0b49

Browse files
Update phpstan/phpstan requirement from ^0.12.88 || ^1.0.0 to ^0.12.88 || ^1.0.0 || ^2.0.0 (#2736)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Progi1984 <[email protected]>
1 parent a3de6ef commit 0ab0b49

File tree

95 files changed

+540
-480
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+540
-480
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@
120120
"friendsofphp/php-cs-fixer": "^3.3",
121121
"mpdf/mpdf": "^7.0 || ^8.0",
122122
"phpmd/phpmd": "^2.13",
123-
"phpstan/phpstan": "^0.12.88 || ^1.0.0",
123+
"phpstan/phpstan": "^0.12.88 || ^1.0.0 || ^2.0.0",
124124
"phpstan/phpstan-phpunit": "^1.0 || ^2.0",
125125
"phpunit/phpunit": ">=7.0",
126126
"symfony/process": "^4.4 || ^5.0",

docs/changes/1.x/1.5.0.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
### Miscellaneous
1212

13+
- Update phpstan/phpstan requirement from ^0.12.88 || ^1.0.0 to ^0.12.88 || ^1.0.0 || ^2.0.0 by [@dependabot](https://github.com/dependabot) & [@Progi1984](https://github.com/Progi1984) in [#2736](https://github.com/PHPOffice/PHPWord/pull/2736)
14+
1315
### Deprecations
1416

1517
### BC Breaks

phpstan-baseline.neon

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1839,3 +1839,39 @@ parameters:
18391839
message: "#^Property PhpOffice\\\\PhpWordTests\\\\XmlDocument\\:\\:\\$xpath \\(DOMXPath\\) does not accept null\\.$#"
18401840
count: 1
18411841
path: tests/PhpWordTests/XmlDocument.php
1842+
1843+
# https://github.com/phpstan/phpstan/issues/8770
1844+
-
1845+
message: "#^PHPDoc tag @var with type PhpOffice\\\\PhpWord\\\\Writer\\\\HTML\\\\Part\\\\AbstractPart is not subtype of native type[\\sA-Za-z\\@\\\\\\/0-9\\.:|]+$#"
1846+
count: 1
1847+
path: src/PhpWord/Writer/HTML.php
1848+
1849+
# https://github.com/phpstan/phpstan/issues/8770
1850+
-
1851+
message: "#^PHPDoc tag @var with type PhpOffice\\\\PhpWord\\\\Element\\\\AbstractElement is not subtype of native type[\\sA-Za-z\\@\\\\\\/0-9\\.:]+$#"
1852+
count: 2
1853+
path: tests/PhpWordTests/Element/AbstractElementTest.php
1854+
1855+
# https://github.com/phpstan/phpstan/issues/8770
1856+
-
1857+
message: "#^PHPDoc tag @var with type PhpOffice\\\\PhpWord\\\\Style\\\\AbstractStyle is not subtype of native type[\\sA-Za-z\\@\\\\\\/0-9\\.:]+$#"
1858+
count: 4
1859+
path: tests/PhpWordTests/Style/AbstractStyleTest.php
1860+
1861+
# https://github.com/phpstan/phpstan/issues/8770
1862+
-
1863+
message: "#^PHPDoc tag @var with type PhpOffice\\\\PhpWord\\\\Writer\\\\EPub3\\\\Style\\\\AbstractStyle is not subtype of native type[\\sA-Za-z\\@\\\\\\/0-9\\.:]+$#"
1864+
count: 2
1865+
path: tests/PhpWordTests/Writer/EPub3/Style/AbstractStyleTest.php
1866+
1867+
# https://github.com/phpstan/phpstan/issues/8770
1868+
-
1869+
message: "#^PHPDoc tag @var with type PhpOffice\\\\PhpWord\\\\Writer\\\\ODText\\\\Part\\\\AbstractPart is not subtype of native type[\\sA-Za-z\\@\\\\\\/0-9\\.:]+$#"
1870+
count: 2
1871+
path: tests/PhpWordTests/Writer/ODText/Part/AbstractPartTest.php
1872+
1873+
# https://github.com/phpstan/phpstan/issues/8770
1874+
-
1875+
message: "#^PHPDoc tag @var with type PhpOffice\\\\PhpWord\\\\Writer\\\\Word2007\\\\Part\\\\AbstractPart is not subtype of native type[\\sA-Za-z\\@\\\\\\/0-9\\.:]+$#"
1876+
count: 2
1877+
path: tests/PhpWordTests/Writer/Word2007/Part/AbstractPartTest.php

phpstan.neon.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ parameters:
1616
- tests/bootstrap.php
1717
## <=PHP7.4
1818
reportUnmatchedIgnoredErrors: false
19+
treatPhpDocTypesAsCertain: false
1920
ignoreErrors:
2021
-
2122
identifier: missingType.iterableValue

src/PhpWord/Element/Field.php

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class Field extends AbstractElement
108108
/**
109109
* Field text.
110110
*
111-
* @var string|TextRun
111+
* @var null|string|TextRun
112112
*/
113113
protected $text;
114114

@@ -217,22 +217,18 @@ public function getType()
217217
/**
218218
* Set Field properties.
219219
*
220-
* @param array $properties
221-
*
222220
* @return self
223221
*/
224-
public function setProperties($properties = [])
222+
public function setProperties(array $properties = [])
225223
{
226-
if (is_array($properties)) {
227-
foreach (array_keys($properties) as $propkey) {
228-
if (!(isset($this->fieldsArray[$this->type]['properties'][$propkey]))) {
229-
throw new InvalidArgumentException("Invalid property '$propkey'");
230-
}
224+
foreach (array_keys($properties) as $propkey) {
225+
if (!(isset($this->fieldsArray[$this->type]['properties'][$propkey]))) {
226+
throw new InvalidArgumentException("Invalid property '$propkey'");
231227
}
232-
$this->properties = array_merge($this->properties, $properties);
233228
}
229+
$this->properties = array_merge($this->properties, $properties);
234230

235-
return $this->properties;
231+
return $this;
236232
}
237233

238234
/**
@@ -248,22 +244,18 @@ public function getProperties()
248244
/**
249245
* Set Field options.
250246
*
251-
* @param array $options
252-
*
253247
* @return self
254248
*/
255-
public function setOptions($options = [])
249+
public function setOptions(array $options = [])
256250
{
257-
if (is_array($options)) {
258-
foreach (array_keys($options) as $optionkey) {
259-
if (!(isset($this->fieldsArray[$this->type]['options'][$optionkey])) && substr($optionkey, 0, 1) !== '\\') {
260-
throw new InvalidArgumentException("Invalid option '$optionkey', possible values are " . implode(', ', $this->fieldsArray[$this->type]['options']));
261-
}
251+
foreach (array_keys($options) as $optionkey) {
252+
if (!(isset($this->fieldsArray[$this->type]['options'][$optionkey])) && substr($optionkey, 0, 1) !== '\\') {
253+
throw new InvalidArgumentException("Invalid option '$optionkey', possible values are " . implode(', ', $this->fieldsArray[$this->type]['options']));
262254
}
263-
$this->options = array_merge($this->options, $options);
264255
}
256+
$this->options = array_merge($this->options, $options);
265257

266-
return $this->options;
258+
return $this;
267259
}
268260

269261
/**
@@ -279,13 +271,13 @@ public function getOptions()
279271
/**
280272
* Set Field text.
281273
*
282-
* @param null|string|TextRun $text
274+
* @param null|mixed|string|TextRun $text
283275
*
284276
* @return null|string|TextRun
285277
*/
286278
public function setText($text = null)
287279
{
288-
if (isset($text)) {
280+
if (null !== $text) {
289281
if (is_string($text) || $text instanceof TextRun) {
290282
$this->text = $text;
291283
} else {

src/PhpWord/Element/OLEObject.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,16 @@ class OLEObject extends AbstractElement
7070
public function __construct($source, $style = null)
7171
{
7272
$supportedTypes = ['xls', 'doc', 'ppt', 'xlsx', 'docx', 'pptx'];
73-
$pathInfo = pathinfo($source);
73+
$pathInfoExtension = pathinfo($source, PATHINFO_EXTENSION);
7474

75-
if (file_exists($source) && in_array($pathInfo['extension'], $supportedTypes)) {
76-
$ext = $pathInfo['extension'];
77-
if (strlen($ext) == 4 && strtolower(substr($ext, -1)) == 'x') {
78-
$ext = substr($ext, 0, -1);
75+
if (file_exists($source) && in_array($pathInfoExtension, $supportedTypes)) {
76+
if (strlen($pathInfoExtension) == 4 && strtolower(substr($pathInfoExtension, -1)) == 'x') {
77+
$pathInfoExtension = substr($pathInfoExtension, 0, -1);
7978
}
8079

8180
$this->source = $source;
8281
$this->style = $this->setNewStyle(new ImageStyle(), $style, true);
83-
$this->icon = realpath(__DIR__ . "/../resources/{$ext}.png");
82+
$this->icon = realpath(__DIR__ . "/../resources/{$pathInfoExtension}.png");
8483

8584
return;
8685
}

src/PhpWord/Element/Section.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,10 @@ public function __construct($sectionCount, $style = null)
7575

7676
/**
7777
* Set section style.
78-
*
79-
* @param array $style
8078
*/
81-
public function setStyle($style = null): void
79+
public function setStyle(?array $style = null): void
8280
{
83-
if (null !== $style && is_array($style)) {
81+
if (null !== $style) {
8482
$this->style->setStyleByArray($style);
8583
}
8684
}

src/PhpWord/Element/TOC.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,14 @@ class TOC extends AbstractElement
5959
* Create a new Table-of-Contents Element.
6060
*
6161
* @param mixed $fontStyle
62-
* @param array $tocStyle
6362
* @param int $minDepth
6463
* @param int $maxDepth
6564
*/
66-
public function __construct($fontStyle = null, $tocStyle = null, $minDepth = 1, $maxDepth = 9)
65+
public function __construct($fontStyle = null, ?array $tocStyle = null, $minDepth = 1, $maxDepth = 9)
6766
{
6867
$this->tocStyle = new TOCStyle();
6968

70-
if (null !== $tocStyle && is_array($tocStyle)) {
69+
if (null !== $tocStyle) {
7170
$this->tocStyle->setStyleByArray($tocStyle);
7271
}
7372

src/PhpWord/Reader/ODText/Content.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ public function read(PhpWord $phpWord): void
4545
$xmlReader = new XMLReader();
4646
$xmlReader->getDomFromZip($this->docFile, $this->xmlFile);
4747

48-
$trackedChanges = [];
49-
5048
$nodes = $xmlReader->getElements('office:body/office:text/*');
5149
$this->section = null;
5250
$this->processNodes($nodes, $xmlReader, $phpWord);
@@ -186,6 +184,7 @@ public function processNodes(DOMNodeList $nodes, XMLReader $xmlReader, PhpWord $
186184
case 'text:section': // Section
187185
// $sectionStyleName = $xmlReader->getAttribute('text:style-name', $listItem);
188186
$this->section = $phpWord->addSection();
187+
/** @var DOMNodeList<DOMElement> $children */
189188
$children = $node->childNodes;
190189
$this->processNodes($children, $xmlReader, $phpWord);
191190

src/PhpWord/Reader/RTF/Document.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
*
3232
* @since 0.11.0
3333
*
34-
* @SuppressWarnings(PHPMD.UnusedPrivateMethod)
34+
* @SuppressWarnings("PHPMD.UnusedPrivateMethod")
3535
*/
3636
class Document
3737
{

0 commit comments

Comments
 (0)