Skip to content

Commit a38f898

Browse files
authored
Merge branch 'master' into bullet_list_render
2 parents 7faa833 + 0ab0b49 commit a38f898

File tree

102 files changed

+587
-493
lines changed

Some content is hidden

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

102 files changed

+587
-493
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ Fixes # (issue)
99
- [ ] My CI is :green_circle:
1010
- [ ] I have covered by unit tests my new code (check build/coverage for coverage report)
1111
- [ ] I have updated the [documentation](https://github.com/PHPOffice/PHPWord/tree/master/docs) to describe the changes
12-
- [ ] I have updated the [changelog](https://github.com/PHPOffice/PHPWord/blob/master/docs/changes/1.x/1.4.0.md)
12+
- [ ] I have updated the [changelog](https://github.com/PHPOffice/PHPWord/blob/master/docs/changes/1.x/1.5.0.md)

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,15 @@
112112
"ext-zip": "*",
113113
"ext-json": "*",
114114
"ext-xml": "*",
115-
"phpoffice/math": "^0.2"
115+
"phpoffice/math": "^0.3"
116116
},
117117
"require-dev": {
118118
"ext-libxml": "*",
119119
"dompdf/dompdf": "^2.0 || ^3.0",
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.4.0.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# [1.4.0](https://github.com/PHPOffice/PHPWord/tree/1.4.0) (WIP)
1+
# [1.4.0](https://github.com/PHPOffice/PHPWord/tree/1.4.0)
22

33
[Full Changelog](https://github.com/PHPOffice/PHPWord/compare/1.3.0...1.4.0)
44

@@ -31,13 +31,16 @@
3131
- Writer HTML: Fixed null string for Text Elements by [@armagedon007](https://github.com/armagedon007) and [@Progi1984](https://github.com/Progi1984) in [#2738](https://github.com/PHPOffice/PHPWord/pull/2738)
3232
- Template Processor: Fix 0 considered as empty string by [@cavasinf](https://github.com/cavasinf), [@SnipsMine](https://github.com/SnipsMine) and [@Progi1984](https://github.com/Progi1984) fixing [#2572](https://github.com/PHPOffice/PHPWord/issues/2572), [#2703](https://github.com/PHPOffice/PHPWord/issues/2703) in [#2748](https://github.com/PHPOffice/PHPWord/pull/2748)
3333
- Word2007 Writer : Corrected generating TOC to fix page number missing issues [@jgiacomello](https://github.com/jgiacomello) in [#2556](https://github.com/PHPOffice/PHPWord/pull/2556)
34+
- Enhanced error handling in encoding functions [@michalschroeder](https://github.com/michalschroeder) in [#2784](https://github.com/PHPOffice/PHPWord/pull/2784)
3435

3536
### Miscellaneous
3637

3738
- Bump dompdf/dompdf from 2.0.4 to 3.0.0 by [@dependabot](https://github.com/dependabot) fixing [#2621](https://github.com/PHPOffice/PHPWord/issues/2621) in [#2666](https://github.com/PHPOffice/PHPWord/pull/2666)
3839
- Add test case to make sure vMerge defaults to 'continue' by [@SpraxDev](https://github.com/SpraxDev) in [#2677](https://github.com/PHPOffice/PHPWord/pull/2677)
3940
- Adding the possibility to use iterate search and replace with setValues by [@moghwan](https://github.com/moghwan) in [#2632](https://github.com/PHPOffice/PHPWord/pull/2640)
4041
- Add test cases that test the ODTText and Word2007 reader using the corresponding writer, increasing test coverage by [@MichaelPFrey](https://github.com/MichaelPFrey) in [#2745](https://github.com/PHPOffice/PHPWord/pull/2745)
42+
- Updated TOCTest to use static HTML content instead of external resource [@michalschroeder](https://github.com/michalschroeder) in [#2784](https://github.com/PHPOffice/PHPWord/pull/2784)
43+
- Bump PHPOffice/math from 0.2.0 to 0.3.0 by [@eileenmcnaughton](https://github.com/eileenmcnaughton) in [#2785](https://github.com/PHPOffice/PHPWord/pull/2785)
4144

4245
### Deprecations
4346
- Deprecate `PhpOffice\PhpWord\Style\Paragraph::getIndent()` : Use `PhpOffice\PhpWord\Style\Paragraph::getIndentLeft()`

docs/changes/1.x/1.5.0.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# [1.5.0](https://github.com/PHPOffice/PHPWord/tree/1.5.0) (WIP)
2+
3+
[Full Changelog](https://github.com/PHPOffice/PHPWord/compare/1.4.0...1.5.0)
4+
5+
## Enhancements
6+
7+
### Bug fixes
8+
9+
- Set writeAttribute return type by [@radarhere](https://github.com/radarhere) fixing [#2204](https://github.com/PHPOffice/PHPWord/issues/2204) in [#2776](https://github.com/PHPOffice/PHPWord/pull/2776)
10+
11+
### Miscellaneous
12+
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+
15+
### Deprecations
16+
17+
### BC Breaks
18+
19+
### Notes

mkdocs.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ nav:
8888
- Credits: 'credits.md'
8989
- Releases:
9090
- '1.x':
91-
- '1.4.0 (WIP)': 'changes/1.x/1.4.0.md'
91+
- '1.5.0 (WIP)': 'changes/1.x/1.5.0.md'
92+
- '1.4.0': 'changes/1.x/1.4.0.md'
9293
- '1.3.0': 'changes/1.x/1.3.0.md'
9394
- '1.2.0': 'changes/1.x/1.2.0.md'
9495
- '1.1.0': 'changes/1.x/1.1.0.md'

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
{

src/PhpWord/Reader/Word2007.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,15 @@ private function readRelationships($docFile)
138138
if ($zip->open($docFile) === true) {
139139
for ($i = 0; $i < $zip->numFiles; ++$i) {
140140
$xmlFile = $zip->getNameIndex($i);
141+
if (!is_string($xmlFile)) {
142+
continue;
143+
}
141144
if ((substr($xmlFile, 0, strlen($wordRelsPath))) == $wordRelsPath && (substr($xmlFile, -1)) != '/') {
142-
$docPart = str_replace('.xml.rels', '', str_replace($wordRelsPath, '', $xmlFile));
145+
$docPart = str_replace(
146+
'.xml.rels',
147+
'',
148+
str_replace($wordRelsPath, '', $xmlFile)
149+
);
143150
$relationships[$docPart] = $this->getRels($docFile, $xmlFile, 'word/');
144151
}
145152
}

src/PhpWord/Reader/Word2007/Document.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
*
2929
* @since 0.10.0
3030
*
31-
* @SuppressWarnings(PHPMD.UnusedPrivateMethod) For readWPNode
31+
* @SuppressWarnings("PHPMD.UnusedPrivateMethod") For readWPNode
3232
*/
3333
class Document extends AbstractPart
3434
{

src/PhpWord/Shared/Html.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
namespace PhpOffice\PhpWord\Shared;
2020

21-
use DOMAttr;
2221
use DOMDocument;
2322
use DOMNode;
2423
use DOMXPath;
@@ -36,7 +35,7 @@
3635
/**
3736
* Common Html functions.
3837
*
39-
* @SuppressWarnings(PHPMD.UnusedPrivateMethod) For readWPNode
38+
* @SuppressWarnings("PHPMD.UnusedPrivateMethod") For readWPNode
4039
*/
4140
class Html
4241
{
@@ -666,14 +665,11 @@ protected static function parseListItem($node, $element, &$styles, $data): void
666665
/**
667666
* Parse style.
668667
*
669-
* @param DOMAttr $attribute
670-
* @param array $styles
671-
*
672-
* @return array
668+
* @param DOMNode $attribute
673669
*/
674-
protected static function parseStyle($attribute, $styles)
670+
protected static function parseStyle($attribute, array $styles): array
675671
{
676-
$properties = explode(';', trim($attribute->value, " \t\n\r\0\x0B;"));
672+
$properties = explode(';', trim($attribute->nodeValue, " \t\n\r\0\x0B;"));
677673

678674
$selectors = [];
679675
foreach ($properties as $property) {
@@ -684,7 +680,7 @@ protected static function parseStyle($attribute, $styles)
684680
return self::parseStyleDeclarations($selectors, $styles);
685681
}
686682

687-
protected static function parseStyleDeclarations(array $selectors, array $styles)
683+
protected static function parseStyleDeclarations(array $selectors, array $styles): array
688684
{
689685
$bidi = ($selectors['direction'] ?? '') === 'rtl';
690686
foreach ($selectors as $property => $value) {

src/PhpWord/Shared/Microsoft/PasswordEncoder.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
namespace PhpOffice\PhpWord\Shared\Microsoft;
2020

21+
use PhpOffice\PhpWord\Exception\Exception;
22+
2123
/**
2224
* Password encoder for microsoft office applications.
2325
*/
@@ -119,8 +121,11 @@ public static function hashPassword($password, $algorithmName = self::ALGORITHM_
119121
// Get the single-byte values by iterating through the Unicode characters of the truncated password.
120122
// For each character, if the low byte is not equal to 0, take it. Otherwise, take the high byte.
121123
$passUtf8 = mb_convert_encoding($password, 'UCS-2LE', 'UTF-8');
122-
$byteChars = [];
124+
if (!is_string($passUtf8)) {
125+
throw new Exception('Failed to convert password to UCS-2LE');
126+
}
123127

128+
$byteChars = [];
124129
for ($i = 0; $i < mb_strlen($password); ++$i) {
125130
$byteChars[$i] = ord(substr($passUtf8, $i * 2, 1));
126131

0 commit comments

Comments
 (0)