Skip to content

Commit cddbef1

Browse files
refactor: Replace traditional syntax array with short syntax array (#747)
* refactor: Replace traditional syntax array with short syntax array * docs: Update changelog
1 parent 2eb0def commit cddbef1

File tree

74 files changed

+1426
-1422
lines changed

Some content is hidden

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

74 files changed

+1426
-1422
lines changed

.php-cs-fixer.dist.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66

77
/* Based on ^2.1 of php-cs-fixer */
88
$config
9-
->setRules(array(
9+
->setRules([
1010
// default
1111
'@PSR2' => true,
1212
'@Symfony' => true,
1313
// additionally
14-
'array_syntax' => array('syntax' => 'long'),
14+
'array_syntax' => ['syntax' => 'short'],
1515
'binary_operator_spaces' => false,
16-
'concat_space' => array('spacing' => 'one'),
16+
'concat_space' => ['spacing' => 'one'],
1717
'increment_style' => false,
1818
'no_superfluous_phpdoc_tags' => false,
1919
'no_useless_else' => true,
@@ -22,12 +22,12 @@
2222
'phpdoc_no_package' => false,
2323
'phpdoc_order' => true,
2424
'phpdoc_summary' => false,
25-
'phpdoc_types_order' => array('null_adjustment' => 'none', 'sort_algorithm' => 'none'),
25+
'phpdoc_types_order' => ['null_adjustment' => 'none', 'sort_algorithm' => 'none'],
2626
'simplified_null_return' => false,
2727
'single_line_throw' => false,
2828
'trailing_comma_in_multiline' => false,
2929
'yoda_style' => false,
30-
))
30+
])
3131
->setFinder($finder)
3232
;
3333

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
- Add missing property in UriResolverTest ([#743](https://github.com/jsonrainbow/json-schema/pull/743))
1313
- Correct casing of paths used in tests ([#745](https://github.com/jsonrainbow/json-schema/pull/745))
1414

15+
### Changed
16+
- Bump to minimum PHP 7.2 ([#746](https://github.com/jsonrainbow/json-schema/pull/746))
17+
- Replace traditional syntax array with short syntax array ([#747](https://github.com/jsonrainbow/json-schema/pull/747))
18+
1519
## [6.0.0] - 2024-07-30
1620
### Added
1721
- Add URI translation, package:// URI scheme & bundle spec schemas ([#362](https://github.com/jsonrainbow/json-schema/pull/362))

bin/validate-json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ if (!$composerAutoload) {
2020
}
2121
require($composerAutoload);
2222

23-
$arOptions = array();
24-
$arArgs = array();
23+
$arOptions = [];
24+
$arArgs = [];
2525
array_shift($argv);//script itself
2626
foreach ($argv as $arg) {
2727
if ($arg[0] == '-') {
@@ -66,7 +66,7 @@ if (count($arArgs) == 1) {
6666
function showJsonError()
6767
{
6868
$constants = get_defined_constants(true);
69-
$json_errors = array();
69+
$json_errors = [];
7070
foreach ($constants['json'] as $name => $value) {
7171
if (!strncmp($name, 'JSON_ERROR_', 11)) {
7272
$json_errors[$value] = $name;
@@ -101,11 +101,11 @@ function getUrlFromPath($path)
101101
function parseHeaderValue($headerValue)
102102
{
103103
if (strpos($headerValue, ';') === false) {
104-
return array('_value' => $headerValue);
104+
return ['_value' => $headerValue];
105105
}
106106

107107
$parts = explode(';', $headerValue);
108-
$arData = array('_value' => array_shift($parts));
108+
$arData = ['_value' => array_shift($parts)];
109109
foreach ($parts as $part) {
110110
list($name, $value) = explode('=', $part);
111111
$arData[$name] = trim($value, ' "\'');
@@ -128,15 +128,15 @@ function output($str) {
128128
$urlData = getUrlFromPath($pathData);
129129

130130
$context = stream_context_create(
131-
array(
132-
'http' => array(
133-
'header' => array(
131+
[
132+
'http' => [
133+
'header' => [
134134
'Accept: */*',
135135
'Connection: Close'
136-
),
136+
],
137137
'max_redirects' => 5
138-
)
139-
)
138+
]
139+
]
140140
);
141141
$dataString = file_get_contents($pathData, false, $context);
142142
if ($dataString == '') {

demo/demo.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
// Validate
88
$validator = new JsonSchema\Validator();
9-
$validator->validate($data, (object) array('$ref' => 'file://' . realpath('schema.json')));
9+
$validator->validate($data, (object) ['$ref' => 'file://' . realpath('schema.json')]);
1010

1111
if ($validator->isValid()) {
1212
echo "The supplied JSON validates against the schema.\n";

src/JsonSchema/ConstraintError.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class ConstraintError extends Enum
5555
public function getMessage()
5656
{
5757
$name = $this->getValue();
58-
static $messages = array(
58+
static $messages = [
5959
self::ADDITIONAL_ITEMS => 'The item %s[%s] is not defined and the definition does not allow additional items',
6060
self::ADDITIONAL_PROPERTIES => 'The property %s is not defined and the definition does not allow additional properties',
6161
self::ALL_OF => 'Failed to match all schemas',
@@ -101,7 +101,7 @@ public function getMessage()
101101
self::PROPERTIES_MAX => 'Must contain no more than %d properties',
102102
self::TYPE => '%s value found, but %s is required',
103103
self::UNIQUE_ITEMS => 'There are no duplicates allowed in the array'
104-
);
104+
];
105105

106106
if (!isset($messages[$name])) {
107107
throw new InvalidArgumentException('Missing error message for ' . $name);

src/JsonSchema/Constraints/BaseConstraint.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class BaseConstraint
2424
/**
2525
* @var array Errors
2626
*/
27-
protected $errors = array();
27+
protected $errors = [];
2828

2929
/**
3030
* @var int All error types which have occurred
@@ -44,11 +44,11 @@ public function __construct(?Factory $factory = null)
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 = [])
4848
{
4949
$message = $constraint ? $constraint->getMessage() : '';
5050
$name = $constraint ? $constraint->getValue() : '';
51-
$error = array(
51+
$error = [
5252
'property' => $this->convertJsonPointerIntoPropertyPath($path ?: new JsonPointer('')),
5353
'pointer' => ltrim(strval($path ?: new JsonPointer('')), '#'),
5454
'message' => ucfirst(vsprintf($message, array_map(function ($val) {
@@ -58,12 +58,12 @@ public function addError(ConstraintError $constraint, ?JsonPointer $path = null,
5858

5959
return json_encode($val);
6060
}, array_values($more)))),
61-
'constraint' => array(
61+
'constraint' => [
6262
'name' => $name,
6363
'params' => $more
64-
),
64+
],
6565
'context' => $this->factory->getErrorContext(),
66-
);
66+
];
6767

6868
if ($this->factory->getConfig(Constraint::CHECK_MODE_EXCEPTIONS)) {
6969
throw new ValidationException(sprintf('Error validating %s: %s', $error['pointer'], $error['message']));
@@ -119,7 +119,7 @@ public function isValid()
119119
*/
120120
public function reset()
121121
{
122-
$this->errors = array();
122+
$this->errors = [];
123123
$this->errorMask = Validator::ERROR_NONE;
124124
}
125125

src/JsonSchema/Constraints/CollectionConstraint.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ public function check(&$value, $schema = null, ?JsonPointer $path = null, $i = n
2727
{
2828
// Verify minItems
2929
if (isset($schema->minItems) && count($value) < $schema->minItems) {
30-
$this->addError(ConstraintError::MIN_ITEMS(), $path, array('minItems' => $schema->minItems));
30+
$this->addError(ConstraintError::MIN_ITEMS(), $path, ['minItems' => $schema->minItems]);
3131
}
3232

3333
// Verify maxItems
3434
if (isset($schema->maxItems) && count($value) > $schema->maxItems) {
35-
$this->addError(ConstraintError::MAX_ITEMS(), $path, array('maxItems' => $schema->maxItems));
35+
$this->addError(ConstraintError::MAX_ITEMS(), $path, ['maxItems' => $schema->maxItems]);
3636
}
3737

3838
// Verify uniqueItems
@@ -101,11 +101,11 @@ protected function validateItems(&$value, $schema = null, ?JsonPointer $path = n
101101
$this->addError(
102102
ConstraintError::ADDITIONAL_ITEMS(),
103103
$path,
104-
array(
104+
[
105105
'item' => $i,
106106
'property' => $k,
107107
'additionalItems' => $schema->additionalItems
108-
)
108+
]
109109
);
110110
}
111111
} else {

src/JsonSchema/Constraints/ConstConstraint.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,6 @@ public function check(&$element, $schema = null, ?JsonPointer $path = null, $i =
4444
return;
4545
}
4646

47-
$this->addError(ConstraintError::CONSTANT(), $path, array('const' => $schema->const));
47+
$this->addError(ConstraintError::CONSTANT(), $path, ['const' => $schema->const]);
4848
}
4949
}

src/JsonSchema/Constraints/Constraint.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ protected function incrementPath(?JsonPointer $path = null, $i)
5151
$path = $path->withPropertyPaths(
5252
array_merge(
5353
$path->getPropertyPaths(),
54-
array($i)
54+
[$i]
5555
)
5656
);
5757

@@ -85,7 +85,7 @@ protected function checkArray(&$value, $schema = null, ?JsonPointer $path = null
8585
* @param mixed $patternProperties
8686
*/
8787
protected function checkObject(&$value, $schema = null, ?JsonPointer $path = null, $properties = null,
88-
$additionalProperties = null, $patternProperties = null, $appliedDefaults = array())
88+
$additionalProperties = null, $patternProperties = null, $appliedDefaults = [])
8989
{
9090
/** @var ObjectConstraint $validator */
9191
$validator = $this->factory->createInstanceFor('object');

src/JsonSchema/Constraints/ConstraintInterface.php

Lines changed: 1 addition & 1 deletion
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 = []);
4444

4545
/**
4646
* checks if the validator has not raised errors

src/JsonSchema/Constraints/EnumConstraint.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,6 @@ public function check(&$element, $schema = null, ?JsonPointer $path = null, $i =
4747
}
4848
}
4949

50-
$this->addError(ConstraintError::ENUM(), $path, array('enum' => $schema->enum));
50+
$this->addError(ConstraintError::ENUM(), $path, ['enum' => $schema->enum]);
5151
}
5252
}

src/JsonSchema/Constraints/Factory.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class Factory
3939
/**
4040
* @var TypeCheck\TypeCheckInterface[]
4141
*/
42-
private $typeCheck = array();
42+
private $typeCheck = [];
4343

4444
/**
4545
* @var int Validation context
@@ -49,7 +49,7 @@ class Factory
4949
/**
5050
* @var array
5151
*/
52-
protected $constraintMap = array(
52+
protected $constraintMap = [
5353
'array' => 'JsonSchema\Constraints\CollectionConstraint',
5454
'collection' => 'JsonSchema\Constraints\CollectionConstraint',
5555
'object' => 'JsonSchema\Constraints\ObjectConstraint',
@@ -62,12 +62,12 @@ class Factory
6262
'format' => 'JsonSchema\Constraints\FormatConstraint',
6363
'schema' => 'JsonSchema\Constraints\SchemaConstraint',
6464
'validator' => 'JsonSchema\Validator'
65-
);
65+
];
6666

6767
/**
6868
* @var array<ConstraintInterface>
6969
*/
70-
private $instanceCache = array();
70+
private $instanceCache = [];
7171

7272
/**
7373
* @param ?SchemaStorage $schemaStorage

0 commit comments

Comments
 (0)