Skip to content

Commit 468a374

Browse files
committed
Fix PHP 7.0 local CI
1 parent 846a9f7 commit 468a374

10 files changed

Lines changed: 49 additions & 54 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"scripts": {
4949
"test": "php ./vendor/phpunit/phpunit/phpunit --configuration ./continuous-integration/phpunit/phpunit.xml --testdox",
5050
"test-coverage": "php ./vendor/phpunit/phpunit/phpunit --configuration ./continuous-integration/phpunit/phpunit.xml --testdox --coverage-html ./continuous-integration/autotests-coverage-report --whitelist ./src",
51-
"phpstan-check": "php ./vendor/bin/phpstan analyse -vvv --configuration continuous-integration/phpstan/phpstan.neon",
51+
"phpstan-check": "php ./vendor/bin/phpstan analyse -vvv --level 7 src --configuration continuous-integration/phpstan/phpstan.neon",
5252
"check-style": "php ./vendor/bin/phpcs --standard=continuous-integration/phpcs/phpcs.xml -v",
5353
"fix-style": "php ./vendor/bin/phpcbf --standard=continuous-integration/phpcs/phpcs.xml -v"
5454
},
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
parameters:
1+
parameters:
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
includes:
22
- ignore-errors/baseline.neon
33
parameters:
4-
level: 10
54
tmpDir: tmp/
65
paths:
76
- ../../src

src/SbWereWolf/XmlNavigator/Conversion/FastXmlToArray.php

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,11 @@
1111

1212
/**
1313
* Converts an XML document into a PHP array with static methods
14-
*
15-
* @phpstan-import-type HierarchyNode from IFastXmlToArray
16-
* @phpstan-import-type PrettyNode from IFastXmlToArray
1714
*/
1815
class FastXmlToArray implements IFastXmlToArray
1916
{
2017
/**
21-
* @return HierarchyNode
18+
* @return array<string, mixed>
2219
*/
2320
public static function convert(
2421
string $xmlText = '',
@@ -57,7 +54,7 @@ static function (XMLReader $cursor): bool {
5754
);
5855
};
5956

60-
/** @var HierarchyNode $result */
57+
/** @var array<string, mixed> $result */
6158
$result = self::parseRootElement(
6259
$xmlText,
6360
$xmlUri,
@@ -70,7 +67,7 @@ static function (XMLReader $cursor): bool {
7067
}
7168

7269
/**
73-
* @return PrettyNode
70+
* @return array<string, mixed>
7471
*/
7572
public static function prettyPrint(
7673
string $xmlText = '',
@@ -103,7 +100,7 @@ static function (XMLReader $cursor): bool {
103100
);
104101
};
105102

106-
/** @var PrettyNode $result */
103+
/** @var array<string, mixed> $result */
107104
$result = self::parseRootElement(
108105
$xmlText,
109106
$xmlUri,
@@ -182,22 +179,30 @@ private static function createXmlReader(
182179
);
183180
}
184181

182+
$reader = new XMLReader();
183+
185184
if ($xmlText !== '') {
186-
/** @var XMLReader $reader */
187-
$reader = @XMLReader::XML(
185+
$loaded = @$reader->XML(
188186
$xmlText,
189187
$encoding,
190188
$flags
191189
);
190+
if ($loaded !== true) {
191+
throw new InvalidArgumentException(
192+
'Unable to parse XML from $xmlText.' . self::formatLibxmlErrors(),
193+
-669
194+
);
195+
}
196+
192197
return $reader;
193198
}
194199

195-
$reader = @XMLReader::open(
200+
$opened = @$reader->open(
196201
$xmlUri,
197202
$encoding,
198203
$flags
199204
);
200-
if (!$reader instanceof XMLReader) {
205+
if ($opened !== true) {
201206
throw new InvalidArgumentException(
202207
'Unable to open XML source from URI `' . $xmlUri . '`.',
203208
-671
@@ -249,8 +254,9 @@ private static function formatLibxmlErrors(): string
249254
}
250255

251256
$messages = array_map(
252-
static function (\LibXMLError $error): string {
253-
return trim($error->message);
257+
static function ($error): string {
258+
/** @var object $error */
259+
return trim((string) $error->message);
254260
},
255261
$errors
256262
);

src/SbWereWolf/XmlNavigator/Conversion/XmlConverter.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,13 @@
88

99
/**
1010
* Converts an XML document into a PHP array
11-
*
12-
* @phpstan-import-type HierarchyNode from IFastXmlToArray
13-
* @phpstan-import-type PrettyNode from IFastXmlToArray
1411
*/
1512
class XmlConverter implements IXmlConverter
1613
{
17-
/** @var HierarchyNode
14+
/** @var array<string, mixed>
1815
* Normalized XML document structure */
1916
private $xmlStructure = [];
20-
/** @var PrettyNode
17+
/** @var array<string, mixed>
2118
* Readable XML document representation */
2219
private $prettyXml = [];
2320
/** @var string Index for the element name */
@@ -62,7 +59,7 @@ public function __construct(
6259
}
6360

6461
/**
65-
* @return PrettyNode
62+
* @return array<string, mixed>
6663
*/
6764
public function toPrettyPrint(
6865
string $xmlText = '',
@@ -88,7 +85,7 @@ public function toPrettyPrint(
8885
}
8986

9087
/**
91-
* @return HierarchyNode
88+
* @return array<string, mixed>
9289
*/
9390
public function toHierarchyOfElements(
9491
string $xmlText = '',

src/SbWereWolf/XmlNavigator/Extraction/HierarchyComposer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ private static function composeElement(
9191
return $result;
9292
}
9393

94-
/** @var list<HierarchyNode> $children */
94+
/** @var array<int, array<string, mixed>> $children */
9595
$children = [];
9696
$value = '';
9797
$hasValue = false;

src/SbWereWolf/XmlNavigator/Extraction/PrettyPrintComposer.php

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,14 @@
99

1010
/**
1111
* Converts an XML element into a PHP array
12-
*
13-
* @phpstan-import-type PrettyNode from \SbWereWolf\XmlNavigator\Conversion\IFastXmlToArray
14-
* @phpstan-import-type PrettyNodeValue from \SbWereWolf\XmlNavigator\Conversion\IFastXmlToArray
15-
* @phpstan-import-type XmlAttributes from \SbWereWolf\XmlNavigator\Conversion\IFastXmlToArray
16-
* @phpstan-type PrettyChildren array<string, PrettyNodeValue>
1712
*/
1813
class PrettyPrintComposer implements Notation
1914
{
2015
/**
2116
* @param XMLReader $reader
2217
* @param string $valueIndex index for element value
2318
* @param string $attributesIndex index for attributes collection
24-
* @return PrettyNode
19+
* @return array<string, mixed>
2520
*/
2621
public static function compose(
2722
XMLReader $reader,
@@ -65,7 +60,7 @@ private static function needsReadToReachElement(
6560
/**
6661
* @param string $valueIndex
6762
* @param string $attributesIndex
68-
* @return PrettyNode
63+
* @return array<string, mixed>
6964
*/
7065
private static function composeEmptyElement(
7166
XMLReader $reader,
@@ -91,7 +86,7 @@ private static function composeEmptyElement(
9186
/**
9287
* @param string $valueIndex
9388
* @param string $attributesIndex
94-
* @return PrettyNode
89+
* @return array<string, mixed>
9590
*/
9691
private static function composeElement(
9792
XMLReader $reader,
@@ -115,7 +110,7 @@ private static function composeElement(
115110
];
116111
}
117112

118-
/** @var PrettyChildren $children */
113+
/** @var array<string, mixed> $children */
119114
$children = [];
120115
$value = '';
121116
$hasValue = false;
@@ -128,7 +123,6 @@ private static function composeElement(
128123
);
129124
/** @var string $childName */
130125
$childName = self::firstKey($child);
131-
/** @var PrettyNodeValue $childValue */
132126
$childValue = $child[$childName];
133127
self::appendChild($children, $childName, $childValue);
134128
continue;
@@ -166,10 +160,10 @@ private static function composeElement(
166160
}
167161

168162
/**
169-
* @param PrettyChildren $target
163+
* @param array<string, mixed> $target
170164
* @param string $childName
171-
* @param PrettyNodeValue $childValue
172-
* @param-out PrettyChildren $target
165+
* @param mixed $childValue
166+
* @param-out array<string, mixed> $target
173167
*/
174168
private static function appendChild(
175169
array &$target,
@@ -197,9 +191,9 @@ private static function appendChild(
197191
}
198192

199193
/**
200-
* @param PrettyChildren $children
201-
* @param XmlAttributes $attributes
202-
* @return PrettyNodeValue
194+
* @param array<string, mixed> $children
195+
* @param array<string, string> $attributes
196+
* @return mixed
203197
*/
204198
private static function normalizeValue(
205199
array $children,
@@ -226,7 +220,7 @@ private static function normalizeValue(
226220
];
227221
}
228222

229-
/** @var array<string, PrettyNodeValue> $result */
223+
/** @var array<string, mixed> $result */
230224
$result = [];
231225
if ($attributes !== []) {
232226
$result[$attributesIndex] = $attributes;

src/SbWereWolf/XmlNavigator/Navigation/XmlElement.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,14 @@
1212
/**
1313
* XML element value object
1414
*
15-
* @phpstan-import-type HierarchyNode from IFastXmlToArray
16-
* @phpstan-import-type XmlAttributes from IFastXmlToArray
1715
* @phpstan-consistent-constructor
1816
*/
1917
class XmlElement implements IXmlElement
2018
{
2119
/** @var bool */
2220
private static $trustChildData = false;
2321

24-
/** @var HierarchyNode Serialized XML element representation */
22+
/** @var array<string, mixed> Serialized XML element representation */
2523
private $data;
2624
/** @var string Index for the element name */
2725
private $name;
@@ -35,13 +33,13 @@ class XmlElement implements IXmlElement
3533
private $elementName;
3634
/** @var string XML element value */
3735
private $elementValue;
38-
/** @var XmlAttributes XML element attributes */
36+
/** @var array<string, string> XML element attributes */
3937
private $attributesData;
40-
/** @var list<array<string, mixed>> Child elements */
38+
/** @var array<int, array<string, mixed>> Child elements */
4139
private $sequenceData;
4240

4341
/**
44-
* @param HierarchyNode $initial Serialized XML element payload
42+
* @param array<string, mixed> $initial Serialized XML element payload
4543
* @param string $name index for the element name
4644
* @param string $val index for the element value
4745
* @param string $attr index for element attributes
@@ -81,7 +79,7 @@ public function __construct(
8179
}
8280

8381
$keys = [$name, $val, $attr, $seq];
84-
/** @var HierarchyNode $data */
82+
/** @var array<string, mixed> $data */
8583
$data = [];
8684
foreach ($keys as $key) {
8785
if (array_key_exists($key, $initial)) {
@@ -147,7 +145,6 @@ public function elements(string $name = ''): array
147145
public function pull(string $name = ''): Generator
148146
{
149147
foreach ($this->sequenceData as $elem) {
150-
/** @var HierarchyNode $elem */
151148
if (
152149
'' !== $name
153150
&& (($elem[$this->name] ?? null) !== $name)
@@ -224,7 +221,7 @@ public function serialize(): array
224221

225222
/**
226223
* @param mixed $value Value that may contain XML attributes
227-
* @phpstan-assert-if-true XmlAttributes $value
224+
* @phpstan-assert-if-true array<string, string> $value
228225
*/
229226
private static function isXmlAttributes($value): bool
230227
{
@@ -243,7 +240,7 @@ private static function isXmlAttributes($value): bool
243240

244241
/**
245242
* @param mixed $value Value that may contain a list of child elements
246-
* @phpstan-assert-if-true list<array<string, mixed>> $value
243+
* @phpstan-assert-if-true array<int, array<string, mixed>> $value
247244
*/
248245
private static function isHierarchySequence($value): bool
249246
{

tests/Compat/docker/Dockerfile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@ RUN apt-get update \
1717
libxml2-dev \
1818
$PHPIZE_DEPS \
1919
&& docker-php-ext-install xml \
20-
&& if [ -n "$XDEBUG_VERSION" ]; then \
20+
&& if [ "$XDEBUG_VERSION" = "none" ]; then \
21+
true; \
22+
elif [ -n "$XDEBUG_VERSION" ]; then \
2123
pecl install xdebug-"$XDEBUG_VERSION"; \
2224
else \
2325
pecl install xdebug; \
2426
fi \
25-
&& docker-php-ext-enable xdebug \
27+
&& if php -m | grep -qi '^xdebug$'; then docker-php-ext-enable xdebug; fi \
2628
&& rm -rf /var/lib/apt/lists/*
2729

2830
WORKDIR /app

tests/Unit/Extraction/HierarchyComposerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public function testComposeReturnsEmptyArrayWhenReaderIsExhausted()
9494
$reader->close();
9595
}
9696

97-
public function testComposeMovesReaderPastTopLevelEmptyElement(): void
97+
public function testComposeMovesReaderPastTopLevelEmptyElement()
9898
{
9999
$reader = XmlFixture::readerFromFixture('empty-elements.xml');
100100

0 commit comments

Comments
 (0)