Skip to content

Commit bd4d321

Browse files
committed
fix: Port #717: Fixes for implicit nullability deprecation
See #717
1 parent 5224ee9 commit bd4d321

17 files changed

+42
-42
lines changed

src/JsonSchema/Constraints/BaseConstraint.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ class BaseConstraint
3939
/**
4040
* @param Factory $factory
4141
*/
42-
public function __construct(Factory $factory = null)
42+
public function __construct(?Factory $factory = null)
4343
{
4444
$this->factory = $factory ?: new Factory();
4545
}
4646

47-
public function addError(ConstraintError $constraint, JsonPointer $path = null, array $more = array())
47+
public function addError(ConstraintError $constraint, ?JsonPointer $path = null, array $more = array())
4848
{
4949
$message = $constraint ? $constraint->getMessage() : '';
5050
$name = $constraint ? $constraint->getValue() : '';

src/JsonSchema/Constraints/CollectionConstraint.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class CollectionConstraint extends Constraint
2323
/**
2424
* {@inheritdoc}
2525
*/
26-
public function check(&$value, $schema = null, JsonPointer $path = null, $i = null)
26+
public function check(&$value, $schema = null, ?JsonPointer $path = null, $i = null)
2727
{
2828
// Verify minItems
2929
if (isset($schema->minItems) && count($value) < $schema->minItems) {
@@ -62,7 +62,7 @@ public function check(&$value, $schema = null, JsonPointer $path = null, $i = nu
6262
* @param JsonPointer|null $path
6363
* @param string $i
6464
*/
65-
protected function validateItems(&$value, $schema = null, JsonPointer $path = null, $i = null)
65+
protected function validateItems(&$value, $schema = null, ?JsonPointer $path = null, $i = null)
6666
{
6767
if (is_object($schema->items)) {
6868
// just one type definition for the whole array

src/JsonSchema/Constraints/ConstConstraint.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class ConstConstraint extends Constraint
2323
/**
2424
* {@inheritdoc}
2525
*/
26-
public function check(&$element, $schema = null, JsonPointer $path = null, $i = null)
26+
public function check(&$element, $schema = null, ?JsonPointer $path = null, $i = null)
2727
{
2828
// Only validate const if the attribute exists
2929
if ($element instanceof UndefinedConstraint && (!isset($schema->required) || !$schema->required)) {

src/JsonSchema/Constraints/Constraint.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ abstract class Constraint extends BaseConstraint implements ConstraintInterface
4040
*
4141
* @return JsonPointer;
4242
*/
43-
protected function incrementPath(JsonPointer $path = null, $i)
43+
protected function incrementPath(?JsonPointer $path = null, $i)
4444
{
4545
$path = $path ?: new JsonPointer('');
4646

@@ -66,7 +66,7 @@ protected function incrementPath(JsonPointer $path = null, $i)
6666
* @param JsonPointer|null $path
6767
* @param mixed $i
6868
*/
69-
protected function checkArray(&$value, $schema = null, JsonPointer $path = null, $i = null)
69+
protected function checkArray(&$value, $schema = null, ?JsonPointer $path = null, $i = null)
7070
{
7171
$validator = $this->factory->createInstanceFor('collection');
7272
$validator->check($value, $schema, $path, $i);
@@ -84,7 +84,7 @@ protected function checkArray(&$value, $schema = null, JsonPointer $path = null,
8484
* @param mixed $additionalProperties
8585
* @param mixed $patternProperties
8686
*/
87-
protected function checkObject(&$value, $schema = null, JsonPointer $path = null, $properties = null,
87+
protected function checkObject(&$value, $schema = null, ?JsonPointer $path = null, $properties = null,
8888
$additionalProperties = null, $patternProperties = null, $appliedDefaults = array())
8989
{
9090
/** @var ObjectConstraint $validator */
@@ -102,7 +102,7 @@ protected function checkObject(&$value, $schema = null, JsonPointer $path = null
102102
* @param JsonPointer|null $path
103103
* @param mixed $i
104104
*/
105-
protected function checkType(&$value, $schema = null, JsonPointer $path = null, $i = null)
105+
protected function checkType(&$value, $schema = null, ?JsonPointer $path = null, $i = null)
106106
{
107107
$validator = $this->factory->createInstanceFor('type');
108108
$validator->check($value, $schema, $path, $i);
@@ -118,7 +118,7 @@ protected function checkType(&$value, $schema = null, JsonPointer $path = null,
118118
* @param JsonPointer|null $path
119119
* @param mixed $i
120120
*/
121-
protected function checkUndefined(&$value, $schema = null, JsonPointer $path = null, $i = null, $fromDefault = false)
121+
protected function checkUndefined(&$value, $schema = null, ?JsonPointer $path = null, $i = null, $fromDefault = false)
122122
{
123123
/** @var UndefinedConstraint $validator */
124124
$validator = $this->factory->createInstanceFor('undefined');
@@ -136,7 +136,7 @@ protected function checkUndefined(&$value, $schema = null, JsonPointer $path = n
136136
* @param JsonPointer|null $path
137137
* @param mixed $i
138138
*/
139-
protected function checkString($value, $schema = null, JsonPointer $path = null, $i = null)
139+
protected function checkString($value, $schema = null, ?JsonPointer $path = null, $i = null)
140140
{
141141
$validator = $this->factory->createInstanceFor('string');
142142
$validator->check($value, $schema, $path, $i);
@@ -147,12 +147,12 @@ protected function checkString($value, $schema = null, JsonPointer $path = null,
147147
/**
148148
* Checks a number element
149149
*
150-
* @param mixed $value
151-
* @param mixed $schema
152-
* @param JsonPointer $path
153-
* @param mixed $i
150+
* @param mixed $value
151+
* @param mixed $schema
152+
* @param JsonPointer|null $path
153+
* @param mixed $i
154154
*/
155-
protected function checkNumber($value, $schema = null, JsonPointer $path = null, $i = null)
155+
protected function checkNumber($value, $schema = null, ?JsonPointer $path = null, $i = null)
156156
{
157157
$validator = $this->factory->createInstanceFor('number');
158158
$validator->check($value, $schema, $path, $i);
@@ -168,7 +168,7 @@ protected function checkNumber($value, $schema = null, JsonPointer $path = null,
168168
* @param JsonPointer|null $path
169169
* @param mixed $i
170170
*/
171-
protected function checkEnum($value, $schema = null, JsonPointer $path = null, $i = null)
171+
protected function checkEnum($value, $schema = null, ?JsonPointer $path = null, $i = null)
172172
{
173173
$validator = $this->factory->createInstanceFor('enum');
174174
$validator->check($value, $schema, $path, $i);
@@ -184,7 +184,7 @@ protected function checkEnum($value, $schema = null, JsonPointer $path = null, $
184184
* @param JsonPointer|null $path
185185
* @param mixed $i
186186
*/
187-
protected function checkConst($value, $schema = null, JsonPointer $path = null, $i = null)
187+
protected function checkConst($value, $schema = null, ?JsonPointer $path = null, $i = null)
188188
{
189189
$validator = $this->factory->createInstanceFor('const');
190190
$validator->check($value, $schema, $path, $i);
@@ -200,7 +200,7 @@ protected function checkConst($value, $schema = null, JsonPointer $path = null,
200200
* @param JsonPointer|null $path
201201
* @param mixed $i
202202
*/
203-
protected function checkFormat($value, $schema = null, JsonPointer $path = null, $i = null)
203+
protected function checkFormat($value, $schema = null, ?JsonPointer $path = null, $i = null)
204204
{
205205
$validator = $this->factory->createInstanceFor('format');
206206
$validator->check($value, $schema, $path, $i);

src/JsonSchema/Constraints/ConstraintInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function addErrors(array $errors);
4040
* @param JsonPointer|null $path
4141
* @param array $more more array elements to add to the error
4242
*/
43-
public function addError(ConstraintError $constraint, JsonPointer $path = null, array $more = array());
43+
public function addError(ConstraintError $constraint, ?JsonPointer $path = null, array $more = array());
4444

4545
/**
4646
* checks if the validator has not raised errors
@@ -61,5 +61,5 @@ public function isValid();
6161
*
6262
* @throws \JsonSchema\Exception\ExceptionInterface
6363
*/
64-
public function check(&$value, $schema = null, JsonPointer $path = null, $i = null);
64+
public function check(&$value, $schema = null, ?JsonPointer $path = null, $i = null);
6565
}

src/JsonSchema/Constraints/EnumConstraint.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class EnumConstraint extends Constraint
2424
/**
2525
* {@inheritdoc}
2626
*/
27-
public function check(&$element, $schema = null, JsonPointer $path = null, $i = null)
27+
public function check(&$element, $schema = null, ?JsonPointer $path = null, $i = null)
2828
{
2929
// Only validate enum if the attribute exists
3030
if ($element instanceof UndefinedConstraint && (!isset($schema->required) || !$schema->required)) {

src/JsonSchema/Constraints/Factory.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,13 @@ class Factory
7070
private $instanceCache = array();
7171

7272
/**
73-
* @param SchemaStorage $schemaStorage
74-
* @param UriRetrieverInterface $uriRetriever
75-
* @param int $checkMode
73+
* @param ?SchemaStorage $schemaStorage
74+
* @param ?UriRetrieverInterface $uriRetriever
75+
* @param int $checkMode
7676
*/
7777
public function __construct(
78-
SchemaStorageInterface $schemaStorage = null,
79-
UriRetrieverInterface $uriRetriever = null,
78+
?SchemaStorageInterface $schemaStorage = null,
79+
?UriRetrieverInterface $uriRetriever = null,
8080
$checkMode = Constraint::CHECK_MODE_NORMAL
8181
) {
8282
// set provided config options

src/JsonSchema/Constraints/FormatConstraint.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class FormatConstraint extends Constraint
2525
/**
2626
* {@inheritdoc}
2727
*/
28-
public function check(&$element, $schema = null, JsonPointer $path = null, $i = null)
28+
public function check(&$element, $schema = null, ?JsonPointer $path = null, $i = null)
2929
{
3030
if (!isset($schema->format) || $this->factory->getConfig(self::CHECK_MODE_DISABLE_FORMAT)) {
3131
return;

src/JsonSchema/Constraints/NumberConstraint.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class NumberConstraint extends Constraint
2323
/**
2424
* {@inheritdoc}
2525
*/
26-
public function check(&$element, $schema = null, JsonPointer $path = null, $i = null)
26+
public function check(&$element, $schema = null, ?JsonPointer $path = null, $i = null)
2727
{
2828
// Verify minimum
2929
if (isset($schema->exclusiveMinimum)) {

src/JsonSchema/Constraints/ObjectConstraint.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class ObjectConstraint extends Constraint
2828
/**
2929
* {@inheritdoc}
3030
*/
31-
public function check(&$element, $schema = null, JsonPointer $path = null, $properties = null,
31+
public function check(&$element, $schema = null, ?JsonPointer $path = null, $properties = null,
3232
$additionalProp = null, $patternProperties = null, $appliedDefaults = array())
3333
{
3434
if ($element instanceof UndefinedConstraint) {
@@ -52,7 +52,7 @@ public function check(&$element, $schema = null, JsonPointer $path = null, $prop
5252
$this->validateElement($element, $matches, $schema, $path, $properties, $additionalProp);
5353
}
5454

55-
public function validatePatternProperties($element, JsonPointer $path = null, $patternProperties)
55+
public function validatePatternProperties($element, ?JsonPointer $path = null, $patternProperties)
5656
{
5757
$matches = array();
5858
foreach ($patternProperties as $pregex => $schema) {
@@ -84,7 +84,7 @@ public function validatePatternProperties($element, JsonPointer $path = null, $p
8484
* @param \StdClass $properties Properties
8585
* @param mixed $additionalProp Additional properties
8686
*/
87-
public function validateElement($element, $matches, $schema = null, JsonPointer $path = null,
87+
public function validateElement($element, $matches, $schema = null, ?JsonPointer $path = null,
8888
$properties = null, $additionalProp = null)
8989
{
9090
$this->validateMinMaxConstraint($element, $schema, $path);
@@ -129,7 +129,7 @@ public function validateElement($element, $matches, $schema = null, JsonPointer
129129
* @param \stdClass $properties Property definitions
130130
* @param JsonPointer|null $path Path?
131131
*/
132-
public function validateProperties(&$element, $properties = null, JsonPointer $path = null)
132+
public function validateProperties(&$element, $properties = null, ?JsonPointer $path = null)
133133
{
134134
$undefinedConstraint = $this->factory->createInstanceFor('undefined');
135135

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

src/JsonSchema/Constraints/SchemaConstraint.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class SchemaConstraint extends Constraint
2929
/**
3030
* {@inheritdoc}
3131
*/
32-
public function check(&$element, $schema = null, JsonPointer $path = null, $i = null)
32+
public function check(&$element, $schema = null, ?JsonPointer $path = null, $i = null)
3333
{
3434
if ($schema !== null) {
3535
// passed schema

src/JsonSchema/Constraints/StringConstraint.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class StringConstraint extends Constraint
2323
/**
2424
* {@inheritdoc}
2525
*/
26-
public function check(&$element, $schema = null, JsonPointer $path = null, $i = null)
26+
public function check(&$element, $schema = null, ?JsonPointer $path = null, $i = null)
2727
{
2828
// Verify maxLength
2929
if (isset($schema->maxLength) && $this->strlen($element) > $schema->maxLength) {

src/JsonSchema/Constraints/TypeConstraint.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class TypeConstraint extends Constraint
4040
/**
4141
* {@inheritdoc}
4242
*/
43-
public function check(&$value = null, $schema = null, JsonPointer $path = null, $i = null)
43+
public function check(&$value = null, $schema = null, ?JsonPointer $path = null, $i = null)
4444
{
4545
$type = isset($schema->type) ? $schema->type : null;
4646
$isValid = false;

src/JsonSchema/Constraints/UndefinedConstraint.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class UndefinedConstraint extends Constraint
3232
/**
3333
* {@inheritdoc}
3434
*/
35-
public function check(&$value, $schema = null, JsonPointer $path = null, $i = null, $fromDefault = false)
35+
public function check(&$value, $schema = null, ?JsonPointer $path = null, $i = null, $fromDefault = false)
3636
{
3737
if (is_null($schema) || !is_object($schema)) {
3838
return;

src/JsonSchema/Exception/JsonDecodingException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*/
1515
class JsonDecodingException extends RuntimeException
1616
{
17-
public function __construct($code = JSON_ERROR_NONE, \Exception $previous = null)
17+
public function __construct($code = JSON_ERROR_NONE, ?\Exception $previous = null)
1818
{
1919
switch ($code) {
2020
case JSON_ERROR_DEPTH:

src/JsonSchema/SchemaStorage.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ class SchemaStorage implements SchemaStorageInterface
1717
protected $schemas = array();
1818

1919
public function __construct(
20-
UriRetrieverInterface $uriRetriever = null,
21-
UriResolverInterface $uriResolver = null
20+
?UriRetrieverInterface $uriRetriever = null,
21+
?UriResolverInterface $uriResolver = null
2222
) {
2323
$this->uriRetriever = $uriRetriever ?: new UriRetriever();
2424
$this->uriResolver = $uriResolver ?: new UriResolver();

tests/Constraints/FactoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class MyBadConstraint
3030
*/
3131
class MyStringConstraint extends Constraint
3232
{
33-
public function check(&$value, $schema = null, JsonPointer $path = null, $i = null)
33+
public function check(&$value, $schema = null, ?JsonPointer $path = null, $i = null)
3434
{
3535
}
3636
}

0 commit comments

Comments
 (0)