Skip to content

Fixed deprecations #152

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 3 additions & 12 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,24 @@ jobs:
strategy:
fail-fast: true
matrix:
php: [7.0, 7.1, 7.2, 7.3, 7.4, 8.0]
stability: [prefer-stable]
php: [7.4, 8.0, 8.1, 8.2, 8.3, 8.4]

name: PHP ${{ matrix.php }}

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Cache dependencies
uses: actions/cache@v1
with:
path: ~/.composer/cache/files
key: dependencies-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: bcmath, json, mbstring, intl
tools: composer:v2
coverage: none

- name: Update composer
run: composer self-update

- name: Install dependencies
run: composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-progress
run: composer update --no-interaction --no-progress

- name: Execute tests
run: vendor/bin/phpunit --verbose
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
}
],
"require": {
"php": ">=7.0"
"php": ">=7.4"
},
"require-dev": {
"opis/string": "^1.4",
"opis/string": "^2.0",
"ext-bcmath": "*",
"ext-json": "*",
"ext-mbstring": "*",
Expand Down
2 changes: 1 addition & 1 deletion src/Formats/AbstractFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected function validateRegex($data, string $regex): bool
* @param null $options
* @return bool
*/
protected function validateFilter($data, int $filter, $options = null): bool
protected function validateFilter($data, int $filter, $options = 0): bool
{
return filter_var($data, $filter, $options) !== false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/ISchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ public function draft(): string;
* @param string|null $id
* @return mixed
*/
public function resolve(string $id = null);
public function resolve(?string $id = null);

}
14 changes: 7 additions & 7 deletions src/IValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ interface IValidator
* @param ISchemaLoader|null $loader
* @return ValidationResult
*/
public function schemaValidation($data, ISchema $schema, int $max_errors = 1, ISchemaLoader $loader = null): ValidationResult;
public function schemaValidation($data, ISchema $schema, int $max_errors = 1, ?ISchemaLoader $loader = null): ValidationResult;

/**
* @param $data
Expand All @@ -37,7 +37,7 @@ public function schemaValidation($data, ISchema $schema, int $max_errors = 1, IS
* @param ISchemaLoader|null $loader
* @return ValidationResult
*/
public function uriValidation($data, string $schema_uri, int $max_errors = 1, ISchemaLoader $loader = null): ValidationResult;
public function uriValidation($data, string $schema_uri, int $max_errors = 1, ?ISchemaLoader $loader = null): ValidationResult;

/**
* @param $data
Expand All @@ -46,13 +46,13 @@ public function uriValidation($data, string $schema_uri, int $max_errors = 1, IS
* @param ISchemaLoader|null $loader
* @return ValidationResult
*/
public function dataValidation($data, $schema, int $max_errors = 1, ISchemaLoader $loader = null): ValidationResult;
public function dataValidation($data, $schema, int $max_errors = 1, ?ISchemaLoader $loader = null): ValidationResult;

/**
* @param IFilterContainer|null $filters
* @return IValidator
*/
public function setFilters(IFilterContainer $filters = null): self;
public function setFilters(?IFilterContainer $filters = null): self;

/**
* @return IFilterContainer|null
Expand All @@ -63,7 +63,7 @@ public function getFilters();
* @param IFormatContainer|null $formats
* @return IValidator
*/
public function setFormats(IFormatContainer $formats = null): self;
public function setFormats(?IFormatContainer $formats = null): self;

/**
* @return IFilterContainer|null
Expand All @@ -85,7 +85,7 @@ public function getHelper(): IValidatorHelper;
* @param ISchemaLoader|null $loader
* @return IValidator
*/
public function setLoader(ISchemaLoader $loader = null): self;
public function setLoader(?ISchemaLoader $loader = null): self;

/**
* @return ISchemaLoader|null
Expand All @@ -96,7 +96,7 @@ public function getLoader();
* @param IMediaTypeContainer|null $media
* @return IValidator
*/
public function setMediaType(IMediaTypeContainer $media = null): self;
public function setMediaType(?IMediaTypeContainer $media = null): self;

/**
* @return IMediaTypeContainer|null
Expand Down
2 changes: 1 addition & 1 deletion src/IValidatorHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ public function isMultipleOf($number, $divisor): bool;
* @param array $defaults
* @return bool
*/
public function equals($a, $b, array $defaults = null): bool;
public function equals($a, $b, ?array $defaults = null): bool;

}
2 changes: 1 addition & 1 deletion src/Loaders/Memory.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function unregister(ISchema $schema): self
* @param string|null $id
* @return Memory
*/
public function add($data, string $id = null): self
public function add($data, ?string $id = null): self
{
if (is_string($data)) {
$data = json_decode($data, false);
Expand Down
6 changes: 3 additions & 3 deletions src/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Schema implements ISchema
* @param \stdClass|boolean $data
* @param string|null $id
*/
public function __construct($data, string $id = null)
public function __construct($data, ?string $id = null)
{
if (is_object($data)) {
if (property_exists($data, static::ID_PROP)) {
Expand Down Expand Up @@ -117,7 +117,7 @@ public function draft(): string
/**
* @inheritDoc
*/
public function resolve(string $id = null)
public function resolve(?string $id = null)
{
if ($id === null) {
$id = $this->id;
Expand Down Expand Up @@ -196,7 +196,7 @@ public static function walk(array &$container, &$schema, string $id, array $path
* @param string|null $id
* @return Schema
*/
public static function fromJsonString(string $json, string $id = null): self
public static function fromJsonString(string $json, ?string $id = null): self
{
return new self(json_decode($json, false), $id);
}
Expand Down
32 changes: 16 additions & 16 deletions src/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ class Validator implements IValidator
* @param IFilterContainer|null $filters
* @param IMediaTypeContainer|null $media
*/
public function __construct(IValidatorHelper $helper = null,
ISchemaLoader $loader = null,
IFormatContainer $formats = null,
IFilterContainer $filters = null,
IMediaTypeContainer $media = null)
public function __construct(?IValidatorHelper $helper = null,
?ISchemaLoader $loader = null,
?IFormatContainer $formats = null,
?IFilterContainer $filters = null,
?IMediaTypeContainer $media = null)
{
$this->helper = $helper ?? new ValidatorHelper();
$this->formats = $formats ?? new FormatContainer();
Expand All @@ -81,7 +81,7 @@ public function __construct(IValidatorHelper $helper = null,
/**
* @inheritDoc
*/
public function schemaValidation($data, ISchema $schema, int $max_errors = 1, ISchemaLoader $loader = null): ValidationResult
public function schemaValidation($data, ISchema $schema, int $max_errors = 1, ?ISchemaLoader $loader = null): ValidationResult
{
$bag = new ValidationResult($max_errors);

Expand All @@ -103,7 +103,7 @@ public function schemaValidation($data, ISchema $schema, int $max_errors = 1, IS
/**
* @inheritDoc
*/
public function uriValidation($data, string $schema_uri, int $max_errors = 1, ISchemaLoader $loader = null): ValidationResult
public function uriValidation($data, string $schema_uri, int $max_errors = 1, ?ISchemaLoader $loader = null): ValidationResult
{
$schema = new stdClass();
$schema->{'$ref'} = URI::normalize($schema_uri);
Expand All @@ -113,7 +113,7 @@ public function uriValidation($data, string $schema_uri, int $max_errors = 1, IS
/**
* @inheritDoc
*/
public function dataValidation($data, $schema, int $max_errors = 1, ISchemaLoader $loader = null): ValidationResult
public function dataValidation($data, $schema, int $max_errors = 1, ?ISchemaLoader $loader = null): ValidationResult
{
$schema = is_string($schema) ? Schema::fromJsonString($schema) : new Schema($schema);
return $this->schemaValidation($data, $schema, $max_errors, $loader);
Expand All @@ -122,7 +122,7 @@ public function dataValidation($data, $schema, int $max_errors = 1, ISchemaLoade
/**
* @inheritDoc
*/
public function setFilters(IFilterContainer $filters = null): IValidator
public function setFilters(?IFilterContainer $filters = null): IValidator
{
$this->filters = $filters;
return $this;
Expand All @@ -139,7 +139,7 @@ public function getFilters()
/**
* @inheritDoc
*/
public function setFormats(IFormatContainer $formats = null): IValidator
public function setFormats(?IFormatContainer $formats = null): IValidator
{
$this->formats = $formats;
return $this;
Expand Down Expand Up @@ -173,7 +173,7 @@ public function getHelper(): IValidatorHelper
/**
* @inheritDoc
*/
public function setLoader(ISchemaLoader $loader = null): IValidator
public function setLoader(?ISchemaLoader $loader = null): IValidator
{
$this->loader = $loader;
return $this;
Expand All @@ -190,7 +190,7 @@ public function getLoader()
/**
* @inheritDoc
*/
public function setMediaType(IMediaTypeContainer $media = null): IValidator
public function setMediaType(?IMediaTypeContainer $media = null): IValidator
{
$this->mediaTypes = $media;
return $this;
Expand Down Expand Up @@ -544,7 +544,7 @@ protected function validateKeywords(&$document_data, &$data, array $data_pointer
* @return bool
*/
protected function validateCommons(/** @noinspection PhpUnusedParameterInspection */
&$document_data, &$data, array $data_pointer, array $parent_data_pointer, ISchema $document, $schema, ValidationResult $bag, array &$defaults = null): bool
&$document_data, &$data, array $data_pointer, array $parent_data_pointer, ISchema $document, $schema, ValidationResult $bag, ?array &$defaults = null): bool
{
$ok = true;

Expand Down Expand Up @@ -929,7 +929,7 @@ protected function validateConditionals(&$document_data, &$data, array $data_poi
* @param array|null $defaults
* @return bool
*/
protected function validateProperties(&$document_data, &$data, array $data_pointer, array $parent_data_pointer, ISchema $document, $schema, ValidationResult $bag, array $defaults = null): bool
protected function validateProperties(&$document_data, &$data, array $data_pointer, array $parent_data_pointer, ISchema $document, $schema, ValidationResult $bag, ?array $defaults = null): bool
{
$type = $this->helper->type($data, true);
if ($type === 'null' || $type === 'boolean') {
Expand Down Expand Up @@ -1694,7 +1694,7 @@ protected function validateArray(&$document_data, &$data, array $data_pointer, a
* @param array|null $defaults
* @return bool
*/
protected function validateObject(&$document_data, &$data, array $data_pointer, array $parent_data_pointer, ISchema $document, $schema, ValidationResult $bag, array &$defaults = null): bool
protected function validateObject(&$document_data, &$data, array $data_pointer, array $parent_data_pointer, ISchema $document, $schema, ValidationResult $bag, ?array &$defaults = null): bool
{
$ok = true;

Expand Down Expand Up @@ -2014,7 +2014,7 @@ protected function validateObject(&$document_data, &$data, array $data_pointer,
* @param $data
* @param $defaults
*/
protected function setObjectDefaults($data, array &$defaults = null)
protected function setObjectDefaults($data, ?array &$defaults = null)
{
if (is_object($data) && $defaults) {
foreach ($defaults as $property => $value) {
Expand Down
2 changes: 1 addition & 1 deletion src/ValidatorHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public function isMultipleOf($number, $divisor): bool
/**
* @inheritDoc
*/
public function equals($a, $b, array $defaults = null): bool
public function equals($a, $b, ?array $defaults = null): bool
{
$a_type = $this->type($a, false);
$b_type = $this->type($b, false);
Expand Down
2 changes: 1 addition & 1 deletion tests/JsonValidatorTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected function getValidator(): IValidator
return $this->validator;
}

protected function createValidator(ISchemaLoader $loader = null, bool $use_default = true): IValidator
protected function createValidator(?ISchemaLoader $loader = null, bool $use_default = true): IValidator
{
if ($loader === null) {
$loader = new File( 'schema:', [__DIR__ . '/schemas']);
Expand Down