Skip to content

Commit afee666

Browse files
authored
More-phpstan-typing (#781)
1 parent 56f34b8 commit afee666

21 files changed

+120
-342
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ coverage
1010
composer.lock
1111
docs-api
1212
phpunit.xml
13+
.phpunit.result.cache

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
## [Unreleased]
99
### Changed
1010
- Used PHPStan's int-mask-of<T> type where applicable ([#779](https://github.com/jsonrainbow/json-schema/pull/779))
11+
- Fixed some PHPStan errors ([#781](https://github.com/jsonrainbow/json-schema/pull/781))
1112

1213
## [6.1.0] - 2025-02-04
1314
### Added

bin/validate-json

+1-3
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,8 @@ if (count($arArgs) == 1) {
6060

6161
/**
6262
* Show the json parse error that happened last
63-
*
64-
* @return void
6563
*/
66-
function showJsonError()
64+
function showJsonError(): void
6765
{
6866
$constants = get_defined_constants(true);
6967
$json_errors = [];

composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
"style-fix": "php-cs-fixer fix --verbose",
7979
"test": "phpunit",
8080
"testOnly": "phpunit --colors --filter",
81-
"phpstan": "@php phpstan"
81+
"phpstan": "@php phpstan",
82+
"phpstan-generate-baseline": "@php phpstan --generate-baseline"
8283
}
8384
}

phpstan-baseline.neon

+5-190
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,10 @@
11
parameters:
22
ignoreErrors:
3-
-
4-
message: "#^Method JsonSchema\\\\Constraints\\\\BaseConstraint\\:\\:addError\\(\\) has no return type specified\\.$#"
5-
count: 1
6-
path: src/JsonSchema/Constraints/BaseConstraint.php
7-
83
-
94
message: "#^Method JsonSchema\\\\Constraints\\\\BaseConstraint\\:\\:addError\\(\\) has parameter \\$more with no value type specified in iterable type array\\.$#"
105
count: 1
116
path: src/JsonSchema/Constraints/BaseConstraint.php
127

13-
-
14-
message: "#^Method JsonSchema\\\\Constraints\\\\BaseConstraint\\:\\:addErrors\\(\\) has no return type specified\\.$#"
15-
count: 1
16-
path: src/JsonSchema/Constraints/BaseConstraint.php
17-
188
-
199
message: "#^Method JsonSchema\\\\Constraints\\\\BaseConstraint\\:\\:addErrors\\(\\) has parameter \\$errors with no value type specified in iterable type array\\.$#"
2010
count: 1
@@ -26,32 +16,7 @@ parameters:
2616
path: src/JsonSchema/Constraints/BaseConstraint.php
2717

2818
-
29-
message: "#^Method JsonSchema\\\\Constraints\\\\BaseConstraint\\:\\:getErrors\\(\\) has no return type specified\\.$#"
30-
count: 1
31-
path: src/JsonSchema/Constraints/BaseConstraint.php
32-
33-
-
34-
message: "#^Method JsonSchema\\\\Constraints\\\\BaseConstraint\\:\\:getErrors\\(\\) has parameter \\$errorContext with no type specified\\.$#"
35-
count: 1
36-
path: src/JsonSchema/Constraints/BaseConstraint.php
37-
38-
-
39-
message: "#^Method JsonSchema\\\\Constraints\\\\BaseConstraint\\:\\:isValid\\(\\) has no return type specified\\.$#"
40-
count: 1
41-
path: src/JsonSchema/Constraints/BaseConstraint.php
42-
43-
-
44-
message: "#^Method JsonSchema\\\\Constraints\\\\BaseConstraint\\:\\:numErrors\\(\\) has no return type specified\\.$#"
45-
count: 1
46-
path: src/JsonSchema/Constraints/BaseConstraint.php
47-
48-
-
49-
message: "#^Method JsonSchema\\\\Constraints\\\\BaseConstraint\\:\\:numErrors\\(\\) has parameter \\$errorContext with no type specified\\.$#"
50-
count: 1
51-
path: src/JsonSchema/Constraints/BaseConstraint.php
52-
53-
-
54-
message: "#^Method JsonSchema\\\\Constraints\\\\BaseConstraint\\:\\:reset\\(\\) has no return type specified\\.$#"
19+
message: "#^Method JsonSchema\\\\Constraints\\\\BaseConstraint\\:\\:getErrors\\(\\) return type has no value type specified in iterable type array\\.$#"
5520
count: 1
5621
path: src/JsonSchema/Constraints/BaseConstraint.php
5722

@@ -65,11 +30,6 @@ parameters:
6530
count: 1
6631
path: src/JsonSchema/Constraints/BaseConstraint.php
6732

68-
-
69-
message: "#^Ternary operator condition is always true\\.$#"
70-
count: 2
71-
path: src/JsonSchema/Constraints/BaseConstraint.php
72-
7333
-
7434
message: "#^Cannot access property \\$additionalItems on stdClass\\|null\\.$#"
7535
count: 3
@@ -80,16 +40,6 @@ parameters:
8040
count: 6
8141
path: src/JsonSchema/Constraints/CollectionConstraint.php
8242

83-
-
84-
message: "#^Method JsonSchema\\\\Constraints\\\\CollectionConstraint\\:\\:check\\(\\) has no return type specified\\.$#"
85-
count: 1
86-
path: src/JsonSchema/Constraints/CollectionConstraint.php
87-
88-
-
89-
message: "#^Method JsonSchema\\\\Constraints\\\\CollectionConstraint\\:\\:validateItems\\(\\) has no return type specified\\.$#"
90-
count: 1
91-
path: src/JsonSchema/Constraints/CollectionConstraint.php
92-
9343
-
9444
message: "#^Method JsonSchema\\\\Constraints\\\\CollectionConstraint\\:\\:validateItems\\(\\) has parameter \\$value with no value type specified in iterable type array\\.$#"
9545
count: 1
@@ -105,61 +55,11 @@ parameters:
10555
count: 1
10656
path: src/JsonSchema/Constraints/CollectionConstraint.php
10757

108-
-
109-
message: "#^Method JsonSchema\\\\Constraints\\\\ConstConstraint\\:\\:check\\(\\) has no return type specified\\.$#"
110-
count: 1
111-
path: src/JsonSchema/Constraints/ConstConstraint.php
112-
113-
-
114-
message: "#^Method JsonSchema\\\\Constraints\\\\Constraint\\:\\:checkArray\\(\\) has no return type specified\\.$#"
115-
count: 1
116-
path: src/JsonSchema/Constraints/Constraint.php
117-
118-
-
119-
message: "#^Method JsonSchema\\\\Constraints\\\\Constraint\\:\\:checkConst\\(\\) has no return type specified\\.$#"
120-
count: 1
121-
path: src/JsonSchema/Constraints/Constraint.php
122-
123-
-
124-
message: "#^Method JsonSchema\\\\Constraints\\\\Constraint\\:\\:checkEnum\\(\\) has no return type specified\\.$#"
125-
count: 1
126-
path: src/JsonSchema/Constraints/Constraint.php
127-
128-
-
129-
message: "#^Method JsonSchema\\\\Constraints\\\\Constraint\\:\\:checkFormat\\(\\) has no return type specified\\.$#"
130-
count: 1
131-
path: src/JsonSchema/Constraints/Constraint.php
132-
133-
-
134-
message: "#^Method JsonSchema\\\\Constraints\\\\Constraint\\:\\:checkNumber\\(\\) has no return type specified\\.$#"
135-
count: 1
136-
path: src/JsonSchema/Constraints/Constraint.php
137-
138-
-
139-
message: "#^Method JsonSchema\\\\Constraints\\\\Constraint\\:\\:checkObject\\(\\) has no return type specified\\.$#"
140-
count: 1
141-
path: src/JsonSchema/Constraints/Constraint.php
142-
14358
-
14459
message: "#^Method JsonSchema\\\\Constraints\\\\Constraint\\:\\:checkObject\\(\\) has parameter \\$appliedDefaults with no type specified\\.$#"
14560
count: 1
14661
path: src/JsonSchema/Constraints/Constraint.php
14762

148-
-
149-
message: "#^Method JsonSchema\\\\Constraints\\\\Constraint\\:\\:checkString\\(\\) has no return type specified\\.$#"
150-
count: 1
151-
path: src/JsonSchema/Constraints/Constraint.php
152-
153-
-
154-
message: "#^Method JsonSchema\\\\Constraints\\\\Constraint\\:\\:checkType\\(\\) has no return type specified\\.$#"
155-
count: 1
156-
path: src/JsonSchema/Constraints/Constraint.php
157-
158-
-
159-
message: "#^Method JsonSchema\\\\Constraints\\\\Constraint\\:\\:checkUndefined\\(\\) has no return type specified\\.$#"
160-
count: 1
161-
path: src/JsonSchema/Constraints/Constraint.php
162-
16363
-
16464
message: "#^Method JsonSchema\\\\Constraints\\\\Constraint\\:\\:checkUndefined\\(\\) has parameter \\$fromDefault with no type specified\\.$#"
16565
count: 1
@@ -170,31 +70,16 @@ parameters:
17070
count: 1
17171
path: src/JsonSchema/Constraints/Constraint.php
17272

173-
-
174-
message: "#^Method JsonSchema\\\\Constraints\\\\ConstraintInterface\\:\\:addError\\(\\) has no return type specified\\.$#"
175-
count: 1
176-
path: src/JsonSchema/Constraints/ConstraintInterface.php
177-
17873
-
17974
message: "#^Method JsonSchema\\\\Constraints\\\\ConstraintInterface\\:\\:addError\\(\\) has parameter \\$more with no value type specified in iterable type array\\.$#"
18075
count: 1
18176
path: src/JsonSchema/Constraints/ConstraintInterface.php
18277

183-
-
184-
message: "#^Method JsonSchema\\\\Constraints\\\\ConstraintInterface\\:\\:addErrors\\(\\) has no return type specified\\.$#"
185-
count: 1
186-
path: src/JsonSchema/Constraints/ConstraintInterface.php
187-
18878
-
18979
message: "#^Method JsonSchema\\\\Constraints\\\\ConstraintInterface\\:\\:addErrors\\(\\) has parameter \\$errors with no value type specified in iterable type array\\.$#"
19080
count: 1
19181
path: src/JsonSchema/Constraints/ConstraintInterface.php
19282

193-
-
194-
message: "#^Method JsonSchema\\\\Constraints\\\\ConstraintInterface\\:\\:check\\(\\) has no return type specified\\.$#"
195-
count: 1
196-
path: src/JsonSchema/Constraints/ConstraintInterface.php
197-
19883
-
19984
message: "#^Method JsonSchema\\\\Constraints\\\\ConstraintInterface\\:\\:getErrors\\(\\) return type has no value type specified in iterable type array\\.$#"
20085
count: 1
@@ -205,49 +90,24 @@ parameters:
20590
count: 1
20691
path: src/JsonSchema/Constraints/ConstraintInterface.php
20792

208-
-
209-
message: "#^Method JsonSchema\\\\Constraints\\\\EnumConstraint\\:\\:check\\(\\) has no return type specified\\.$#"
210-
count: 1
211-
path: src/JsonSchema/Constraints/EnumConstraint.php
212-
213-
-
214-
message: "#^Method JsonSchema\\\\Constraints\\\\Factory\\:\\:addConfig\\(\\) has no return type specified\\.$#"
215-
count: 1
216-
path: src/JsonSchema/Constraints/Factory.php
217-
21893
-
21994
message: "#^Method JsonSchema\\\\Constraints\\\\Factory\\:\\:createInstanceFor\\(\\) should return JsonSchema\\\\Constraints\\\\BaseConstraint&JsonSchema\\\\Constraints\\\\ConstraintInterface but returns object\\.$#"
22095
count: 1
22196
path: src/JsonSchema/Constraints/Factory.php
22297

22398
-
224-
message: "#^Method JsonSchema\\\\Constraints\\\\Factory\\:\\:getErrorContext\\(\\) should return 1\\|2 but returns int\\.$#"
225-
count: 1
226-
path: src/JsonSchema/Constraints/Factory.php
227-
228-
-
229-
message: "#^Method JsonSchema\\\\Constraints\\\\Factory\\:\\:getSchemaStorage\\(\\) has no return type specified\\.$#"
99+
message: "#^Method JsonSchema\\\\Constraints\\\\Factory\\:\\:getConfig\\(\\) should return int\\<0, 511\\> but returns int\\.$#"
230100
count: 1
231101
path: src/JsonSchema/Constraints/Factory.php
232102

233103
-
234-
message: "#^Method JsonSchema\\\\Constraints\\\\Factory\\:\\:getTypeCheck\\(\\) has no return type specified\\.$#"
235-
count: 1
236-
path: src/JsonSchema/Constraints/Factory.php
237-
238-
-
239-
message: "#^Method JsonSchema\\\\Constraints\\\\Factory\\:\\:removeConfig\\(\\) has no return type specified\\.$#"
240-
count: 1
241-
path: src/JsonSchema/Constraints/Factory.php
242-
243-
-
244-
message: "#^Method JsonSchema\\\\Constraints\\\\Factory\\:\\:setConfig\\(\\) has no return type specified\\.$#"
104+
message: "#^Method JsonSchema\\\\Constraints\\\\Factory\\:\\:getErrorContext\\(\\) should return 1\\|2 but returns int\\.$#"
245105
count: 1
246106
path: src/JsonSchema/Constraints/Factory.php
247107

248108
-
249-
message: "#^Method JsonSchema\\\\Constraints\\\\Factory\\:\\:setErrorContext\\(\\) has no return type specified\\.$#"
250-
count: 1
109+
message: "#^Property JsonSchema\\\\Constraints\\\\Factory\\:\\:\\$checkMode \\(int\\<0, 511\\>\\) does not accept int\\.$#"
110+
count: 2
251111
path: src/JsonSchema/Constraints/Factory.php
252112

253113
-
@@ -265,11 +125,6 @@ parameters:
265125
count: 1
266126
path: src/JsonSchema/Constraints/Factory.php
267127

268-
-
269-
message: "#^Method JsonSchema\\\\Constraints\\\\FormatConstraint\\:\\:check\\(\\) has no return type specified\\.$#"
270-
count: 1
271-
path: src/JsonSchema/Constraints/FormatConstraint.php
272-
273128
-
274129
message: "#^Method JsonSchema\\\\Constraints\\\\FormatConstraint\\:\\:validateColor\\(\\) has no return type specified\\.$#"
275130
count: 1
@@ -335,11 +190,6 @@ parameters:
335190
count: 1
336191
path: src/JsonSchema/Constraints/FormatConstraint.php
337192

338-
-
339-
message: "#^Method JsonSchema\\\\Constraints\\\\NumberConstraint\\:\\:check\\(\\) has no return type specified\\.$#"
340-
count: 1
341-
path: src/JsonSchema/Constraints/NumberConstraint.php
342-
343193
-
344194
message: "#^Method JsonSchema\\\\Constraints\\\\NumberConstraint\\:\\:fmod\\(\\) has no return type specified\\.$#"
345195
count: 1
@@ -365,11 +215,6 @@ parameters:
365215
count: 1
366216
path: src/JsonSchema/Constraints/ObjectConstraint.php
367217

368-
-
369-
message: "#^Method JsonSchema\\\\Constraints\\\\ObjectConstraint\\:\\:check\\(\\) has no return type specified\\.$#"
370-
count: 1
371-
path: src/JsonSchema/Constraints/ObjectConstraint.php
372-
373218
-
374219
message: "#^Method JsonSchema\\\\Constraints\\\\ObjectConstraint\\:\\:check\\(\\) has parameter \\$additionalProp with no type specified\\.$#"
375220
count: 1
@@ -430,16 +275,6 @@ parameters:
430275
count: 1
431276
path: src/JsonSchema/Constraints/ObjectConstraint.php
432277

433-
-
434-
message: "#^Method JsonSchema\\\\Constraints\\\\SchemaConstraint\\:\\:check\\(\\) has no return type specified\\.$#"
435-
count: 1
436-
path: src/JsonSchema/Constraints/SchemaConstraint.php
437-
438-
-
439-
message: "#^Method JsonSchema\\\\Constraints\\\\StringConstraint\\:\\:check\\(\\) has no return type specified\\.$#"
440-
count: 1
441-
path: src/JsonSchema/Constraints/StringConstraint.php
442-
443278
-
444279
message: "#^Method JsonSchema\\\\Constraints\\\\StringConstraint\\:\\:strlen\\(\\) has no return type specified\\.$#"
445280
count: 1
@@ -700,11 +535,6 @@ parameters:
700535
count: 1
701536
path: src/JsonSchema/Constraints/TypeCheck/TypeCheckInterface.php
702537

703-
-
704-
message: "#^Method JsonSchema\\\\Constraints\\\\TypeConstraint\\:\\:check\\(\\) has no return type specified\\.$#"
705-
count: 1
706-
path: src/JsonSchema/Constraints/TypeConstraint.php
707-
708538
-
709539
message: "#^Method JsonSchema\\\\Constraints\\\\TypeConstraint\\:\\:implodeWith\\(\\) has parameter \\$elements with no value type specified in iterable type array\\.$#"
710540
count: 1
@@ -750,16 +580,6 @@ parameters:
750580
count: 1
751581
path: src/JsonSchema/Constraints/TypeConstraint.php
752582

753-
-
754-
message: "#^Method JsonSchema\\\\Constraints\\\\UndefinedConstraint\\:\\:applyDefaultValues\\(\\) has no return type specified\\.$#"
755-
count: 1
756-
path: src/JsonSchema/Constraints/UndefinedConstraint.php
757-
758-
-
759-
message: "#^Method JsonSchema\\\\Constraints\\\\UndefinedConstraint\\:\\:check\\(\\) has no return type specified\\.$#"
760-
count: 1
761-
path: src/JsonSchema/Constraints/UndefinedConstraint.php
762-
763583
-
764584
message: "#^Method JsonSchema\\\\Constraints\\\\UndefinedConstraint\\:\\:check\\(\\) has parameter \\$fromDefault with no type specified\\.$#"
765585
count: 1
@@ -805,11 +625,6 @@ parameters:
805625
count: 1
806626
path: src/JsonSchema/Constraints/UndefinedConstraint.php
807627

808-
-
809-
message: "#^Parameter \\#1 \\$requiredOnly of method JsonSchema\\\\Constraints\\\\UndefinedConstraint\\:\\:shouldApplyDefaultValue\\(\\) expects bool, int given\\.$#"
810-
count: 3
811-
path: src/JsonSchema/Constraints/UndefinedConstraint.php
812-
813628
-
814629
message: "#^Property JsonSchema\\\\Constraints\\\\UndefinedConstraint\\:\\:\\$appliedDefaults type has no value type specified in iterable type array\\.$#"
815630
count: 1

phpstan.neon

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ parameters:
33
paths:
44
- ./src/
55
ignoreErrors: []
6+
phpVersion: 70200
67

78
includes:
89
- phpstan-baseline.neon

0 commit comments

Comments
 (0)