Skip to content

Commit

Permalink
Merge pull request #731 from Seldaek/php84
Browse files Browse the repository at this point in the history
php 8.4 support for 5.x
  • Loading branch information
Seldaek committed Jul 6, 2024
2 parents fbbe7e5 + 2201471 commit 00fbffd
Show file tree
Hide file tree
Showing 17 changed files with 39 additions and 44 deletions.
17 changes: 6 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,13 @@
}
],
"require": {
"php": ">=5.3.3"
"php": ">=7.1"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "~2.2.20||~2.15.1",
"json-schema/json-schema-test-suite": "1.2.0",
"phpunit/phpunit": "^4.8.35"
},
"extra": {
"branch-alias": {
"dev-master": "5.0.x-dev"
}
},
"autoload": {
"psr-4": {
"JsonSchema\\": "src/JsonSchema/"
Expand Down Expand Up @@ -67,10 +62,10 @@
"bin/validate-json"
],
"scripts": {
"coverage": "phpunit --coverage-text",
"style-check": "php-cs-fixer fix --dry-run --verbose --diff",
"style-fix": "php-cs-fixer fix --verbose",
"test": "phpunit",
"testOnly": "phpunit --colors --filter"
"coverage": "@php phpunit --coverage-text",
"style-check": "@php php-cs-fixer fix --dry-run --verbose --diff",
"style-fix": "@php php-cs-fixer fix --verbose",
"test": "@php phpunit",
"testOnly": "@php phpunit --colors --filter"
}
}
4 changes: 2 additions & 2 deletions src/JsonSchema/Constraints/BaseConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ class BaseConstraint
/**
* @param Factory $factory
*/
public function __construct(Factory $factory = null)
public function __construct(?Factory $factory = null)
{
$this->factory = $factory ?: new Factory();
}

public function addError(JsonPointer $path = null, $message, $constraint = '', array $more = null)
public function addError(?JsonPointer $path = null, $message, $constraint = '', array $more = null)
{
$error = array(
'property' => $this->convertJsonPointerIntoPropertyPath($path ?: new JsonPointer('')),
Expand Down
4 changes: 2 additions & 2 deletions src/JsonSchema/Constraints/CollectionConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class CollectionConstraint extends Constraint
/**
* {@inheritdoc}
*/
public function check(&$value, $schema = null, JsonPointer $path = null, $i = null)
public function check(&$value, $schema = null, ?JsonPointer $path = null, $i = null)
{
// Verify minItems
if (isset($schema->minItems) && count($value) < $schema->minItems) {
Expand Down Expand Up @@ -61,7 +61,7 @@ public function check(&$value, $schema = null, JsonPointer $path = null, $i = nu
* @param JsonPointer|null $path
* @param string $i
*/
protected function validateItems(&$value, $schema = null, JsonPointer $path = null, $i = null)
protected function validateItems(&$value, $schema = null, ?JsonPointer $path = null, $i = null)
{
if (is_object($schema->items)) {
// just one type definition for the whole array
Expand Down
18 changes: 9 additions & 9 deletions src/JsonSchema/Constraints/Constraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ abstract class Constraint extends BaseConstraint implements ConstraintInterface
*
* @return JsonPointer;
*/
protected function incrementPath(JsonPointer $path = null, $i)
protected function incrementPath(?JsonPointer $path = null, $i)
{
$path = $path ?: new JsonPointer('');

Expand All @@ -65,7 +65,7 @@ protected function incrementPath(JsonPointer $path = null, $i)
* @param JsonPointer|null $path
* @param mixed $i
*/
protected function checkArray(&$value, $schema = null, JsonPointer $path = null, $i = null)
protected function checkArray(&$value, $schema = null, ?JsonPointer $path = null, $i = null)
{
$validator = $this->factory->createInstanceFor('collection');
$validator->check($value, $schema, $path, $i);
Expand All @@ -83,7 +83,7 @@ protected function checkArray(&$value, $schema = null, JsonPointer $path = null,
* @param mixed $additionalProperties
* @param mixed $patternProperties
*/
protected function checkObject(&$value, $schema = null, JsonPointer $path = null, $properties = null,
protected function checkObject(&$value, $schema = null, ?JsonPointer $path = null, $properties = null,
$additionalProperties = null, $patternProperties = null, $appliedDefaults = array())
{
$validator = $this->factory->createInstanceFor('object');
Expand All @@ -100,7 +100,7 @@ protected function checkObject(&$value, $schema = null, JsonPointer $path = null
* @param JsonPointer|null $path
* @param mixed $i
*/
protected function checkType(&$value, $schema = null, JsonPointer $path = null, $i = null)
protected function checkType(&$value, $schema = null, ?JsonPointer $path = null, $i = null)
{
$validator = $this->factory->createInstanceFor('type');
$validator->check($value, $schema, $path, $i);
Expand All @@ -116,7 +116,7 @@ protected function checkType(&$value, $schema = null, JsonPointer $path = null,
* @param JsonPointer|null $path
* @param mixed $i
*/
protected function checkUndefined(&$value, $schema = null, JsonPointer $path = null, $i = null, $fromDefault = false)
protected function checkUndefined(&$value, $schema = null, ?JsonPointer $path = null, $i = null, $fromDefault = false)
{
$validator = $this->factory->createInstanceFor('undefined');

Expand All @@ -133,7 +133,7 @@ protected function checkUndefined(&$value, $schema = null, JsonPointer $path = n
* @param JsonPointer|null $path
* @param mixed $i
*/
protected function checkString($value, $schema = null, JsonPointer $path = null, $i = null)
protected function checkString($value, $schema = null, ?JsonPointer $path = null, $i = null)
{
$validator = $this->factory->createInstanceFor('string');
$validator->check($value, $schema, $path, $i);
Expand All @@ -149,7 +149,7 @@ protected function checkString($value, $schema = null, JsonPointer $path = null,
* @param JsonPointer $path
* @param mixed $i
*/
protected function checkNumber($value, $schema = null, JsonPointer $path = null, $i = null)
protected function checkNumber($value, $schema = null, ?JsonPointer $path = null, $i = null)
{
$validator = $this->factory->createInstanceFor('number');
$validator->check($value, $schema, $path, $i);
Expand All @@ -165,7 +165,7 @@ protected function checkNumber($value, $schema = null, JsonPointer $path = null,
* @param JsonPointer|null $path
* @param mixed $i
*/
protected function checkEnum($value, $schema = null, JsonPointer $path = null, $i = null)
protected function checkEnum($value, $schema = null, ?JsonPointer $path = null, $i = null)
{
$validator = $this->factory->createInstanceFor('enum');
$validator->check($value, $schema, $path, $i);
Expand All @@ -181,7 +181,7 @@ protected function checkEnum($value, $schema = null, JsonPointer $path = null, $
* @param JsonPointer|null $path
* @param mixed $i
*/
protected function checkFormat($value, $schema = null, JsonPointer $path = null, $i = null)
protected function checkFormat($value, $schema = null, ?JsonPointer $path = null, $i = null)
{
$validator = $this->factory->createInstanceFor('format');
$validator->check($value, $schema, $path, $i);
Expand Down
4 changes: 2 additions & 2 deletions src/JsonSchema/Constraints/ConstraintInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function addErrors(array $errors);
* @param string $constraint the constraint/rule that is broken, e.g.: 'minLength'
* @param array $more more array elements to add to the error
*/
public function addError(JsonPointer $path = null, $message, $constraint='', array $more = null);
public function addError(?JsonPointer $path = null, $message, $constraint='', array $more = null);

/**
* checks if the validator has not raised errors
Expand All @@ -61,5 +61,5 @@ public function isValid();
*
* @throws \JsonSchema\Exception\ExceptionInterface
*/
public function check(&$value, $schema = null, JsonPointer $path = null, $i = null);
public function check(&$value, $schema = null, ?JsonPointer $path = null, $i = null);
}
2 changes: 1 addition & 1 deletion src/JsonSchema/Constraints/EnumConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class EnumConstraint extends Constraint
/**
* {@inheritdoc}
*/
public function check(&$element, $schema = null, JsonPointer $path = null, $i = null)
public function check(&$element, $schema = null, ?JsonPointer $path = null, $i = null)
{
// Only validate enum if the attribute exists
if ($element instanceof UndefinedConstraint && (!isset($schema->required) || !$schema->required)) {
Expand Down
4 changes: 2 additions & 2 deletions src/JsonSchema/Constraints/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ class Factory
* @param int $checkMode
*/
public function __construct(
SchemaStorageInterface $schemaStorage = null,
UriRetrieverInterface $uriRetriever = null,
?SchemaStorageInterface $schemaStorage = null,
?UriRetrieverInterface $uriRetriever = null,
$checkMode = Constraint::CHECK_MODE_NORMAL
) {
// set provided config options
Expand Down
2 changes: 1 addition & 1 deletion src/JsonSchema/Constraints/FormatConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class FormatConstraint extends Constraint
/**
* {@inheritdoc}
*/
public function check(&$element, $schema = null, JsonPointer $path = null, $i = null)
public function check(&$element, $schema = null, ?JsonPointer $path = null, $i = null)
{
if (!isset($schema->format) || $this->factory->getConfig(self::CHECK_MODE_DISABLE_FORMAT)) {
return;
Expand Down
2 changes: 1 addition & 1 deletion src/JsonSchema/Constraints/NumberConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class NumberConstraint extends Constraint
/**
* {@inheritdoc}
*/
public function check(&$element, $schema = null, JsonPointer $path = null, $i = null)
public function check(&$element, $schema = null, ?JsonPointer $path = null, $i = null)
{
// Verify minimum
if (isset($schema->exclusiveMinimum)) {
Expand Down
10 changes: 5 additions & 5 deletions src/JsonSchema/Constraints/ObjectConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ObjectConstraint extends Constraint
/**
* {@inheritdoc}
*/
public function check(&$element, $schema = null, JsonPointer $path = null, $properties = null,
public function check(&$element, $schema = null, ?JsonPointer $path = null, $properties = null,
$additionalProp = null, $patternProperties = null, $appliedDefaults = array())
{
if ($element instanceof UndefinedConstraint) {
Expand All @@ -51,7 +51,7 @@ public function check(&$element, $schema = null, JsonPointer $path = null, $prop
$this->validateElement($element, $matches, $schema, $path, $properties, $additionalProp);
}

public function validatePatternProperties($element, JsonPointer $path = null, $patternProperties)
public function validatePatternProperties($element, ?JsonPointer $path = null, $patternProperties)
{
$try = array('/', '#', '+', '~', '%');
$matches = array();
Expand Down Expand Up @@ -90,7 +90,7 @@ public function validatePatternProperties($element, JsonPointer $path = null, $p
* @param \StdClass $properties Properties
* @param mixed $additionalProp Additional properties
*/
public function validateElement($element, $matches, $schema = null, JsonPointer $path = null,
public function validateElement($element, $matches, $schema = null, ?JsonPointer $path = null,
$properties = null, $additionalProp = null)
{
$this->validateMinMaxConstraint($element, $schema, $path);
Expand Down Expand Up @@ -132,7 +132,7 @@ public function validateElement($element, $matches, $schema = null, JsonPointer
* @param \stdClass $properties Property definitions
* @param JsonPointer|null $path Path?
*/
public function validateProperties(&$element, $properties = null, JsonPointer $path = null)
public function validateProperties(&$element, $properties = null, ?JsonPointer $path = null)
{
$undefinedConstraint = $this->factory->createInstanceFor('undefined');

Expand Down Expand Up @@ -174,7 +174,7 @@ protected function &getProperty(&$element, $property, $fallback = null)
* @param \stdClass $objectDefinition ObjectConstraint definition
* @param JsonPointer|null $path Path to test?
*/
protected function validateMinMaxConstraint($element, $objectDefinition, JsonPointer $path = null)
protected function validateMinMaxConstraint($element, $objectDefinition, ?JsonPointer $path = null)
{
// Verify minimum number of properties
if (isset($objectDefinition->minProperties) && !is_object($objectDefinition->minProperties)) {
Expand Down
2 changes: 1 addition & 1 deletion src/JsonSchema/Constraints/SchemaConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class SchemaConstraint extends Constraint
/**
* {@inheritdoc}
*/
public function check(&$element, $schema = null, JsonPointer $path = null, $i = null)
public function check(&$element, $schema = null, ?JsonPointer $path = null, $i = null)
{
if ($schema !== null) {
// passed schema
Expand Down
2 changes: 1 addition & 1 deletion src/JsonSchema/Constraints/StringConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class StringConstraint extends Constraint
/**
* {@inheritdoc}
*/
public function check(&$element, $schema = null, JsonPointer $path = null, $i = null)
public function check(&$element, $schema = null, ?JsonPointer $path = null, $i = null)
{
// Verify maxLength
if (isset($schema->maxLength) && $this->strlen($element) > $schema->maxLength) {
Expand Down
2 changes: 1 addition & 1 deletion src/JsonSchema/Constraints/TypeConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class TypeConstraint extends Constraint
/**
* {@inheritdoc}
*/
public function check(&$value = null, $schema = null, JsonPointer $path = null, $i = null)
public function check(&$value = null, $schema = null, ?JsonPointer $path = null, $i = null)
{
$type = isset($schema->type) ? $schema->type : null;
$isValid = false;
Expand Down
2 changes: 1 addition & 1 deletion src/JsonSchema/Constraints/UndefinedConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class UndefinedConstraint extends Constraint
/**
* {@inheritdoc}
*/
public function check(&$value, $schema = null, JsonPointer $path = null, $i = null, $fromDefault = false)
public function check(&$value, $schema = null, ?JsonPointer $path = null, $i = null, $fromDefault = false)
{
if (is_null($schema) || !is_object($schema)) {
return;
Expand Down
2 changes: 1 addition & 1 deletion src/JsonSchema/Exception/JsonDecodingException.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
class JsonDecodingException extends RuntimeException
{
public function __construct($code = JSON_ERROR_NONE, \Exception $previous = null)
public function __construct($code = JSON_ERROR_NONE, ?\Exception $previous = null)
{
switch ($code) {
case JSON_ERROR_DEPTH:
Expand Down
4 changes: 2 additions & 2 deletions src/JsonSchema/SchemaStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class SchemaStorage implements SchemaStorageInterface
protected $schemas = array();

public function __construct(
UriRetrieverInterface $uriRetriever = null,
UriResolverInterface $uriResolver = null
?UriRetrieverInterface $uriRetriever = null,
?UriResolverInterface $uriResolver = null
) {
$this->uriRetriever = $uriRetriever ?: new UriRetriever();
$this->uriResolver = $uriResolver ?: new UriResolver();
Expand Down
2 changes: 1 addition & 1 deletion tests/Constraints/FactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class MyBadConstraint
*/
class MyStringConstraint extends Constraint
{
public function check(&$value, $schema = null, JsonPointer $path = null, $i = null)
public function check(&$value, $schema = null, ?JsonPointer $path = null, $i = null)
{
}
}
Expand Down

0 comments on commit 00fbffd

Please sign in to comment.