Skip to content

Commit 0e12227

Browse files
authored
Fixed issues uncovered by PHPStan v2.1.26 (#198)
For more details see #198 Key changes: * Fixed return type of `Handler::convert` and `Xml::convertDom` * Improved strict checks in `Xml::convertDom` method * Aligned Json input handler PHPDoc with the changes
1 parent fb3e879 commit 0e12227

File tree

7 files changed

+7
-131
lines changed

7 files changed

+7
-131
lines changed

phpstan-baseline-7.4.neon

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,6 @@ parameters:
2424
count: 1
2525
path: src/lib/Input/Handler/Xml.php
2626

27-
-
28-
message: '#^Parameter \#1 \$input of function array_slice expects array, iterable\<int, Ibexa\\Contracts\\Core\\Repository\\Values\\Content\\Relation\> given\.$#'
29-
identifier: argument.type
30-
count: 1
31-
path: src/lib/Server/Controller/Content.php
32-
3327
-
3428
message: '#^Parameter \#2 \$str of function explode expects string, string\|null given\.$#'
3529
identifier: argument.type

phpstan-baseline-gte-8.0.neon

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,6 @@ parameters:
3636
count: 1
3737
path: src/lib/Input/Handler/Xml.php
3838

39-
-
40-
message: '#^Parameter \#1 \$array of function array_slice expects array, iterable\<int, Ibexa\\Contracts\\Core\\Repository\\Values\\Content\\Relation\> given\.$#'
41-
identifier: argument.type
42-
count: 1
43-
path: src/lib/Server/Controller/Content.php
44-
4539
-
4640
message: '#^Parameter \#2 \$string of function explode expects string, string\|null given\.$#'
4741
identifier: argument.type

phpstan-baseline.neon

Lines changed: 0 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -318,12 +318,6 @@ parameters:
318318
count: 1
319319
path: src/contracts/Event/ParseEvent.php
320320

321-
-
322-
message: '#^Method Ibexa\\Contracts\\Rest\\Input\\Handler\:\:convert\(\) return type has no value type specified in iterable type array\.$#'
323-
identifier: missingType.iterableValue
324-
count: 1
325-
path: src/contracts/Input/Handler.php
326-
327321
-
328322
message: '#^Method Ibexa\\Contracts\\Rest\\Input\\ParsingDispatcher\:\:__construct\(\) has parameter \$parsers with no value type specified in iterable type array\.$#'
329323
identifier: missingType.iterableValue
@@ -780,42 +774,12 @@ parameters:
780774
count: 1
781775
path: src/lib/Input/FieldTypeParser.php
782776

783-
-
784-
message: '#^Method Ibexa\\Rest\\Input\\Handler\\Json\:\:convert\(\) return type has no value type specified in iterable type array\.$#'
785-
identifier: missingType.iterableValue
786-
count: 1
787-
path: src/lib/Input/Handler/Json.php
788-
789777
-
790778
message: '#^Method Ibexa\\Rest\\Input\\Handler\\Json\:\:jsonDecodeErrorMessage\(\) has parameter \$jsonErrorCode with no type specified\.$#'
791779
identifier: missingType.parameter
792780
count: 1
793781
path: src/lib/Input/Handler/Json.php
794782

795-
-
796-
message: '#^Method Ibexa\\Rest\\Input\\Handler\\Xml\:\:convert\(\) return type has no value type specified in iterable type array\.$#'
797-
identifier: missingType.iterableValue
798-
count: 1
799-
path: src/lib/Input/Handler/Xml.php
800-
801-
-
802-
message: '#^Method Ibexa\\Rest\\Input\\Handler\\Xml\:\:convertDom\(\) return type has no value type specified in iterable type array\.$#'
803-
identifier: missingType.iterableValue
804-
count: 1
805-
path: src/lib/Input/Handler/Xml.php
806-
807-
-
808-
message: '#^Method Ibexa\\Rest\\Input\\Handler\\Xml\:\:convertDom\(\) should return array but returns array\|string\.$#'
809-
identifier: return.type
810-
count: 1
811-
path: src/lib/Input/Handler/Xml.php
812-
813-
-
814-
message: '#^Method Ibexa\\Rest\\Input\\Handler\\Xml\:\:convertDom\(\) should return array but returns null\.$#'
815-
identifier: return.type
816-
count: 1
817-
path: src/lib/Input/Handler/Xml.php
818-
819783
-
820784
message: '#^Method Ibexa\\Rest\\Input\\Handler\\Xml\:\:parseFieldTypeHash\(\) return type has no value type specified in iterable type array\.$#'
821785
identifier: missingType.iterableValue
@@ -1440,24 +1404,6 @@ parameters:
14401404
count: 1
14411405
path: src/lib/Server/Controller/Content.php
14421406

1443-
-
1444-
message: '#^Parameter \#1 \$versions of class Ibexa\\Rest\\Server\\Values\\VersionList constructor expects array\<Ibexa\\Contracts\\Core\\Repository\\Values\\Content\\VersionInfo\>, iterable\<int, Ibexa\\Contracts\\Core\\Repository\\Values\\Content\\VersionInfo\> given\.$#'
1445-
identifier: argument.type
1446-
count: 1
1447-
path: src/lib/Server/Controller/Content.php
1448-
1449-
-
1450-
message: '#^Parameter \#3 \$relations of class Ibexa\\Rest\\Server\\Values\\Version constructor expects array\<Ibexa\\Contracts\\Core\\Repository\\Values\\Content\\Relation\>, iterable\<int, Ibexa\\Contracts\\Core\\Repository\\Values\\Content\\Relation\> given\.$#'
1451-
identifier: argument.type
1452-
count: 4
1453-
path: src/lib/Server/Controller/Content.php
1454-
1455-
-
1456-
message: '#^Parameter \#5 \$relations of class Ibexa\\Rest\\Server\\Values\\RestContent constructor expects array\<Ibexa\\Contracts\\Core\\Repository\\Values\\Content\\Relation\>\|null, iterable\<int, Ibexa\\Contracts\\Core\\Repository\\Values\\Content\\Relation\>\|null given\.$#'
1457-
identifier: argument.type
1458-
count: 2
1459-
path: src/lib/Server/Controller/Content.php
1460-
14611407
-
14621408
message: '#^Method Ibexa\\Rest\\Server\\Controller\\ContentType\:\:addContentTypeDraftFieldDefinition\(\) has parameter \$contentTypeId with no type specified\.$#'
14631409
identifier: missingType.parameter
@@ -2514,18 +2460,6 @@ parameters:
25142460
count: 1
25152461
path: src/lib/Server/Controller/User.php
25162462

2517-
-
2518-
message: '#^Parameter \#5 \$relations of class Ibexa\\Rest\\Server\\Values\\RestUser constructor expects array\<Ibexa\\Contracts\\Core\\Repository\\Values\\Content\\Relation\>, iterable\<int, Ibexa\\Contracts\\Core\\Repository\\Values\\Content\\Relation\> given\.$#'
2519-
identifier: argument.type
2520-
count: 5
2521-
path: src/lib/Server/Controller/User.php
2522-
2523-
-
2524-
message: '#^Parameter \#5 \$relations of class Ibexa\\Rest\\Server\\Values\\RestUserGroup constructor expects array\<Ibexa\\Contracts\\Core\\Repository\\Values\\Content\\Relation\>, iterable\<int, Ibexa\\Contracts\\Core\\Repository\\Values\\Content\\Relation\> given\.$#'
2525-
identifier: argument.type
2526-
count: 10
2527-
path: src/lib/Server/Controller/User.php
2528-
25292463
-
25302464
message: '#^Property Ibexa\\Rest\\Server\\Controller\\User\:\:\$csrfTokenStorage is never read, only written\.$#'
25312465
identifier: property.onlyWritten
@@ -2838,12 +2772,6 @@ parameters:
28382772
count: 1
28392773
path: src/lib/Server/Input/Parser/Criterion.php
28402774

2841-
-
2842-
message: '#^Possibly invalid array key type \(list\<string\>\|string\)\.$#'
2843-
identifier: offsetAccess.invalidOffset
2844-
count: 1
2845-
path: src/lib/Server/Input/Parser/Criterion.php
2846-
28472775
-
28482776
message: '#^Property Ibexa\\Rest\\Server\\Input\\Parser\\Criterion\:\:\$criterionIdMap type has no value type specified in iterable type array\.$#'
28492777
identifier: missingType.iterableValue
@@ -3858,12 +3786,6 @@ parameters:
38583786
count: 1
38593787
path: src/lib/Server/Output/ValueObjectVisitor/Location.php
38603788

3861-
-
3862-
message: '#^Parameter \#5 \$relations of class Ibexa\\Rest\\Server\\Values\\RestContent constructor expects array\<Ibexa\\Contracts\\Core\\Repository\\Values\\Content\\Relation\>\|null, iterable\<int, Ibexa\\Contracts\\Core\\Repository\\Values\\Content\\Relation\> given\.$#'
3863-
identifier: argument.type
3864-
count: 1
3865-
path: src/lib/Server/Output/ValueObjectVisitor/Location.php
3866-
38673789
-
38683790
message: '#^Method Ibexa\\Rest\\Server\\Output\\ValueObjectVisitor\\LocationList\:\:visit\(\) has no return type specified\.$#'
38693791
identifier: missingType.return
@@ -4050,12 +3972,6 @@ parameters:
40503972
count: 1
40513973
path: src/lib/Server/Output/ValueObjectVisitor/RestExecutedView.php
40523974

4053-
-
4054-
message: '#^Parameter \#5 \$relations of class Ibexa\\Rest\\Server\\Values\\RestContent constructor expects array\<Ibexa\\Contracts\\Core\\Repository\\Values\\Content\\Relation\>\|null, iterable\<int, Ibexa\\Contracts\\Core\\Repository\\Values\\Content\\Relation\> given\.$#'
4055-
identifier: argument.type
4056-
count: 1
4057-
path: src/lib/Server/Output/ValueObjectVisitor/RestExecutedView.php
4058-
40593975
-
40603976
message: '#^Method Ibexa\\Rest\\Server\\Output\\ValueObjectVisitor\\RestFieldDefinition\:\:visit\(\) has no return type specified\.$#'
40613977
identifier: missingType.return
@@ -4290,24 +4206,12 @@ parameters:
42904206
count: 1
42914207
path: src/lib/Server/Output/ValueObjectVisitor/User.php
42924208

4293-
-
4294-
message: '#^Parameter \#5 \$relations of class Ibexa\\Rest\\Server\\Values\\RestUser constructor expects array\<Ibexa\\Contracts\\Core\\Repository\\Values\\Content\\Relation\>, iterable\<int, Ibexa\\Contracts\\Core\\Repository\\Values\\Content\\Relation\> given\.$#'
4295-
identifier: argument.type
4296-
count: 1
4297-
path: src/lib/Server/Output/ValueObjectVisitor/User.php
4298-
42994209
-
43004210
message: '#^Parameter \#4 \$mainLocation of class Ibexa\\Rest\\Server\\Values\\RestUserGroup constructor expects Ibexa\\Contracts\\Core\\Repository\\Values\\Content\\Location, Ibexa\\Contracts\\Core\\Repository\\Values\\Content\\Location\|null given\.$#'
43014211
identifier: argument.type
43024212
count: 1
43034213
path: src/lib/Server/Output/ValueObjectVisitor/UserGroup.php
43044214

4305-
-
4306-
message: '#^Parameter \#5 \$relations of class Ibexa\\Rest\\Server\\Values\\RestUserGroup constructor expects array\<Ibexa\\Contracts\\Core\\Repository\\Values\\Content\\Relation\>, iterable\<int, Ibexa\\Contracts\\Core\\Repository\\Values\\Content\\Relation\> given\.$#'
4307-
identifier: argument.type
4308-
count: 1
4309-
path: src/lib/Server/Output/ValueObjectVisitor/UserGroup.php
4310-
43114215
-
43124216
message: '#^Method Ibexa\\Rest\\Server\\Output\\ValueObjectVisitor\\UserGroupList\:\:visit\(\) has no return type specified\.$#'
43134217
identifier: missingType.return

src/contracts/Input/Handler.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ abstract class Handler
1616
*
1717
* @param string $string
1818
*
19-
* @return array
19+
* @return array<mixed>|string|int|bool|float|null
20+
*
21+
* @throws \Ibexa\Contracts\Rest\Exceptions\Parser
2022
*/
2123
abstract public function convert($string);
2224
}

src/lib/Input/Dispatcher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public function parse(Message $message)
101101
$rawArray = $this->handlers[$format]->convert($message->body);
102102

103103
// Only 1 XML root node
104-
$rootNodeArray = reset($rawArray);
104+
$rootNodeArray = is_array($rawArray) ? reset($rawArray) : [];
105105

106106
// @todo: This needs to be refactored in order to make the called URL
107107
// available to parsers in the server in a sane way

src/lib/Input/Handler/Json.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,6 @@
1414
*/
1515
class Json extends Handler
1616
{
17-
/**
18-
* Converts the given string to an array structure.
19-
*
20-
* @throw Ibexa\Contracts\Rest\Exceptions\Parser
21-
*
22-
* @param string $string
23-
*
24-
* @return array
25-
*/
2617
public function convert($string)
2718
{
2819
$json = json_decode($string, true);

src/lib/Input/Handler/Xml.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,6 @@ class Xml extends Handler
7777
'validatorConfiguration',
7878
];
7979

80-
/**
81-
* Converts the given string to an array structure.
82-
*
83-
* @param string $string
84-
*
85-
* @return array
86-
*/
8780
public function convert($string)
8881
{
8982
$oldXmlErrorHandling = libxml_use_internal_errors(true);
@@ -118,9 +111,7 @@ public function convert($string)
118111
/**
119112
* Converts DOM nodes to array structures.
120113
*
121-
* @param \DOMNode $node
122-
*
123-
* @return array
114+
* @return array<mixed>|string|null
124115
*/
125116
protected function convertDom(\DOMNode $node)
126117
{
@@ -140,7 +131,7 @@ protected function convertDom(\DOMNode $node)
140131
case XML_ELEMENT_NODE:
141132
$tagName = $childNode->tagName;
142133

143-
if (in_array($tagName, $this->fieldTypeHashElements)) {
134+
if (in_array($tagName, $this->fieldTypeHashElements, true)) {
144135
$current[$tagName] = $this->parseFieldTypeHash($childNode);
145136
} elseif (!isset($current[$tagName])) {
146137
if (isset($this->forceList[$parentTagName]) &&
@@ -158,7 +149,7 @@ protected function convertDom(\DOMNode $node)
158149
$this->convertDom($childNode),
159150
];
160151
$isArray = true;
161-
} else {
152+
} elseif (!is_string($current[$tagName])) {
162153
$current[$tagName][] = $this->convertDom($childNode);
163154
}
164155

0 commit comments

Comments
 (0)