Skip to content

Commit 2b6a820

Browse files
authored
Fixed deprecations - v1 (#152)
* Fixed deprecations * Updated tests.yml
1 parent c276370 commit 2b6a820

File tree

11 files changed

+37
-46
lines changed

11 files changed

+37
-46
lines changed

.github/workflows/tests.yml

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,24 @@ jobs:
1212
strategy:
1313
fail-fast: true
1414
matrix:
15-
php: [7.0, 7.1, 7.2, 7.3, 7.4, 8.0]
16-
stability: [prefer-stable]
15+
php: [7.4, 8.0, 8.1, 8.2, 8.3, 8.4]
1716

1817
name: PHP ${{ matrix.php }}
1918

2019
steps:
2120
- name: Checkout code
2221
uses: actions/checkout@v2
2322

24-
- name: Cache dependencies
25-
uses: actions/cache@v1
26-
with:
27-
path: ~/.composer/cache/files
28-
key: dependencies-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}
29-
3023
- name: Setup PHP
3124
uses: shivammathur/setup-php@v2
3225
with:
3326
php-version: ${{ matrix.php }}
3427
extensions: bcmath, json, mbstring, intl
28+
tools: composer:v2
3529
coverage: none
3630

37-
- name: Update composer
38-
run: composer self-update
39-
4031
- name: Install dependencies
41-
run: composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-progress
32+
run: composer update --no-interaction --no-progress
4233

4334
- name: Execute tests
4435
run: vendor/bin/phpunit --verbose

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
}
2121
],
2222
"require": {
23-
"php": ">=7.0"
23+
"php": ">=7.4"
2424
},
2525
"require-dev": {
26-
"opis/string": "^1.4",
26+
"opis/string": "^2.0",
2727
"ext-bcmath": "*",
2828
"ext-json": "*",
2929
"ext-mbstring": "*",

src/Formats/AbstractFormat.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ protected function validateRegex($data, string $regex): bool
3838
* @param null $options
3939
* @return bool
4040
*/
41-
protected function validateFilter($data, int $filter, $options = null): bool
41+
protected function validateFilter($data, int $filter, $options = 0): bool
4242
{
4343
return filter_var($data, $filter, $options) !== false;
4444
}

src/ISchema.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@ public function draft(): string;
3636
* @param string|null $id
3737
* @return mixed
3838
*/
39-
public function resolve(string $id = null);
39+
public function resolve(?string $id = null);
4040

4141
}

src/IValidator.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ interface IValidator
2828
* @param ISchemaLoader|null $loader
2929
* @return ValidationResult
3030
*/
31-
public function schemaValidation($data, ISchema $schema, int $max_errors = 1, ISchemaLoader $loader = null): ValidationResult;
31+
public function schemaValidation($data, ISchema $schema, int $max_errors = 1, ?ISchemaLoader $loader = null): ValidationResult;
3232

3333
/**
3434
* @param $data
@@ -37,7 +37,7 @@ public function schemaValidation($data, ISchema $schema, int $max_errors = 1, IS
3737
* @param ISchemaLoader|null $loader
3838
* @return ValidationResult
3939
*/
40-
public function uriValidation($data, string $schema_uri, int $max_errors = 1, ISchemaLoader $loader = null): ValidationResult;
40+
public function uriValidation($data, string $schema_uri, int $max_errors = 1, ?ISchemaLoader $loader = null): ValidationResult;
4141

4242
/**
4343
* @param $data
@@ -46,13 +46,13 @@ public function uriValidation($data, string $schema_uri, int $max_errors = 1, IS
4646
* @param ISchemaLoader|null $loader
4747
* @return ValidationResult
4848
*/
49-
public function dataValidation($data, $schema, int $max_errors = 1, ISchemaLoader $loader = null): ValidationResult;
49+
public function dataValidation($data, $schema, int $max_errors = 1, ?ISchemaLoader $loader = null): ValidationResult;
5050

5151
/**
5252
* @param IFilterContainer|null $filters
5353
* @return IValidator
5454
*/
55-
public function setFilters(IFilterContainer $filters = null): self;
55+
public function setFilters(?IFilterContainer $filters = null): self;
5656

5757
/**
5858
* @return IFilterContainer|null
@@ -63,7 +63,7 @@ public function getFilters();
6363
* @param IFormatContainer|null $formats
6464
* @return IValidator
6565
*/
66-
public function setFormats(IFormatContainer $formats = null): self;
66+
public function setFormats(?IFormatContainer $formats = null): self;
6767

6868
/**
6969
* @return IFilterContainer|null
@@ -85,7 +85,7 @@ public function getHelper(): IValidatorHelper;
8585
* @param ISchemaLoader|null $loader
8686
* @return IValidator
8787
*/
88-
public function setLoader(ISchemaLoader $loader = null): self;
88+
public function setLoader(?ISchemaLoader $loader = null): self;
8989

9090
/**
9191
* @return ISchemaLoader|null
@@ -96,7 +96,7 @@ public function getLoader();
9696
* @param IMediaTypeContainer|null $media
9797
* @return IValidator
9898
*/
99-
public function setMediaType(IMediaTypeContainer $media = null): self;
99+
public function setMediaType(?IMediaTypeContainer $media = null): self;
100100

101101
/**
102102
* @return IMediaTypeContainer|null

src/IValidatorHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,6 @@ public function isMultipleOf($number, $divisor): bool;
6161
* @param array $defaults
6262
* @return bool
6363
*/
64-
public function equals($a, $b, array $defaults = null): bool;
64+
public function equals($a, $b, ?array $defaults = null): bool;
6565

6666
}

src/Loaders/Memory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function unregister(ISchema $schema): self
5959
* @param string|null $id
6060
* @return Memory
6161
*/
62-
public function add($data, string $id = null): self
62+
public function add($data, ?string $id = null): self
6363
{
6464
if (is_string($data)) {
6565
$data = json_decode($data, false);

src/Schema.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class Schema implements ISchema
5353
* @param \stdClass|boolean $data
5454
* @param string|null $id
5555
*/
56-
public function __construct($data, string $id = null)
56+
public function __construct($data, ?string $id = null)
5757
{
5858
if (is_object($data)) {
5959
if (property_exists($data, static::ID_PROP)) {
@@ -117,7 +117,7 @@ public function draft(): string
117117
/**
118118
* @inheritDoc
119119
*/
120-
public function resolve(string $id = null)
120+
public function resolve(?string $id = null)
121121
{
122122
if ($id === null) {
123123
$id = $this->id;
@@ -196,7 +196,7 @@ public static function walk(array &$container, &$schema, string $id, array $path
196196
* @param string|null $id
197197
* @return Schema
198198
*/
199-
public static function fromJsonString(string $json, string $id = null): self
199+
public static function fromJsonString(string $json, ?string $id = null): self
200200
{
201201
return new self(json_decode($json, false), $id);
202202
}

src/Validator.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ class Validator implements IValidator
6565
* @param IFilterContainer|null $filters
6666
* @param IMediaTypeContainer|null $media
6767
*/
68-
public function __construct(IValidatorHelper $helper = null,
69-
ISchemaLoader $loader = null,
70-
IFormatContainer $formats = null,
71-
IFilterContainer $filters = null,
72-
IMediaTypeContainer $media = null)
68+
public function __construct(?IValidatorHelper $helper = null,
69+
?ISchemaLoader $loader = null,
70+
?IFormatContainer $formats = null,
71+
?IFilterContainer $filters = null,
72+
?IMediaTypeContainer $media = null)
7373
{
7474
$this->helper = $helper ?? new ValidatorHelper();
7575
$this->formats = $formats ?? new FormatContainer();
@@ -81,7 +81,7 @@ public function __construct(IValidatorHelper $helper = null,
8181
/**
8282
* @inheritDoc
8383
*/
84-
public function schemaValidation($data, ISchema $schema, int $max_errors = 1, ISchemaLoader $loader = null): ValidationResult
84+
public function schemaValidation($data, ISchema $schema, int $max_errors = 1, ?ISchemaLoader $loader = null): ValidationResult
8585
{
8686
$bag = new ValidationResult($max_errors);
8787

@@ -103,7 +103,7 @@ public function schemaValidation($data, ISchema $schema, int $max_errors = 1, IS
103103
/**
104104
* @inheritDoc
105105
*/
106-
public function uriValidation($data, string $schema_uri, int $max_errors = 1, ISchemaLoader $loader = null): ValidationResult
106+
public function uriValidation($data, string $schema_uri, int $max_errors = 1, ?ISchemaLoader $loader = null): ValidationResult
107107
{
108108
$schema = new stdClass();
109109
$schema->{'$ref'} = URI::normalize($schema_uri);
@@ -113,7 +113,7 @@ public function uriValidation($data, string $schema_uri, int $max_errors = 1, IS
113113
/**
114114
* @inheritDoc
115115
*/
116-
public function dataValidation($data, $schema, int $max_errors = 1, ISchemaLoader $loader = null): ValidationResult
116+
public function dataValidation($data, $schema, int $max_errors = 1, ?ISchemaLoader $loader = null): ValidationResult
117117
{
118118
$schema = is_string($schema) ? Schema::fromJsonString($schema) : new Schema($schema);
119119
return $this->schemaValidation($data, $schema, $max_errors, $loader);
@@ -122,7 +122,7 @@ public function dataValidation($data, $schema, int $max_errors = 1, ISchemaLoade
122122
/**
123123
* @inheritDoc
124124
*/
125-
public function setFilters(IFilterContainer $filters = null): IValidator
125+
public function setFilters(?IFilterContainer $filters = null): IValidator
126126
{
127127
$this->filters = $filters;
128128
return $this;
@@ -139,7 +139,7 @@ public function getFilters()
139139
/**
140140
* @inheritDoc
141141
*/
142-
public function setFormats(IFormatContainer $formats = null): IValidator
142+
public function setFormats(?IFormatContainer $formats = null): IValidator
143143
{
144144
$this->formats = $formats;
145145
return $this;
@@ -173,7 +173,7 @@ public function getHelper(): IValidatorHelper
173173
/**
174174
* @inheritDoc
175175
*/
176-
public function setLoader(ISchemaLoader $loader = null): IValidator
176+
public function setLoader(?ISchemaLoader $loader = null): IValidator
177177
{
178178
$this->loader = $loader;
179179
return $this;
@@ -190,7 +190,7 @@ public function getLoader()
190190
/**
191191
* @inheritDoc
192192
*/
193-
public function setMediaType(IMediaTypeContainer $media = null): IValidator
193+
public function setMediaType(?IMediaTypeContainer $media = null): IValidator
194194
{
195195
$this->mediaTypes = $media;
196196
return $this;
@@ -544,7 +544,7 @@ protected function validateKeywords(&$document_data, &$data, array $data_pointer
544544
* @return bool
545545
*/
546546
protected function validateCommons(/** @noinspection PhpUnusedParameterInspection */
547-
&$document_data, &$data, array $data_pointer, array $parent_data_pointer, ISchema $document, $schema, ValidationResult $bag, array &$defaults = null): bool
547+
&$document_data, &$data, array $data_pointer, array $parent_data_pointer, ISchema $document, $schema, ValidationResult $bag, ?array &$defaults = null): bool
548548
{
549549
$ok = true;
550550

@@ -929,7 +929,7 @@ protected function validateConditionals(&$document_data, &$data, array $data_poi
929929
* @param array|null $defaults
930930
* @return bool
931931
*/
932-
protected function validateProperties(&$document_data, &$data, array $data_pointer, array $parent_data_pointer, ISchema $document, $schema, ValidationResult $bag, array $defaults = null): bool
932+
protected function validateProperties(&$document_data, &$data, array $data_pointer, array $parent_data_pointer, ISchema $document, $schema, ValidationResult $bag, ?array $defaults = null): bool
933933
{
934934
$type = $this->helper->type($data, true);
935935
if ($type === 'null' || $type === 'boolean') {
@@ -1694,7 +1694,7 @@ protected function validateArray(&$document_data, &$data, array $data_pointer, a
16941694
* @param array|null $defaults
16951695
* @return bool
16961696
*/
1697-
protected function validateObject(&$document_data, &$data, array $data_pointer, array $parent_data_pointer, ISchema $document, $schema, ValidationResult $bag, array &$defaults = null): bool
1697+
protected function validateObject(&$document_data, &$data, array $data_pointer, array $parent_data_pointer, ISchema $document, $schema, ValidationResult $bag, ?array &$defaults = null): bool
16981698
{
16991699
$ok = true;
17001700

@@ -2014,7 +2014,7 @@ protected function validateObject(&$document_data, &$data, array $data_pointer,
20142014
* @param $data
20152015
* @param $defaults
20162016
*/
2017-
protected function setObjectDefaults($data, array &$defaults = null)
2017+
protected function setObjectDefaults($data, ?array &$defaults = null)
20182018
{
20192019
if (is_object($data) && $defaults) {
20202020
foreach ($defaults as $property => $value) {

src/ValidatorHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public function isMultipleOf($number, $divisor): bool
139139
/**
140140
* @inheritDoc
141141
*/
142-
public function equals($a, $b, array $defaults = null): bool
142+
public function equals($a, $b, ?array $defaults = null): bool
143143
{
144144
$a_type = $this->type($a, false);
145145
$b_type = $this->type($b, false);

0 commit comments

Comments
 (0)