Skip to content

Commit f6f2388

Browse files
committed
Phpstan-fixes
1 parent 6e48daf commit f6f2388

22 files changed

+2745
-353
lines changed

phpstan-baseline.neon

Lines changed: 2666 additions & 290 deletions
Large diffs are not rendered by default.

phpstan.neon

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
parameters:
2-
level: 8
2+
level: max
33
paths:
44
- ./src/
5-
ignoreErrors: []
5+
- ./tests/
66
phpVersion:
77
min: 70200
88
max: 80499

src/JsonSchema/Constraints/FormatConstraint.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public function check(&$element, $schema = null, ?JsonPointer $path = null, $i =
165165
}
166166
}
167167

168-
protected function validateDateTime($datetime, $format)
168+
protected function validateDateTime($datetime, $format): bool
169169
{
170170
$dt = \DateTime::createFromFormat($format, (string) $datetime);
171171

@@ -180,7 +180,7 @@ protected function validateDateTime($datetime, $format)
180180
return false;
181181
}
182182

183-
protected function validateRegex($regex)
183+
protected function validateRegex($regex): bool
184184
{
185185
if (!is_string($regex)) {
186186
return true;
@@ -189,7 +189,7 @@ protected function validateRegex($regex)
189189
return false !== @preg_match(self::jsonPatternToPhpRegex($regex), '');
190190
}
191191

192-
protected function validateColor($color)
192+
protected function validateColor($color): bool
193193
{
194194
if (!is_string($color)) {
195195
return true;
@@ -201,30 +201,30 @@ protected function validateColor($color)
201201
return true;
202202
}
203203

204-
return preg_match('/^#([a-f0-9]{3}|[a-f0-9]{6})$/i', $color);
204+
return 1 === preg_match('/^#([a-f0-9]{3}|[a-f0-9]{6})$/i', $color);
205205
}
206206

207-
protected function validateStyle($style)
207+
protected function validateStyle($style): bool
208208
{
209209
$properties = explode(';', rtrim($style, ';'));
210210
$invalidEntries = preg_grep('/^\s*[-a-z]+\s*:\s*.+$/i', $properties, PREG_GREP_INVERT);
211211

212212
return empty($invalidEntries);
213213
}
214214

215-
protected function validatePhone($phone)
215+
protected function validatePhone($phone): bool
216216
{
217-
return preg_match('/^\+?(\(\d{3}\)|\d{3}) \d{3} \d{4}$/', $phone);
217+
return 1 === preg_match('/^\+?(\(\d{3}\)|\d{3}) \d{3} \d{4}$/', $phone);
218218
}
219219

220-
protected function validateHostname($host)
220+
protected function validateHostname($host): bool
221221
{
222222
if (!is_string($host)) {
223223
return true;
224224
}
225225

226226
$hostnameRegex = '/^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$/i';
227227

228-
return preg_match($hostnameRegex, $host);
228+
return 1 === preg_match($hostnameRegex, $host);
229229
}
230230
}

src/JsonSchema/Constraints/NumberConstraint.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function check(&$element, $schema = null, ?JsonPointer $path = null, $i =
7070
$this->checkFormat($element, $schema, $path, $i);
7171
}
7272

73-
private function fmod($number1, $number2)
73+
private function fmod($number1, $number2): float
7474
{
7575
$modulus = ($number1 - round($number1 / $number2) * $number2);
7676
$precision = 0.0000000001;

src/JsonSchema/Constraints/ObjectConstraint.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function check(&$element, $schema = null, ?JsonPointer $path = null, $pro
5454
$this->validateElement($element, $matches, $schema, $path, $properties, $additionalProp);
5555
}
5656

57-
public function validatePatternProperties($element, ?JsonPointer $path, $patternProperties)
57+
public function validatePatternProperties($element, ?JsonPointer $path, $patternProperties): array
5858
{
5959
$matches = [];
6060
foreach ($patternProperties as $pregex => $schema) {
@@ -87,7 +87,7 @@ public function validatePatternProperties($element, ?JsonPointer $path, $pattern
8787
* @param mixed $additionalProp Additional properties
8888
*/
8989
public function validateElement($element, $matches, $schema = null, ?JsonPointer $path = null,
90-
$properties = null, $additionalProp = null)
90+
$properties = null, $additionalProp = null): void
9191
{
9292
$this->validateMinMaxConstraint($element, $schema, $path);
9393

@@ -131,7 +131,7 @@ public function validateElement($element, $matches, $schema = null, ?JsonPointer
131131
* @param \stdClass $properties Property definitions
132132
* @param JsonPointer|null $path Path?
133133
*/
134-
public function validateProperties(&$element, $properties = null, ?JsonPointer $path = null)
134+
public function validateProperties(&$element, $properties = null, ?JsonPointer $path = null): void
135135
{
136136
$undefinedConstraint = $this->factory->createInstanceFor('undefined');
137137

@@ -173,7 +173,7 @@ protected function &getProperty(&$element, $property, $fallback = null)
173173
* @param \stdClass $objectDefinition ObjectConstraint definition
174174
* @param JsonPointer|null $path Path to test?
175175
*/
176-
protected function validateMinMaxConstraint($element, $objectDefinition, ?JsonPointer $path = null)
176+
protected function validateMinMaxConstraint($element, $objectDefinition, ?JsonPointer $path = null): void
177177
{
178178
// Verify minimum number of properties
179179
if (isset($objectDefinition->minProperties) && !is_object($objectDefinition->minProperties)) {

src/JsonSchema/Constraints/StringConstraint.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function check(&$element, $schema = null, ?JsonPointer $path = null, $i =
5151
$this->checkFormat($element, $schema, $path, $i);
5252
}
5353

54-
private function strlen($string)
54+
private function strlen($string): int
5555
{
5656
if (extension_loaded('mbstring')) {
5757
return mb_strlen($string, mb_detect_encoding($string));

src/JsonSchema/Constraints/TypeCheck/LooseTypeCheck.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,23 @@
66

77
class LooseTypeCheck implements TypeCheckInterface
88
{
9-
public static function isObject($value)
9+
public static function isObject($value): bool
1010
{
1111
return
1212
is_object($value)
1313
|| (is_array($value) && (count($value) == 0 || self::isAssociativeArray($value)));
1414
}
1515

16-
public static function isArray($value)
16+
public static function isArray($value): bool
1717
{
1818
return
1919
is_array($value)
2020
&& (count($value) == 0 || !self::isAssociativeArray($value));
2121
}
2222

23+
/**
24+
* @return mixed
25+
*/
2326
public static function propertyGet($value, $property)
2427
{
2528
if (is_object($value)) {
@@ -29,7 +32,7 @@ public static function propertyGet($value, $property)
2932
return $value[$property];
3033
}
3134

32-
public static function propertySet(&$value, $property, $data)
35+
public static function propertySet(&$value, $property, $data): void
3336
{
3437
if (is_object($value)) {
3538
$value->{$property} = $data;
@@ -38,7 +41,7 @@ public static function propertySet(&$value, $property, $data)
3841
}
3942
}
4043

41-
public static function propertyExists($value, $property)
44+
public static function propertyExists($value, $property): bool
4245
{
4346
if (is_object($value)) {
4447
return property_exists($value, $property);
@@ -47,7 +50,7 @@ public static function propertyExists($value, $property)
4750
return array_key_exists($property, $value);
4851
}
4952

50-
public static function propertyCount($value)
53+
public static function propertyCount($value): int
5154
{
5255
if (is_object($value)) {
5356
return count(get_object_vars($value));

src/JsonSchema/Constraints/TypeCheck/StrictTypeCheck.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,35 @@
66

77
class StrictTypeCheck implements TypeCheckInterface
88
{
9-
public static function isObject($value)
9+
public static function isObject($value): bool
1010
{
1111
return is_object($value);
1212
}
1313

14-
public static function isArray($value)
14+
public static function isArray($value): bool
1515
{
1616
return is_array($value);
1717
}
1818

19+
/**
20+
* @return mixed
21+
*/
1922
public static function propertyGet($value, $property)
2023
{
2124
return $value->{$property};
2225
}
2326

24-
public static function propertySet(&$value, $property, $data)
27+
public static function propertySet(&$value, $property, $data): void
2528
{
2629
$value->{$property} = $data;
2730
}
2831

29-
public static function propertyExists($value, $property)
32+
public static function propertyExists($value, $property): bool
3033
{
3134
return property_exists($value, $property);
3235
}
3336

34-
public static function propertyCount($value)
37+
public static function propertyCount($value): int
3538
{
3639
if (!is_object($value)) {
3740
return 0;

src/JsonSchema/Constraints/TypeCheck/TypeCheckInterface.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,18 @@
66

77
interface TypeCheckInterface
88
{
9-
public static function isObject($value);
9+
public static function isObject($value): bool;
1010

11-
public static function isArray($value);
11+
public static function isArray($value): bool;
1212

13+
/**
14+
* @return mixed
15+
*/
1316
public static function propertyGet($value, $property);
1417

15-
public static function propertySet(&$value, $property, $data);
18+
public static function propertySet(&$value, $property, $data): void;
1619

17-
public static function propertyExists($value, $property);
20+
public static function propertyExists($value, $property): bool;
1821

19-
public static function propertyCount($value);
22+
public static function propertyCount($value): int;
2023
}

src/JsonSchema/Constraints/TypeConstraint.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function check(&$value = null, $schema = null, ?JsonPointer $path = null,
9090
* @param ?JsonPointer $path
9191
* @param bool $coerce
9292
*/
93-
protected function validateTypesArray(&$value, array $type, &$validTypesWording, &$isValid, $path, $coerce = false)
93+
protected function validateTypesArray(&$value, array $type, &$validTypesWording, &$isValid, $path, $coerce = false): void
9494
{
9595
foreach ($type as $tp) {
9696
// already valid, so no need to waste cycles looping over everything
@@ -151,7 +151,7 @@ protected function implodeWith(array $elements, $delimiter = ', ', $listEnd = fa
151151
*
152152
* @throws StandardUnexpectedValueException
153153
*/
154-
protected function validateTypeNameWording($type)
154+
protected function validateTypeNameWording($type): void
155155
{
156156
if (!array_key_exists($type, self::$wording)) {
157157
throw new StandardUnexpectedValueException(

src/JsonSchema/Constraints/UndefinedConstraint.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function check(&$value, $schema = null, ?JsonPointer $path = null, $i = n
6363
* @param JsonPointer $path
6464
* @param string $i
6565
*/
66-
public function validateTypes(&$value, $schema, JsonPointer $path, $i = null)
66+
public function validateTypes(&$value, $schema, JsonPointer $path, $i = null): void
6767
{
6868
// check array
6969
if ($this->getTypeCheck()->isArray($value)) {
@@ -114,7 +114,7 @@ public function validateTypes(&$value, $schema, JsonPointer $path, $i = null)
114114
* @param JsonPointer $path
115115
* @param string $i
116116
*/
117-
protected function validateCommonProperties(&$value, $schema, JsonPointer $path, $i = '')
117+
protected function validateCommonProperties(&$value, $schema, JsonPointer $path, $i = ''): void
118118
{
119119
// if it extends another schema, it must pass that schema as well
120120
if (isset($schema->extends)) {
@@ -311,7 +311,7 @@ protected function applyDefaultValues(&$value, $schema, $path): void
311311
* @param JsonPointer $path
312312
* @param string $i
313313
*/
314-
protected function validateOfProperties(&$value, $schema, JsonPointer $path, $i = '')
314+
protected function validateOfProperties(&$value, $schema, JsonPointer $path, $i = ''): void
315315
{
316316
// Verify type
317317
if ($value instanceof self) {
@@ -385,7 +385,7 @@ protected function validateOfProperties(&$value, $schema, JsonPointer $path, $i
385385
* @param JsonPointer $path
386386
* @param string $i
387387
*/
388-
protected function validateDependencies($value, $dependencies, JsonPointer $path, $i = '')
388+
protected function validateDependencies($value, $dependencies, JsonPointer $path, $i = ''): void
389389
{
390390
foreach ($dependencies as $key => $dependency) {
391391
if ($this->getTypeCheck()->propertyExists($value, $key)) {
@@ -415,7 +415,7 @@ protected function validateDependencies($value, $dependencies, JsonPointer $path
415415
}
416416
}
417417

418-
protected function validateUri($schema, $schemaUri = null)
418+
protected function validateUri($schema, $schemaUri = null): ?object
419419
{
420420
$resolver = new UriResolver();
421421
$retriever = $this->factory->getUriRetriever();

src/JsonSchema/Entity/JsonPointer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public function __toString()
140140
/**
141141
* Mark the value at this path as being set from a schema default
142142
*/
143-
public function setFromDefault()
143+
public function setFromDefault(): void
144144
{
145145
$this->fromDefault = true;
146146
}

src/JsonSchema/Iterator/ObjectIterator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public function count(): int
100100
/**
101101
* Initializer
102102
*/
103-
private function initialize()
103+
private function initialize(): void
104104
{
105105
if (!$this->initialized) {
106106
$this->data = $this->buildDataFromObject($this->object);

src/JsonSchema/SchemaStorage.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function getUriResolver()
4545
/**
4646
* {@inheritdoc}
4747
*/
48-
public function addSchema($id, $schema = null)
48+
public function addSchema($id, $schema = null): void
4949
{
5050
if (is_null($schema) && $id !== self::INTERNAL_PROVIDED_SCHEMA_URI) {
5151
// if the schema was user-provided to Validator and is still null, then assume this is
@@ -82,7 +82,7 @@ public function addSchema($id, $schema = null)
8282
* @param mixed $schema
8383
* @param string $base
8484
*/
85-
private function expandRefs(&$schema, $base = null)
85+
private function expandRefs(&$schema, $base = null): void
8686
{
8787
if (!is_object($schema)) {
8888
if (is_array($schema)) {

src/JsonSchema/SchemaStorageInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ interface SchemaStorageInterface
1212
* @param string $id
1313
* @param object $schema
1414
*/
15-
public function addSchema($id, $schema = null);
15+
public function addSchema($id, $schema = null): void;
1616

1717
/**
1818
* Returns schema for given identifier, or null if it does not exist

src/JsonSchema/Uri/Retrievers/Curl.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function retrieve($uri)
6161
/**
6262
* @param string $response cURL HTTP response
6363
*/
64-
private function fetchMessageBody($response)
64+
private function fetchMessageBody($response): void
6565
{
6666
preg_match("/(?:\r\n){2}(.*)$/ms", $response, $match);
6767
$this->messageBody = $match[1];

src/JsonSchema/Uri/UriRetriever.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class UriRetriever implements BaseUriRetrieverInterface
5959
*
6060
* @param string $endpoint
6161
*/
62-
public function addInvalidContentTypeEndpoint($endpoint)
62+
public function addInvalidContentTypeEndpoint($endpoint): void
6363
{
6464
$this->allowedInvalidContentTypeEndpoints[] = $endpoint;
6565
}
@@ -329,15 +329,15 @@ public function isValid($uri)
329329
/**
330330
* Set a URL translation rule
331331
*/
332-
public function setTranslation($from, $to)
332+
public function setTranslation($from, $to): void
333333
{
334334
$this->translationMap[$from] = $to;
335335
}
336336

337337
/**
338338
* Apply URI translation rules
339339
*/
340-
public function translate($uri)
340+
public function translate($uri): string
341341
{
342342
foreach ($this->translationMap as $from => $to) {
343343
$uri = preg_replace($from, $to, $uri);

0 commit comments

Comments
 (0)