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(

0 commit comments

Comments
 (0)