Skip to content

Commit 2eb0def

Browse files
Extend pipeline for newer versions php (#746)
* ci: Add PHP 8.0 and greater to build matrix * ci: Remove PHP 5.3 - 7.1 from workflows * build: Require minimum PHP 7.2 * build: Upgrade to PHPUnit 8.5 * refactor: Add now required void return types for setup() methods * build: Include phpspec/prophecy dependency * refactor: Replace setExpectedException with expectException/expectExceptionMessage * refactor: Replace @ExpectedException annotation for expectException method * refactor: Replace assertInternalType for assertIsArray * refactor: Replace getMock for createMock * test: Improve test assertions * fix: Solve return type issues with Objectiterator (port of #682) See #682 * build: Update icecave/parity to ^3.0 as 1.0 uses deprecated each() method * style: Correct code style issues * fix: Fix deprecation notices found from GHA workflow run See https://github.com/jsonrainbow/json-schema/actions/runs/10216569969/job/28268331091 * fix: Add fallback to empty string when null value is passed in UriResolver::parse * fix: Port #717: Fixes for implicit nullability deprecation See #717 * ci: Avoid GHA run on each push and pull request; Include PHP 8.4 in matrix * ci(Drop-PHP-8.4-from-matrix): This PR adds phpspec/prophecy as an explicit dependency which is restrictive and doesnt support upcoming PHP versions * refactor: Replace ternary variable with explicit cast to string
1 parent 985840f commit 2eb0def

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+152
-170
lines changed

.github/workflows/continuous-integration.yml

+12-11
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
name: "Continuous Integration"
22

33
on:
4-
- push
5-
- pull_request
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
610

711
env:
812
COMPOSER_FLAGS: "--ansi --no-interaction --no-progress --prefer-dist"
@@ -17,23 +21,20 @@ jobs:
1721
strategy:
1822
matrix:
1923
php-version:
20-
- "5.3"
21-
- "5.4"
22-
- "5.5"
23-
- "5.6"
24-
- "7.0"
25-
- "7.1"
2624
- "7.2"
2725
- "7.3"
2826
- "7.4"
29-
# - "8.0"
27+
- "8.0"
28+
- "8.1"
29+
- "8.2"
30+
- "8.3"
3031
dependencies: [highest]
3132
experimental: [false]
3233
include:
33-
- php-version: "5.3"
34+
- php-version: "7.2"
3435
dependencies: highest
3536
experimental: false
36-
- php-version: "5.3"
37+
- php-version: "7.2"
3738
dependencies: lowest
3839
experimental: false
3940
# - php-version: "8.0"

.github/workflows/lint.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
strategy:
1414
matrix:
1515
php-version:
16-
- "5.3"
16+
- "7.2"
1717
- "latest"
1818

1919
steps:

composer.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,15 @@
2727
}
2828
],
2929
"require": {
30-
"php": ">=5.3.3",
30+
"php": "^7.2 || ^8.0",
3131
"marc-mabe/php-enum":"^2.0 || ^3.0 || ^4.0",
32-
"icecave/parity": "1.0.0"
32+
"icecave/parity": "^3.0"
3333
},
3434
"require-dev": {
3535
"friendsofphp/php-cs-fixer": "~2.2.20 || ~2.19.0",
3636
"json-schema/json-schema-test-suite": "1.2.0",
37-
"phpunit/phpunit": "^4.8.35"
37+
"phpunit/phpunit": "^8.5",
38+
"phpspec/prophecy": "^1.19"
3839
},
3940
"extra": {
4041
"branch-alias": {

phpunit.xml.dist

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22

3-
<phpunit backupGlobals="false"
3+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
5+
backupGlobals="false"
46
backupStaticAttributes="false"
57
colors="true"
68
convertErrorsToExceptions="true"
79
convertNoticesToExceptions="true"
810
convertWarningsToExceptions="true"
911
processIsolation="false"
1012
stopOnFailure="false"
11-
syntaxCheck="false"
1213
bootstrap="vendor/autoload.php"
1314
verbose="true"
1415
>

src/JsonSchema/Constraints/BaseConstraint.php

+2-2
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

+2-2
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

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

+14-14
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

+2-2
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

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

+5-5
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

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

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

+5-5
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

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

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

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

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

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

0 commit comments

Comments
 (0)