Skip to content

Follow PSR2 rules #140

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

Closed
wants to merge 2 commits into from
Closed
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
!/bin/validate-json
coverage
.buildpath
.php_cs.cache
.project
.settings
composer.lock
14 changes: 14 additions & 0 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

use Symfony\CS\Config\Config;
use Symfony\CS\FixerInterface;

$config = Config::create()
->level(Symfony\CS\FixerInterface::PSR2_LEVEL)
->setUsingCache(true)
->setUsingLinter(false);

$finder = $config->getFinder()
->in(__DIR__);

return $config;
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ install:
- sudo apt-get -y install pypy python-sphinx graphviz
- composer selfupdate
- travis_retry composer update --no-interaction --prefer-source
- curl http://get.sensiolabs.org/php-cs-fixer.phar -o php-cs-fixer.phar

script:
- cd docs && make linkcheck && cd ..
- vendor/bin/phpdoc.php -d src -t docs-api
- vendor/bin/phpunit --coverage-text
- if [[ `php -r "echo version_compare(PHP_VERSION, '5.3.6', '>=') && !defined('HHVM_VERSION');"` ]]; then php php-cs-fixer.phar --diff --dry-run -vv fix; fi
8 changes: 4 additions & 4 deletions src/JsonSchema/Constraints/CollectionConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function check($value, $schema = null, $path = null, $i = null)
if (isset($schema->uniqueItems)) {
$unique = $value;
if (is_array($value) && count($value)) {
$unique = array_map(function($e) { return var_export($e, true); }, $value);
$unique = array_map(function ($e) { return var_export($e, true); }, $value);
}
if (count(array_unique($unique)) != count($value)) {
$this->addError($path, "There are no duplicates allowed in the array");
Expand Down Expand Up @@ -76,7 +76,7 @@ protected function validateItems($value, $schema = null, $path = null, $i = null
// Reset errors if needed
if (isset($secondErrors) && count($secondErrors) < count($this->getErrors())) {
$this->errors = $secondErrors;
} else if (isset($secondErrors) && count($secondErrors) === count($this->getErrors())) {
} elseif (isset($secondErrors) && count($secondErrors) === count($this->getErrors())) {
$this->errors = $initErrors;
}
}
Expand All @@ -102,11 +102,11 @@ protected function validateItems($value, $schema = null, $path = null, $i = null
}

// Treat when we have more schema definitions than values, not for empty arrays
if(count($value) > 0) {
if (count($value) > 0) {
for ($k = count($value); $k < count($schema->items); $k++) {
$this->checkUndefined(new UndefinedConstraint(), $schema->items[$k], $path, $k);
}
}
}
}
}
}
3 changes: 1 addition & 2 deletions src/JsonSchema/Constraints/Constraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ public function __construct($checkMode = self::CHECK_MODE_NORMAL, UriRetriever $
*/
public function getUriRetriever()
{
if (is_null($this->uriRetriever))
{
if (is_null($this->uriRetriever)) {
$this->setUriRetriever(new UriRetriever);
}

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 @@ -55,4 +55,4 @@ public function isValid();
* @param mixed $i
*/
public function check($value, $schema = null, $path = null, $i = null);
}
}
7 changes: 4 additions & 3 deletions src/JsonSchema/Constraints/EnumConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ public function check($element, $schema = null, $path = null, $i = null)
$type = gettype($element);
if ($type === gettype($enum)) {
if ($type == "object") {
if ($element == $enum)
if ($element == $enum) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There they are: #132 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't get it... it's ok for you to add that missing braces or not ?

return;
}
} else {
if ($element === $enum)
if ($element === $enum) {
return;

}
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/JsonSchema/Constraints/NumberConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ public function check($element, $schema = null, $path = null, $i = null)
if (isset($schema->minimum)) {
if ($schema->exclusiveMinimum && $element === $schema->minimum) {
$this->addError($path, "must have a minimum value greater than boundary value of " . $schema->minimum);
} else if ($element < $schema->minimum) {
} elseif ($element < $schema->minimum) {
$this->addError($path, "must have a minimum value of " . $schema->minimum);
}
} else {
$this->addError($path, "use of exclusiveMinimum requires presence of minimum");
}
} else if (isset($schema->minimum) && $element < $schema->minimum) {
} elseif (isset($schema->minimum) && $element < $schema->minimum) {
$this->addError($path, "must have a minimum value of " . $schema->minimum);
}

Expand All @@ -42,13 +42,13 @@ public function check($element, $schema = null, $path = null, $i = null)
if (isset($schema->maximum)) {
if ($schema->exclusiveMaximum && $element === $schema->maximum) {
$this->addError($path, "must have a maximum value less than boundary value of " . $schema->maximum);
} else if ($element > $schema->maximum) {
} elseif ($element > $schema->maximum) {
$this->addError($path, "must have a maximum value of " . $schema->maximum);
}
} else {
$this->addError($path, "use of exclusiveMaximum requires presence of maximum");
}
} else if (isset($schema->maximum) && $element > $schema->maximum) {
} elseif (isset($schema->maximum) && $element > $schema->maximum) {
$this->addError($path, "must have a maximum value of " . $schema->maximum);
}

Expand Down
5 changes: 2 additions & 3 deletions src/JsonSchema/Constraints/ObjectConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ObjectConstraint extends Constraint
/**
* {@inheritDoc}
*/
function check($element, $definition = null, $path = null, $additionalProp = null, $patternProperties = null)
public function check($element, $definition = null, $path = null, $additionalProp = null, $patternProperties = null)
{
if ($element instanceof UndefinedConstraint) {
return;
Expand Down Expand Up @@ -71,7 +71,6 @@ public function validatePatternProperties($element, $path, $patternProperties)
public function validateElement($element, $matches, $objectDefinition = null, $path = null, $additionalProp = null)
{
foreach ($element as $i => $value) {

$property = $this->getProperty($element, $i, new UndefinedConstraint());
$definition = $this->getProperty($objectDefinition, $i);

Expand Down Expand Up @@ -137,4 +136,4 @@ protected function getProperty($element, $property, $fallback = null)

return $fallback;
}
}
}
2 changes: 1 addition & 1 deletion src/JsonSchema/Constraints/SchemaConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ public function check($element, $schema = null, $path = null, $i = null)
throw new InvalidArgumentException('no schema found to verify against');
}
}
}
}
8 changes: 4 additions & 4 deletions src/JsonSchema/Constraints/TypeConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ class TypeConstraint extends Constraint
/**
* @var array|string[] type wordings for validation error messages
*/
static $wording = array(
public static $wording = array(
'integer' => 'an integer',
'number' => 'a number',
'boolean' => 'a boolean',
'object' => 'an object',
'array' => 'an array',
'string' => 'a string',
'null' => 'a null',
'any' => NULL, // validation of 'any' is always true so is not needed in message wording
0 => NULL, // validation of a false-y value is always true, so not needed as well
'any' => null, // validation of 'any' is always true so is not needed in message wording
0 => null, // validation of a false-y value is always true, so not needed as well
);

/**
Expand Down Expand Up @@ -136,4 +136,4 @@ protected function validateType($value, $type)

throw new InvalidArgumentException((is_object($value) ? 'object' : $value) . ' is an invalid type for ' . $type);
}
}
}
13 changes: 6 additions & 7 deletions src/JsonSchema/Constraints/UndefinedConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,16 @@ protected function validateCommonProperties($value, $schema = null, $path = null

// Verify required values
if (is_object($value)) {

if (!($value instanceof UndefinedConstraint) && isset($schema->required) && is_array($schema->required) ) {
if (!($value instanceof UndefinedConstraint) && isset($schema->required) && is_array($schema->required)) {
// Draft 4 - Required is an array of strings - e.g. "required": ["foo", ...]
foreach ($schema->required as $required) {
if (!property_exists($value, $required)) {
$this->addError($path, "the property " . $required . " is required");
}
}
} else if (isset($schema->required) && !is_array($schema->required)) {
} elseif (isset($schema->required) && !is_array($schema->required)) {
// Draft 3 - Required attribute - e.g. "foo": {"type": "string", "required": true}
if ( $schema->required && $value instanceof UndefinedConstraint) {
if ($schema->required && $value instanceof UndefinedConstraint) {
$this->addError($path, "is missing and it is required");
}
}
Expand Down Expand Up @@ -249,7 +248,7 @@ protected function validateOfProperties($value, $schema, $path, $i = "")
array(array(
'property' => $path,
'message' => "failed to match exactly one schema"
),),
), ),
$startErrors
)
);
Expand All @@ -276,14 +275,14 @@ protected function validateDependencies($value, $dependencies, $path, $i = "")
if (!property_exists($value, $dependency)) {
$this->addError($path, "$key depends on $dependency and $dependency is missing");
}
} else if (is_array($dependency)) {
} elseif (is_array($dependency)) {
// Draft 4 must be an array - e.g. "dependencies": {"bar": ["foo"]}
foreach ($dependency as $d) {
if (!property_exists($value, $d)) {
$this->addError($path, "$key depends on $d and $d is missing");
}
}
} else if (is_object($dependency)) {
} elseif (is_object($dependency)) {
// Schema - e.g. "dependencies": {"bar": {"properties": {"foo": {...}}}}
$this->checkUndefined($value, $dependency, $path, $i);
}
Expand Down
2 changes: 1 addition & 1 deletion src/JsonSchema/Exception/InvalidArgumentException.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
*/
class InvalidArgumentException extends \InvalidArgumentException
{
}
}
4 changes: 2 additions & 2 deletions src/JsonSchema/Exception/InvalidSchemaMediaTypeException.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
* Wrapper for the InvalidSchemaMediaType
*/
class InvalidSchemaMediaTypeException extends \RuntimeException
{
}
{
}
2 changes: 1 addition & 1 deletion src/JsonSchema/Exception/JsonDecodingException.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ public function __construct($code = JSON_ERROR_NONE, \Exception $previous = null
}
parent::__construct($message, $code, $previous);
}
}
}
2 changes: 1 addition & 1 deletion src/JsonSchema/Exception/ResourceNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
*/
class ResourceNotFoundException extends \RuntimeException
{
}
}
2 changes: 1 addition & 1 deletion src/JsonSchema/Exception/UriResolverException.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
*/
class UriResolverException extends \RuntimeException
{
}
}
2 changes: 1 addition & 1 deletion src/JsonSchema/Uri/Retrievers/Curl.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,4 @@ protected function fetchContentType($response)

return false;
}
}
}
4 changes: 2 additions & 2 deletions src/JsonSchema/Uri/Retrievers/FileGetContents.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

/**
* Tries to retrieve JSON schemas from a URI using file_get_contents()
*
* @author Sander Coolen <[email protected]>
*
* @author Sander Coolen <[email protected]>
*/
class FileGetContents extends AbstractRetriever
{
Expand Down
2 changes: 1 addition & 1 deletion src/JsonSchema/Uri/Retrievers/PredefinedArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ public function retrieve($uri)

return $this->schemas[$uri];
}
}
}
6 changes: 3 additions & 3 deletions src/JsonSchema/Uri/Retrievers/UriRetrieverInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

/**
* Interface for URI retrievers
*
* @author Sander Coolen <[email protected]>
*
* @author Sander Coolen <[email protected]>
*/
interface UriRetrieverInterface
{
Expand All @@ -29,4 +29,4 @@ public function retrieve($uri);
* @return string
*/
public function getContentType();
}
}
20 changes: 10 additions & 10 deletions src/JsonSchema/Uri/UriResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@

/**
* Resolves JSON Schema URIs
*
* @author Sander Coolen <[email protected]>
*
* @author Sander Coolen <[email protected]>
*/
class UriResolver
{
/**
* Parses a URI into five main components
*
*
* @param string $uri
* @return array
* @return array
*/
public function parse($uri)
{
Expand All @@ -35,7 +35,7 @@ public function parse($uri)
'authority' => $match[4],
'path' => $match[5]
);
}
}
if (7 < count($match)) {
$components['query'] = $match[7];
}
Expand All @@ -48,13 +48,13 @@ public function parse($uri)

/**
* Builds a URI based on n array with the main components
*
*
* @param array $components
* @return string
* @return string
*/
public function generate(array $components)
{
$uri = $components['scheme'] . '://'
$uri = $components['scheme'] . '://'
. $components['authority']
. $components['path'];

Expand All @@ -70,7 +70,7 @@ public function generate(array $components)

/**
* Resolves a URI
*
*
* @param string $uri Absolute or relative
* @param string $baseUri Optional base URI
* @return string Absolute URI
Expand Down Expand Up @@ -146,7 +146,7 @@ private static function normalizePath($path)

/**
* @param string $uri
* @return boolean
* @return boolean
*/
public function isValid($uri)
{
Expand Down
2 changes: 0 additions & 2 deletions src/JsonSchema/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@

use JsonSchema\Constraints\SchemaConstraint;
use JsonSchema\Constraints\Constraint;

use JsonSchema\Exception\InvalidSchemaMediaTypeException;
use JsonSchema\Exception\JsonDecodingException;

use JsonSchema\Uri\Retrievers\UriRetrieverInterface;

/**
Expand Down
Loading