Skip to content

Commit 00fbffd

Browse files
authored
Merge pull request #731 from Seldaek/php84
php 8.4 support for 5.x
2 parents fbbe7e5 + 2201471 commit 00fbffd

17 files changed

+39
-44
lines changed

Diff for: composer.json

+6-11
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,13 @@
2727
}
2828
],
2929
"require": {
30-
"php": ">=5.3.3"
30+
"php": ">=7.1"
3131
},
3232
"require-dev": {
3333
"friendsofphp/php-cs-fixer": "~2.2.20||~2.15.1",
3434
"json-schema/json-schema-test-suite": "1.2.0",
3535
"phpunit/phpunit": "^4.8.35"
3636
},
37-
"extra": {
38-
"branch-alias": {
39-
"dev-master": "5.0.x-dev"
40-
}
41-
},
4237
"autoload": {
4338
"psr-4": {
4439
"JsonSchema\\": "src/JsonSchema/"
@@ -67,10 +62,10 @@
6762
"bin/validate-json"
6863
],
6964
"scripts": {
70-
"coverage": "phpunit --coverage-text",
71-
"style-check": "php-cs-fixer fix --dry-run --verbose --diff",
72-
"style-fix": "php-cs-fixer fix --verbose",
73-
"test": "phpunit",
74-
"testOnly": "phpunit --colors --filter"
65+
"coverage": "@php phpunit --coverage-text",
66+
"style-check": "@php php-cs-fixer fix --dry-run --verbose --diff",
67+
"style-fix": "@php php-cs-fixer fix --verbose",
68+
"test": "@php phpunit",
69+
"testOnly": "@php phpunit --colors --filter"
7570
}
7671
}

Diff for: src/JsonSchema/Constraints/BaseConstraint.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ class BaseConstraint
3838
/**
3939
* @param Factory $factory
4040
*/
41-
public function __construct(Factory $factory = null)
41+
public function __construct(?Factory $factory = null)
4242
{
4343
$this->factory = $factory ?: new Factory();
4444
}
4545

46-
public function addError(JsonPointer $path = null, $message, $constraint = '', array $more = null)
46+
public function addError(?JsonPointer $path = null, $message, $constraint = '', array $more = null)
4747
{
4848
$error = array(
4949
'property' => $this->convertJsonPointerIntoPropertyPath($path ?: new JsonPointer('')),

Diff for: src/JsonSchema/Constraints/CollectionConstraint.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class CollectionConstraint extends Constraint
2222
/**
2323
* {@inheritdoc}
2424
*/
25-
public function check(&$value, $schema = null, JsonPointer $path = null, $i = null)
25+
public function check(&$value, $schema = null, ?JsonPointer $path = null, $i = null)
2626
{
2727
// Verify minItems
2828
if (isset($schema->minItems) && count($value) < $schema->minItems) {
@@ -61,7 +61,7 @@ public function check(&$value, $schema = null, JsonPointer $path = null, $i = nu
6161
* @param JsonPointer|null $path
6262
* @param string $i
6363
*/
64-
protected function validateItems(&$value, $schema = null, JsonPointer $path = null, $i = null)
64+
protected function validateItems(&$value, $schema = null, ?JsonPointer $path = null, $i = null)
6565
{
6666
if (is_object($schema->items)) {
6767
// just one type definition for the whole array

Diff for: src/JsonSchema/Constraints/Constraint.php

+9-9
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ abstract class Constraint extends BaseConstraint implements ConstraintInterface
3939
*
4040
* @return JsonPointer;
4141
*/
42-
protected function incrementPath(JsonPointer $path = null, $i)
42+
protected function incrementPath(?JsonPointer $path = null, $i)
4343
{
4444
$path = $path ?: new JsonPointer('');
4545

@@ -65,7 +65,7 @@ protected function incrementPath(JsonPointer $path = null, $i)
6565
* @param JsonPointer|null $path
6666
* @param mixed $i
6767
*/
68-
protected function checkArray(&$value, $schema = null, JsonPointer $path = null, $i = null)
68+
protected function checkArray(&$value, $schema = null, ?JsonPointer $path = null, $i = null)
6969
{
7070
$validator = $this->factory->createInstanceFor('collection');
7171
$validator->check($value, $schema, $path, $i);
@@ -83,7 +83,7 @@ protected function checkArray(&$value, $schema = null, JsonPointer $path = null,
8383
* @param mixed $additionalProperties
8484
* @param mixed $patternProperties
8585
*/
86-
protected function checkObject(&$value, $schema = null, JsonPointer $path = null, $properties = null,
86+
protected function checkObject(&$value, $schema = null, ?JsonPointer $path = null, $properties = null,
8787
$additionalProperties = null, $patternProperties = null, $appliedDefaults = array())
8888
{
8989
$validator = $this->factory->createInstanceFor('object');
@@ -100,7 +100,7 @@ protected function checkObject(&$value, $schema = null, JsonPointer $path = null
100100
* @param JsonPointer|null $path
101101
* @param mixed $i
102102
*/
103-
protected function checkType(&$value, $schema = null, JsonPointer $path = null, $i = null)
103+
protected function checkType(&$value, $schema = null, ?JsonPointer $path = null, $i = null)
104104
{
105105
$validator = $this->factory->createInstanceFor('type');
106106
$validator->check($value, $schema, $path, $i);
@@ -116,7 +116,7 @@ protected function checkType(&$value, $schema = null, JsonPointer $path = null,
116116
* @param JsonPointer|null $path
117117
* @param mixed $i
118118
*/
119-
protected function checkUndefined(&$value, $schema = null, JsonPointer $path = null, $i = null, $fromDefault = false)
119+
protected function checkUndefined(&$value, $schema = null, ?JsonPointer $path = null, $i = null, $fromDefault = false)
120120
{
121121
$validator = $this->factory->createInstanceFor('undefined');
122122

@@ -133,7 +133,7 @@ protected function checkUndefined(&$value, $schema = null, JsonPointer $path = n
133133
* @param JsonPointer|null $path
134134
* @param mixed $i
135135
*/
136-
protected function checkString($value, $schema = null, JsonPointer $path = null, $i = null)
136+
protected function checkString($value, $schema = null, ?JsonPointer $path = null, $i = null)
137137
{
138138
$validator = $this->factory->createInstanceFor('string');
139139
$validator->check($value, $schema, $path, $i);
@@ -149,7 +149,7 @@ protected function checkString($value, $schema = null, JsonPointer $path = null,
149149
* @param JsonPointer $path
150150
* @param mixed $i
151151
*/
152-
protected function checkNumber($value, $schema = null, JsonPointer $path = null, $i = null)
152+
protected function checkNumber($value, $schema = null, ?JsonPointer $path = null, $i = null)
153153
{
154154
$validator = $this->factory->createInstanceFor('number');
155155
$validator->check($value, $schema, $path, $i);
@@ -165,7 +165,7 @@ protected function checkNumber($value, $schema = null, JsonPointer $path = null,
165165
* @param JsonPointer|null $path
166166
* @param mixed $i
167167
*/
168-
protected function checkEnum($value, $schema = null, JsonPointer $path = null, $i = null)
168+
protected function checkEnum($value, $schema = null, ?JsonPointer $path = null, $i = null)
169169
{
170170
$validator = $this->factory->createInstanceFor('enum');
171171
$validator->check($value, $schema, $path, $i);
@@ -181,7 +181,7 @@ protected function checkEnum($value, $schema = null, JsonPointer $path = null, $
181181
* @param JsonPointer|null $path
182182
* @param mixed $i
183183
*/
184-
protected function checkFormat($value, $schema = null, JsonPointer $path = null, $i = null)
184+
protected function checkFormat($value, $schema = null, ?JsonPointer $path = null, $i = null)
185185
{
186186
$validator = $this->factory->createInstanceFor('format');
187187
$validator->check($value, $schema, $path, $i);

Diff for: src/JsonSchema/Constraints/ConstraintInterface.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function addErrors(array $errors);
4040
* @param string $constraint the constraint/rule that is broken, e.g.: 'minLength'
4141
* @param array $more more array elements to add to the error
4242
*/
43-
public function addError(JsonPointer $path = null, $message, $constraint='', array $more = null);
43+
public function addError(?JsonPointer $path = null, $message, $constraint='', array $more = null);
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
}

Diff for: src/JsonSchema/Constraints/EnumConstraint.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class EnumConstraint extends Constraint
2222
/**
2323
* {@inheritdoc}
2424
*/
25-
public function check(&$element, $schema = null, JsonPointer $path = null, $i = null)
25+
public function check(&$element, $schema = null, ?JsonPointer $path = null, $i = null)
2626
{
2727
// Only validate enum if the attribute exists
2828
if ($element instanceof UndefinedConstraint && (!isset($schema->required) || !$schema->required)) {

Diff for: src/JsonSchema/Constraints/Factory.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ class Factory
7474
* @param int $checkMode
7575
*/
7676
public function __construct(
77-
SchemaStorageInterface $schemaStorage = null,
78-
UriRetrieverInterface $uriRetriever = null,
77+
?SchemaStorageInterface $schemaStorage = null,
78+
?UriRetrieverInterface $uriRetriever = null,
7979
$checkMode = Constraint::CHECK_MODE_NORMAL
8080
) {
8181
// set provided config options

Diff for: src/JsonSchema/Constraints/FormatConstraint.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class FormatConstraint 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
if (!isset($schema->format) || $this->factory->getConfig(self::CHECK_MODE_DISABLE_FORMAT)) {
3030
return;

Diff for: src/JsonSchema/Constraints/NumberConstraint.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class NumberConstraint extends Constraint
2222
/**
2323
* {@inheritdoc}
2424
*/
25-
public function check(&$element, $schema = null, JsonPointer $path = null, $i = null)
25+
public function check(&$element, $schema = null, ?JsonPointer $path = null, $i = null)
2626
{
2727
// Verify minimum
2828
if (isset($schema->exclusiveMinimum)) {

Diff for: src/JsonSchema/Constraints/ObjectConstraint.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class ObjectConstraint extends Constraint
2727
/**
2828
* {@inheritdoc}
2929
*/
30-
public function check(&$element, $schema = null, JsonPointer $path = null, $properties = null,
30+
public function check(&$element, $schema = null, ?JsonPointer $path = null, $properties = null,
3131
$additionalProp = null, $patternProperties = null, $appliedDefaults = array())
3232
{
3333
if ($element instanceof UndefinedConstraint) {
@@ -51,7 +51,7 @@ public function check(&$element, $schema = null, JsonPointer $path = null, $prop
5151
$this->validateElement($element, $matches, $schema, $path, $properties, $additionalProp);
5252
}
5353

54-
public function validatePatternProperties($element, JsonPointer $path = null, $patternProperties)
54+
public function validatePatternProperties($element, ?JsonPointer $path = null, $patternProperties)
5555
{
5656
$try = array('/', '#', '+', '~', '%');
5757
$matches = array();
@@ -90,7 +90,7 @@ public function validatePatternProperties($element, JsonPointer $path = null, $p
9090
* @param \StdClass $properties Properties
9191
* @param mixed $additionalProp Additional properties
9292
*/
93-
public function validateElement($element, $matches, $schema = null, JsonPointer $path = null,
93+
public function validateElement($element, $matches, $schema = null, ?JsonPointer $path = null,
9494
$properties = null, $additionalProp = null)
9595
{
9696
$this->validateMinMaxConstraint($element, $schema, $path);
@@ -132,7 +132,7 @@ public function validateElement($element, $matches, $schema = null, JsonPointer
132132
* @param \stdClass $properties Property definitions
133133
* @param JsonPointer|null $path Path?
134134
*/
135-
public function validateProperties(&$element, $properties = null, JsonPointer $path = null)
135+
public function validateProperties(&$element, $properties = null, ?JsonPointer $path = null)
136136
{
137137
$undefinedConstraint = $this->factory->createInstanceFor('undefined');
138138

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

Diff for: src/JsonSchema/Constraints/SchemaConstraint.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class SchemaConstraint extends Constraint
2828
/**
2929
* {@inheritdoc}
3030
*/
31-
public function check(&$element, $schema = null, JsonPointer $path = null, $i = null)
31+
public function check(&$element, $schema = null, ?JsonPointer $path = null, $i = null)
3232
{
3333
if ($schema !== null) {
3434
// passed schema

Diff for: src/JsonSchema/Constraints/StringConstraint.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class StringConstraint extends Constraint
2222
/**
2323
* {@inheritdoc}
2424
*/
25-
public function check(&$element, $schema = null, JsonPointer $path = null, $i = null)
25+
public function check(&$element, $schema = null, ?JsonPointer $path = null, $i = null)
2626
{
2727
// Verify maxLength
2828
if (isset($schema->maxLength) && $this->strlen($element) > $schema->maxLength) {

Diff for: src/JsonSchema/Constraints/TypeConstraint.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class TypeConstraint extends Constraint
3939
/**
4040
* {@inheritdoc}
4141
*/
42-
public function check(&$value = null, $schema = null, JsonPointer $path = null, $i = null)
42+
public function check(&$value = null, $schema = null, ?JsonPointer $path = null, $i = null)
4343
{
4444
$type = isset($schema->type) ? $schema->type : null;
4545
$isValid = false;

Diff for: src/JsonSchema/Constraints/UndefinedConstraint.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class UndefinedConstraint extends Constraint
3131
/**
3232
* {@inheritdoc}
3333
*/
34-
public function check(&$value, $schema = null, JsonPointer $path = null, $i = null, $fromDefault = false)
34+
public function check(&$value, $schema = null, ?JsonPointer $path = null, $i = null, $fromDefault = false)
3535
{
3636
if (is_null($schema) || !is_object($schema)) {
3737
return;

Diff for: src/JsonSchema/Exception/JsonDecodingException.php

+1-1
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:

Diff for: src/JsonSchema/SchemaStorage.php

+2-2
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();

Diff for: tests/Constraints/FactoryTest.php

+1-1
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)