Skip to content

Commit

Permalink
refactor: Replace traditional syntax array with short syntax array
Browse files Browse the repository at this point in the history
  • Loading branch information
DannyvdSluijs committed Aug 27, 2024
1 parent 2eb0def commit cd83df0
Show file tree
Hide file tree
Showing 73 changed files with 1,422 additions and 1,422 deletions.
10 changes: 5 additions & 5 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

/* Based on ^2.1 of php-cs-fixer */
$config
->setRules(array(
->setRules([
// default
'@PSR2' => true,
'@Symfony' => true,
// additionally
'array_syntax' => array('syntax' => 'long'),
'array_syntax' => ['syntax' => 'short'],
'binary_operator_spaces' => false,
'concat_space' => array('spacing' => 'one'),
'concat_space' => ['spacing' => 'one'],
'increment_style' => false,
'no_superfluous_phpdoc_tags' => false,
'no_useless_else' => true,
Expand All @@ -22,12 +22,12 @@
'phpdoc_no_package' => false,
'phpdoc_order' => true,
'phpdoc_summary' => false,
'phpdoc_types_order' => array('null_adjustment' => 'none', 'sort_algorithm' => 'none'),
'phpdoc_types_order' => ['null_adjustment' => 'none', 'sort_algorithm' => 'none'],
'simplified_null_return' => false,
'single_line_throw' => false,
'trailing_comma_in_multiline' => false,
'yoda_style' => false,
))
])
->setFinder($finder)
;

Expand Down
22 changes: 11 additions & 11 deletions bin/validate-json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ if (!$composerAutoload) {
}
require($composerAutoload);

$arOptions = array();
$arArgs = array();
$arOptions = [];
$arArgs = [];
array_shift($argv);//script itself
foreach ($argv as $arg) {
if ($arg[0] == '-') {
Expand Down Expand Up @@ -66,7 +66,7 @@ if (count($arArgs) == 1) {
function showJsonError()
{
$constants = get_defined_constants(true);
$json_errors = array();
$json_errors = [];
foreach ($constants['json'] as $name => $value) {
if (!strncmp($name, 'JSON_ERROR_', 11)) {
$json_errors[$value] = $name;
Expand Down Expand Up @@ -101,11 +101,11 @@ function getUrlFromPath($path)
function parseHeaderValue($headerValue)
{
if (strpos($headerValue, ';') === false) {
return array('_value' => $headerValue);
return ['_value' => $headerValue];
}

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

$context = stream_context_create(
array(
'http' => array(
'header' => array(
[
'http' => [
'header' => [
'Accept: */*',
'Connection: Close'
),
],
'max_redirects' => 5
)
)
]
]
);
$dataString = file_get_contents($pathData, false, $context);
if ($dataString == '') {
Expand Down
2 changes: 1 addition & 1 deletion demo/demo.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

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

if ($validator->isValid()) {
echo "The supplied JSON validates against the schema.\n";
Expand Down
4 changes: 2 additions & 2 deletions src/JsonSchema/ConstraintError.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class ConstraintError extends Enum
public function getMessage()
{
$name = $this->getValue();
static $messages = array(
static $messages = [
self::ADDITIONAL_ITEMS => 'The item %s[%s] is not defined and the definition does not allow additional items',
self::ADDITIONAL_PROPERTIES => 'The property %s is not defined and the definition does not allow additional properties',
self::ALL_OF => 'Failed to match all schemas',
Expand Down Expand Up @@ -101,7 +101,7 @@ public function getMessage()
self::PROPERTIES_MAX => 'Must contain no more than %d properties',
self::TYPE => '%s value found, but %s is required',
self::UNIQUE_ITEMS => 'There are no duplicates allowed in the array'
);
];

if (!isset($messages[$name])) {
throw new InvalidArgumentException('Missing error message for ' . $name);
Expand Down
14 changes: 7 additions & 7 deletions src/JsonSchema/Constraints/BaseConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class BaseConstraint
/**
* @var array Errors
*/
protected $errors = array();
protected $errors = [];

/**
* @var int All error types which have occurred
Expand All @@ -44,11 +44,11 @@ public function __construct(?Factory $factory = null)
$this->factory = $factory ?: new Factory();
}

public function addError(ConstraintError $constraint, ?JsonPointer $path = null, array $more = array())
public function addError(ConstraintError $constraint, ?JsonPointer $path = null, array $more = [])
{
$message = $constraint ? $constraint->getMessage() : '';
$name = $constraint ? $constraint->getValue() : '';
$error = array(
$error = [
'property' => $this->convertJsonPointerIntoPropertyPath($path ?: new JsonPointer('')),
'pointer' => ltrim(strval($path ?: new JsonPointer('')), '#'),
'message' => ucfirst(vsprintf($message, array_map(function ($val) {
Expand All @@ -58,12 +58,12 @@ public function addError(ConstraintError $constraint, ?JsonPointer $path = null,

return json_encode($val);
}, array_values($more)))),
'constraint' => array(
'constraint' => [
'name' => $name,
'params' => $more
),
],
'context' => $this->factory->getErrorContext(),
);
];

if ($this->factory->getConfig(Constraint::CHECK_MODE_EXCEPTIONS)) {
throw new ValidationException(sprintf('Error validating %s: %s', $error['pointer'], $error['message']));
Expand Down Expand Up @@ -119,7 +119,7 @@ public function isValid()
*/
public function reset()
{
$this->errors = array();
$this->errors = [];
$this->errorMask = Validator::ERROR_NONE;
}

Expand Down
8 changes: 4 additions & 4 deletions src/JsonSchema/Constraints/CollectionConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ public function check(&$value, $schema = null, ?JsonPointer $path = null, $i = n
{
// Verify minItems
if (isset($schema->minItems) && count($value) < $schema->minItems) {
$this->addError(ConstraintError::MIN_ITEMS(), $path, array('minItems' => $schema->minItems));
$this->addError(ConstraintError::MIN_ITEMS(), $path, ['minItems' => $schema->minItems]);
}

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

// Verify uniqueItems
Expand Down Expand Up @@ -101,11 +101,11 @@ protected function validateItems(&$value, $schema = null, ?JsonPointer $path = n
$this->addError(
ConstraintError::ADDITIONAL_ITEMS(),
$path,
array(
[
'item' => $i,
'property' => $k,
'additionalItems' => $schema->additionalItems
)
]
);
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/JsonSchema/Constraints/ConstConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ public function check(&$element, $schema = null, ?JsonPointer $path = null, $i =
return;
}

$this->addError(ConstraintError::CONSTANT(), $path, array('const' => $schema->const));
$this->addError(ConstraintError::CONSTANT(), $path, ['const' => $schema->const]);
}
}
4 changes: 2 additions & 2 deletions src/JsonSchema/Constraints/Constraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ protected function incrementPath(?JsonPointer $path = null, $i)
$path = $path->withPropertyPaths(
array_merge(
$path->getPropertyPaths(),
array($i)
[$i]
)
);

Expand Down Expand Up @@ -85,7 +85,7 @@ protected function checkArray(&$value, $schema = null, ?JsonPointer $path = null
* @param mixed $patternProperties
*/
protected function checkObject(&$value, $schema = null, ?JsonPointer $path = null, $properties = null,
$additionalProperties = null, $patternProperties = null, $appliedDefaults = array())
$additionalProperties = null, $patternProperties = null, $appliedDefaults = [])
{
/** @var ObjectConstraint $validator */
$validator = $this->factory->createInstanceFor('object');
Expand Down
2 changes: 1 addition & 1 deletion 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 JsonPointer|null $path
* @param array $more more array elements to add to the error
*/
public function addError(ConstraintError $constraint, ?JsonPointer $path = null, array $more = array());
public function addError(ConstraintError $constraint, ?JsonPointer $path = null, array $more = []);

/**
* checks if the validator has not raised errors
Expand Down
2 changes: 1 addition & 1 deletion src/JsonSchema/Constraints/EnumConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ public function check(&$element, $schema = null, ?JsonPointer $path = null, $i =
}
}

$this->addError(ConstraintError::ENUM(), $path, array('enum' => $schema->enum));
$this->addError(ConstraintError::ENUM(), $path, ['enum' => $schema->enum]);
}
}
8 changes: 4 additions & 4 deletions src/JsonSchema/Constraints/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Factory
/**
* @var TypeCheck\TypeCheckInterface[]
*/
private $typeCheck = array();
private $typeCheck = [];

/**
* @var int Validation context
Expand All @@ -49,7 +49,7 @@ class Factory
/**
* @var array
*/
protected $constraintMap = array(
protected $constraintMap = [
'array' => 'JsonSchema\Constraints\CollectionConstraint',
'collection' => 'JsonSchema\Constraints\CollectionConstraint',
'object' => 'JsonSchema\Constraints\ObjectConstraint',
Expand All @@ -62,12 +62,12 @@ class Factory
'format' => 'JsonSchema\Constraints\FormatConstraint',
'schema' => 'JsonSchema\Constraints\SchemaConstraint',
'validator' => 'JsonSchema\Validator'
);
];

/**
* @var array<ConstraintInterface>
*/
private $instanceCache = array();
private $instanceCache = [];

/**
* @param ?SchemaStorage $schemaStorage
Expand Down
Loading

0 comments on commit cd83df0

Please sign in to comment.