Skip to content
This repository has been archived by the owner on May 12, 2018. It is now read-only.

Commit

Permalink
Restore PHP 5.5 support
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Allan committed May 11, 2016
1 parent f46d4f9 commit 5c0ae09
Show file tree
Hide file tree
Showing 20 changed files with 42 additions and 49 deletions.
2 changes: 1 addition & 1 deletion .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ checks:
tools:
external_code_coverage:
timeout: 600
runs: 1
runs: 2
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
language: php

php:
- 5.5
- 5.6
- 7.0
- hhvm
Expand Down
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ This project adheres to [Semantic Versioning](http://semver.org/).
### Changed

* The `ErrorCode` constants class is now marked as final.
* Dropped support for PHP 5.5
* All function names are now snake cased.

## 0.2.1 - 2016-05-08
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
}
],
"require": {
"php": ">=5.6.0"
"php": ">=5.5.0"
},
"suggest": {
"ext-bcmath": "Required to properly check type constraints for numbers larger than PHP_INT_MAX."
Expand Down
4 changes: 2 additions & 2 deletions src/Constraints/Enum.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use League\JsonGuard\ErrorCode;
use League\JsonGuard\ValidationError;
use function League\JsonGuard\as_string;
use League\JsonGuard;

class Enum implements PropertyConstraint
{
Expand All @@ -23,7 +23,7 @@ public static function validate($value, $parameter, $pointer = null)

$message = sprintf(
'Value "%s" is not one of: %s',
as_string($value),
JsonGuard\as_string($value),
implode(', ', array_map('League\JsonGuard\as_string', $parameter))
);
return new ValidationError($message, ErrorCode::INVALID_ENUM, $value, $pointer, ['choices' => $parameter]);
Expand Down
3 changes: 1 addition & 2 deletions src/Constraints/Format.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace League\JsonGuard\Constraints;

use League\JsonGuard;
use function League\JsonGuard\as_string;
use League\JsonGuard\ErrorCode;
use League\JsonGuard\ValidationError;

Expand Down Expand Up @@ -122,6 +121,6 @@ private static function validateFilter($format, $value, $filter, $options, $erro
*/
private static function invalidFormatMessage($format, $value)
{
return sprintf('"%s" is not a valid %s.', as_string($value), $format);
return sprintf('"%s" is not a valid %s.', JsonGuard\as_string($value), $format);
}
}
10 changes: 5 additions & 5 deletions src/Constraints/Max.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace League\JsonGuard\Constraints;

use function League\JsonGuard\as_string;
use League\JsonGuard;
use League\JsonGuard\ErrorCode;
use League\JsonGuard\ValidationError;

Expand Down Expand Up @@ -35,8 +35,8 @@ public static function validateMax($value, $parameter, $pointer = null)

$message = sprintf(
'Number "%s" is not at most "%d"',
as_string($value),
as_string($parameter)
JsonGuard\as_string($value),
JsonGuard\as_string($parameter)
);
return new ValidationError($message, ErrorCode::INVALID_MAX, $value, $pointer, ['max' => $parameter]);
}
Expand All @@ -56,8 +56,8 @@ public static function validateExclusiveMax($value, $parameter, $pointer = null)

$message = sprintf(
'Number "%s" is not less than "%d"',
as_string($value),
as_string($parameter)
JsonGuard\as_string($value),
JsonGuard\as_string($parameter)
);
return new ValidationError(
$message,
Expand Down
3 changes: 1 addition & 2 deletions src/Constraints/MaxItems.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace League\JsonGuard\Constraints;

use League\JsonGuard;
use function League\JsonGuard\as_string;
use League\JsonGuard\ErrorCode;
use League\JsonGuard\ValidationError;

Expand All @@ -18,7 +17,7 @@ public static function validate($value, $parameter, $pointer = null)
return null;
}

$message = sprintf('Array does not contain less than "%d" items', as_string($parameter));
$message = sprintf('Array does not contain less than "%d" items', JsonGuard\as_string($parameter));
return new ValidationError(
$message,
ErrorCode::MAX_ITEMS_EXCEEDED,
Expand Down
7 changes: 3 additions & 4 deletions src/Constraints/MaxLength.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

namespace League\JsonGuard\Constraints;

use function League\JsonGuard\strlen;
use function League\JsonGuard\as_string;
use League\JsonGuard;
use League\JsonGuard\ErrorCode;
use League\JsonGuard\ValidationError;

Expand All @@ -14,11 +13,11 @@ class MaxLength implements PropertyConstraint
*/
public static function validate($value, $parameter, $pointer = null)
{
if (!is_string($value) || strlen($value) <= $parameter) {
if (!is_string($value) || JsonGuard\strlen($value) <= $parameter) {
return null;
}

$message = sprintf('String is not at most "%s" characters long', as_string($parameter));
$message = sprintf('String is not at most "%s" characters long', JsonGuard\as_string($parameter));
return new ValidationError(
$message,
ErrorCode::INVALID_MAX_LENGTH,
Expand Down
4 changes: 2 additions & 2 deletions src/Constraints/MaxProperties.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace League\JsonGuard\Constraints;

use function League\JsonGuard\as_string;
use League\JsonGuard;
use League\JsonGuard\ErrorCode;
use League\JsonGuard\ValidationError;

Expand All @@ -17,7 +17,7 @@ public static function validate($value, $parameter, $pointer = null)
return null;
}

$message = sprintf('Object does not contain less than "%d" properties', as_string($parameter));
$message = sprintf('Object does not contain less than "%d" properties', JsonGuard\as_string($parameter));
return new ValidationError(
$message,
ErrorCode::MAX_PROPERTIES_EXCEEDED,
Expand Down
10 changes: 5 additions & 5 deletions src/Constraints/Min.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace League\JsonGuard\Constraints;

use League\JsonGuard;
use League\JsonGuard\ErrorCode;
use League\JsonGuard\ValidationError;
use function League\JsonGuard\as_string;

class Min implements ParentSchemaAwarePropertyConstraint
{
Expand Down Expand Up @@ -35,8 +35,8 @@ public static function validateMin($value, $parameter, $pointer = null)

$message = sprintf(
'Number "%s" is not at least "%d"',
as_string($value),
as_string($parameter)
JsonGuard\as_string($value),
JsonGuard\as_string($parameter)
);

return new ValidationError($message, ErrorCode::INVALID_MIN, $value, $pointer, ['min' => $parameter]);
Expand All @@ -57,8 +57,8 @@ public static function validateExclusiveMin($value, $parameter, $pointer = null)

$message = sprintf(
'Number "%s" is not at least greater than "%d"',
as_string($value),
as_string($parameter)
JsonGuard\as_string($value),
JsonGuard\as_string($parameter)
);

return new ValidationError(
Expand Down
4 changes: 2 additions & 2 deletions src/Constraints/MinItems.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace League\JsonGuard\Constraints;

use function League\JsonGuard\as_string;
use League\JsonGuard;
use League\JsonGuard\ErrorCode;
use League\JsonGuard\ValidationError;

Expand All @@ -17,7 +17,7 @@ public static function validate($value, $parameter, $pointer = null)
return null;
}

$message = sprintf('Array does not contain more than "%d" items', as_string($parameter));
$message = sprintf('Array does not contain more than "%d" items', JsonGuard\as_string($parameter));
return new ValidationError(
$message,
ErrorCode::INVALID_MIN_COUNT,
Expand Down
7 changes: 3 additions & 4 deletions src/Constraints/MinLength.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

namespace League\JsonGuard\Constraints;

use function League\JsonGuard\strlen;
use function League\JsonGuard\as_string;
use League\JsonGuard;
use League\JsonGuard\ErrorCode;
use League\JsonGuard\ValidationError;

Expand All @@ -14,11 +13,11 @@ class MinLength implements PropertyConstraint
*/
public static function validate($value, $parameter, $pointer = null)
{
if (!is_string($value) || strlen($value) >= $parameter) {
if (!is_string($value) || JsonGuard\strlen($value) >= $parameter) {
return null;
}

$message = sprintf('String is not at least "%s" characters long', as_string($parameter));
$message = sprintf('String is not at least "%s" characters long', JsonGuard\as_string($parameter));

return new ValidationError(
$message,
Expand Down
4 changes: 2 additions & 2 deletions src/Constraints/MinProperties.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace League\JsonGuard\Constraints;

use function League\JsonGuard\as_string;
use League\JsonGuard;
use League\JsonGuard\ErrorCode;
use League\JsonGuard\ValidationError;

Expand All @@ -17,7 +17,7 @@ public static function validate($value, $min, $pointer = null)
return null;
}

$message = sprintf('Object does not contain at least "%d" properties', as_string($min));
$message = sprintf('Object does not contain at least "%d" properties', JsonGuard\as_string($min));
return new ValidationError(
$message,
ErrorCode::INVALID_MIN_COUNT,
Expand Down
6 changes: 3 additions & 3 deletions src/Constraints/MultipleOf.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace League\JsonGuard\Constraints;

use function League\JsonGuard\as_string;
use League\JsonGuard;
use League\JsonGuard\ErrorCode;
use League\JsonGuard\ValidationError;

Expand All @@ -26,8 +26,8 @@ public static function validate($value, $multiple, $pointer = null)

$message = sprintf(
'Number "%d" is not a multiple of "%d"',
as_string($value),
as_string($multiple)
JsonGuard\as_string($value),
JsonGuard\as_string($multiple)
);
return new ValidationError(
$message,
Expand Down
7 changes: 3 additions & 4 deletions src/Constraints/Pattern.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

namespace League\JsonGuard\Constraints;

use function League\JsonGuard\as_string;
use function League\JsonGuard\delimit_pattern;
use League\JsonGuard;
use League\JsonGuard\ErrorCode;
use League\JsonGuard\ValidationError;

Expand All @@ -18,11 +17,11 @@ public static function validate($value, $pattern, $pointer = null)
return null;
}

if (preg_match(delimit_pattern($pattern), $value) === 1) {
if (preg_match(JsonGuard\delimit_pattern($pattern), $value) === 1) {
return null;
}

$message = sprintf('Value "%s" does not match the given pattern.', as_string($value));
$message = sprintf('Value "%s" does not match the given pattern.', JsonGuard\as_string($value));
return new ValidationError($message, ErrorCode::INVALID_PATTERN, $value, $pointer, ['pattern' => $pattern]);
}
}
3 changes: 1 addition & 2 deletions src/Constraints/PatternProperties.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace League\JsonGuard\Constraints;

use League\JsonGuard;
use function League\JsonGuard\properties_matching_pattern;
use League\JsonGuard\SubSchemaValidatorFactory;

class PatternProperties implements ContainerInstanceConstraint
Expand All @@ -19,7 +18,7 @@ public static function validate($data, $parameter, SubSchemaValidatorFactory $va

$errors = [];
foreach ($parameter as $property => $schema) {
$matches = properties_matching_pattern($property, $data);
$matches = JsonGuard\properties_matching_pattern($property, $data);
$matchedSchema = array_fill_keys($matches, $schema);
$propertyErrors = Properties::validate($data, $matchedSchema, $validatorFactory, $pointer);
if (is_array($propertyErrors)) {
Expand Down
4 changes: 2 additions & 2 deletions src/Constraints/Properties.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace League\JsonGuard\Constraints;

use function League\JsonGuard\escape_pointer;
use League\JsonGuard;
use League\JsonGuard\SubSchemaValidatorFactory;

class Properties implements ContainerInstanceConstraint
Expand All @@ -23,7 +23,7 @@ public static function validate($data, $parameter, SubSchemaValidatorFactory $va
foreach ($parameter as $property => $schema) {
if (is_object($data) && property_exists($data, $property)) {
$propertyData = $data->$property;
$propertyPointer = $pointer . '/' . escape_pointer($property);
$propertyPointer = $pointer . '/' . JsonGuard\escape_pointer($property);
$validator = $validatorFactory->makeSubSchemaValidator($propertyData, $schema, $propertyPointer);
if ($validator->fails()) {
$errors = array_merge($errors, $validator->errors());
Expand Down
5 changes: 2 additions & 3 deletions src/Constraints/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use League\JsonGuard;
use League\JsonGuard\ErrorCode;
use League\JsonGuard\ValidationError;
use function League\JsonGuard\as_string;

class Type implements PropertyConstraint
{
Expand Down Expand Up @@ -83,7 +82,7 @@ private static function validateType($value, $type, callable $callable, $errorCo
return null;
}

$message = sprintf('Value "%s" is not a(n) %s.', as_string($value), $type);
$message = sprintf('Value "%s" is not a(n) %s.', JsonGuard\as_string($value), $type);

return new ValidationError($message, $errorCode, $value, $pointer);
}
Expand All @@ -106,7 +105,7 @@ private static function anyType($value, array $choices, $pointer)

$message = sprintf(
'Value "%s" is not one of: %s',
as_string($value),
JsonGuard\as_string($value),
implode(', ', array_map('League\JsonGuard\as_string', $choices))
);

Expand Down
4 changes: 2 additions & 2 deletions src/Constraints/UniqueItems.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace League\JsonGuard\Constraints;

use function League\JsonGuard\as_string;
use League\JsonGuard;
use League\JsonGuard\ErrorCode;
use League\JsonGuard\ValidationError;

Expand All @@ -21,7 +21,7 @@ public static function validate($value, $parameter, $pointer = null)
return null;
}

$message = sprintf('Array "%s" is not unique.', as_string($value));
$message = sprintf('Array "%s" is not unique.', JsonGuard\as_string($value));
return new ValidationError($message, ErrorCode::NOT_UNIQUE_ITEM, $value, $pointer);
}
}

0 comments on commit 5c0ae09

Please sign in to comment.