Skip to content

Commit f3bb1ab

Browse files
committed
Follow PSR2 rules
1 parent 34e2982 commit f3bb1ab

29 files changed

+72
-74
lines changed

src/JsonSchema/Constraints/CollectionConstraint.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function check($value, $schema = null, $path = null, $i = null)
3636
if (isset($schema->uniqueItems)) {
3737
$unique = $value;
3838
if (is_array($value) && count($value)) {
39-
$unique = array_map(function($e) { return var_export($e, true); }, $value);
39+
$unique = array_map(function ($e) { return var_export($e, true); }, $value);
4040
}
4141
if (count(array_unique($unique)) != count($value)) {
4242
$this->addError($path, "There are no duplicates allowed in the array");
@@ -76,7 +76,7 @@ protected function validateItems($value, $schema = null, $path = null, $i = null
7676
// Reset errors if needed
7777
if (isset($secondErrors) && count($secondErrors) < count($this->getErrors())) {
7878
$this->errors = $secondErrors;
79-
} else if (isset($secondErrors) && count($secondErrors) === count($this->getErrors())) {
79+
} elseif (isset($secondErrors) && count($secondErrors) === count($this->getErrors())) {
8080
$this->errors = $initErrors;
8181
}
8282
}
@@ -102,11 +102,11 @@ protected function validateItems($value, $schema = null, $path = null, $i = null
102102
}
103103

104104
// Treat when we have more schema definitions than values, not for empty arrays
105-
if(count($value) > 0) {
105+
if (count($value) > 0) {
106106
for ($k = count($value); $k < count($schema->items); $k++) {
107107
$this->checkUndefined(new UndefinedConstraint(), $schema->items[$k], $path, $k);
108108
}
109109
}
110110
}
111111
}
112-
}
112+
}

src/JsonSchema/Constraints/Constraint.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ public function __construct($checkMode = self::CHECK_MODE_NORMAL, UriRetriever $
4242
*/
4343
public function getUriRetriever()
4444
{
45-
if (is_null($this->uriRetriever))
46-
{
45+
if (is_null($this->uriRetriever)) {
4746
$this->setUriRetriever(new UriRetriever);
4847
}
4948

src/JsonSchema/Constraints/ConstraintInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,4 @@ public function isValid();
5555
* @param mixed $i
5656
*/
5757
public function check($value, $schema = null, $path = null, $i = null);
58-
}
58+
}

src/JsonSchema/Constraints/EnumConstraint.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,13 @@ public function check($element, $schema = null, $path = null, $i = null)
3131
$type = gettype($element);
3232
if ($type === gettype($enum)) {
3333
if ($type == "object") {
34-
if ($element == $enum)
34+
if ($element == $enum) {
3535
return;
36+
}
3637
} else {
37-
if ($element === $enum)
38+
if ($element === $enum) {
3839
return;
39-
40+
}
4041
}
4142
}
4243
}

src/JsonSchema/Constraints/NumberConstraint.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ public function check($element, $schema = null, $path = null, $i = null)
2727
if (isset($schema->minimum)) {
2828
if ($schema->exclusiveMinimum && $element === $schema->minimum) {
2929
$this->addError($path, "must have a minimum value greater than boundary value of " . $schema->minimum);
30-
} else if ($element < $schema->minimum) {
30+
} elseif ($element < $schema->minimum) {
3131
$this->addError($path, "must have a minimum value of " . $schema->minimum);
3232
}
3333
} else {
3434
$this->addError($path, "use of exclusiveMinimum requires presence of minimum");
3535
}
36-
} else if (isset($schema->minimum) && $element < $schema->minimum) {
36+
} elseif (isset($schema->minimum) && $element < $schema->minimum) {
3737
$this->addError($path, "must have a minimum value of " . $schema->minimum);
3838
}
3939

@@ -42,13 +42,13 @@ public function check($element, $schema = null, $path = null, $i = null)
4242
if (isset($schema->maximum)) {
4343
if ($schema->exclusiveMaximum && $element === $schema->maximum) {
4444
$this->addError($path, "must have a maximum value less than boundary value of " . $schema->maximum);
45-
} else if ($element > $schema->maximum) {
45+
} elseif ($element > $schema->maximum) {
4646
$this->addError($path, "must have a maximum value of " . $schema->maximum);
4747
}
4848
} else {
4949
$this->addError($path, "use of exclusiveMaximum requires presence of maximum");
5050
}
51-
} else if (isset($schema->maximum) && $element > $schema->maximum) {
51+
} elseif (isset($schema->maximum) && $element > $schema->maximum) {
5252
$this->addError($path, "must have a maximum value of " . $schema->maximum);
5353
}
5454

src/JsonSchema/Constraints/ObjectConstraint.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class ObjectConstraint extends Constraint
2020
/**
2121
* {@inheritDoc}
2222
*/
23-
function check($element, $definition = null, $path = null, $additionalProp = null, $patternProperties = null)
23+
public function check($element, $definition = null, $path = null, $additionalProp = null, $patternProperties = null)
2424
{
2525
if ($element instanceof UndefinedConstraint) {
2626
return;
@@ -71,7 +71,6 @@ public function validatePatternProperties($element, $path, $patternProperties)
7171
public function validateElement($element, $matches, $objectDefinition = null, $path = null, $additionalProp = null)
7272
{
7373
foreach ($element as $i => $value) {
74-
7574
$property = $this->getProperty($element, $i, new UndefinedConstraint());
7675
$definition = $this->getProperty($objectDefinition, $i);
7776

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

138137
return $fallback;
139138
}
140-
}
139+
}

src/JsonSchema/Constraints/SchemaConstraint.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ public function check($element, $schema = null, $path = null, $i = null)
3434
throw new InvalidArgumentException('no schema found to verify against');
3535
}
3636
}
37-
}
37+
}

src/JsonSchema/Constraints/TypeConstraint.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@ class TypeConstraint extends Constraint
2323
/**
2424
* @var array|string[] type wordings for validation error messages
2525
*/
26-
static $wording = array(
26+
public static $wording = array(
2727
'integer' => 'an integer',
2828
'number' => 'a number',
2929
'boolean' => 'a boolean',
3030
'object' => 'an object',
3131
'array' => 'an array',
3232
'string' => 'a string',
3333
'null' => 'a null',
34-
'any' => NULL, // validation of 'any' is always true so is not needed in message wording
35-
0 => NULL, // validation of a false-y value is always true, so not needed as well
34+
'any' => null, // validation of 'any' is always true so is not needed in message wording
35+
0 => null, // validation of a false-y value is always true, so not needed as well
3636
);
3737

3838
/**
@@ -136,4 +136,4 @@ protected function validateType($value, $type)
136136

137137
throw new InvalidArgumentException((is_object($value) ? 'object' : $value) . ' is an invalid type for ' . $type);
138138
}
139-
}
139+
}

src/JsonSchema/Constraints/UndefinedConstraint.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,17 +117,16 @@ protected function validateCommonProperties($value, $schema = null, $path = null
117117

118118
// Verify required values
119119
if (is_object($value)) {
120-
121-
if (!($value instanceof UndefinedConstraint) && isset($schema->required) && is_array($schema->required) ) {
120+
if (!($value instanceof UndefinedConstraint) && isset($schema->required) && is_array($schema->required)) {
122121
// Draft 4 - Required is an array of strings - e.g. "required": ["foo", ...]
123122
foreach ($schema->required as $required) {
124123
if (!property_exists($value, $required)) {
125124
$this->addError($path, "the property " . $required . " is required");
126125
}
127126
}
128-
} else if (isset($schema->required) && !is_array($schema->required)) {
127+
} elseif (isset($schema->required) && !is_array($schema->required)) {
129128
// Draft 3 - Required attribute - e.g. "foo": {"type": "string", "required": true}
130-
if ( $schema->required && $value instanceof UndefinedConstraint) {
129+
if ($schema->required && $value instanceof UndefinedConstraint) {
131130
$this->addError($path, "is missing and it is required");
132131
}
133132
}
@@ -249,7 +248,7 @@ protected function validateOfProperties($value, $schema, $path, $i = "")
249248
array(array(
250249
'property' => $path,
251250
'message' => "failed to match exactly one schema"
252-
),),
251+
), ),
253252
$startErrors
254253
)
255254
);
@@ -276,14 +275,14 @@ protected function validateDependencies($value, $dependencies, $path, $i = "")
276275
if (!property_exists($value, $dependency)) {
277276
$this->addError($path, "$key depends on $dependency and $dependency is missing");
278277
}
279-
} else if (is_array($dependency)) {
278+
} elseif (is_array($dependency)) {
280279
// Draft 4 must be an array - e.g. "dependencies": {"bar": ["foo"]}
281280
foreach ($dependency as $d) {
282281
if (!property_exists($value, $d)) {
283282
$this->addError($path, "$key depends on $d and $d is missing");
284283
}
285284
}
286-
} else if (is_object($dependency)) {
285+
} elseif (is_object($dependency)) {
287286
// Schema - e.g. "dependencies": {"bar": {"properties": {"foo": {...}}}}
288287
$this->checkUndefined($value, $dependency, $path, $i);
289288
}

src/JsonSchema/Exception/InvalidArgumentException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414
*/
1515
class InvalidArgumentException extends \InvalidArgumentException
1616
{
17-
}
17+
}

src/JsonSchema/Exception/InvalidSchemaMediaTypeException.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@
1313
* Wrapper for the InvalidSchemaMediaType
1414
*/
1515
class InvalidSchemaMediaTypeException extends \RuntimeException
16-
{
17-
}
16+
{
17+
}

src/JsonSchema/Exception/JsonDecodingException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ public function __construct($code = JSON_ERROR_NONE, \Exception $previous = null
3737
}
3838
parent::__construct($message, $code, $previous);
3939
}
40-
}
40+
}

src/JsonSchema/Exception/ResourceNotFoundException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414
*/
1515
class ResourceNotFoundException extends \RuntimeException
1616
{
17-
}
17+
}

src/JsonSchema/Exception/UriResolverException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414
*/
1515
class UriResolverException extends \RuntimeException
1616
{
17-
}
17+
}

src/JsonSchema/Uri/Retrievers/Curl.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,4 @@ protected function fetchContentType($response)
7676

7777
return false;
7878
}
79-
}
79+
}

src/JsonSchema/Uri/Retrievers/FileGetContents.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
/**
1616
* Tries to retrieve JSON schemas from a URI using file_get_contents()
17-
*
18-
* @author Sander Coolen <[email protected]>
17+
*
18+
* @author Sander Coolen <[email protected]>
1919
*/
2020
class FileGetContents extends AbstractRetriever
2121
{

src/JsonSchema/Uri/Retrievers/PredefinedArray.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,4 @@ public function retrieve($uri)
5252

5353
return $this->schemas[$uri];
5454
}
55-
}
55+
}

src/JsonSchema/Uri/Retrievers/UriRetrieverInterface.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
/**
1313
* Interface for URI retrievers
14-
*
15-
* @author Sander Coolen <[email protected]>
14+
*
15+
* @author Sander Coolen <[email protected]>
1616
*/
1717
interface UriRetrieverInterface
1818
{
@@ -29,4 +29,4 @@ public function retrieve($uri);
2929
* @return string
3030
*/
3131
public function getContentType();
32-
}
32+
}

src/JsonSchema/Uri/UriResolver.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@
1313

1414
/**
1515
* Resolves JSON Schema URIs
16-
*
17-
* @author Sander Coolen <[email protected]>
16+
*
17+
* @author Sander Coolen <[email protected]>
1818
*/
1919
class UriResolver
2020
{
2121
/**
2222
* Parses a URI into five main components
23-
*
23+
*
2424
* @param string $uri
25-
* @return array
25+
* @return array
2626
*/
2727
public function parse($uri)
2828
{
@@ -35,7 +35,7 @@ public function parse($uri)
3535
'authority' => $match[4],
3636
'path' => $match[5]
3737
);
38-
}
38+
}
3939
if (7 < count($match)) {
4040
$components['query'] = $match[7];
4141
}
@@ -48,13 +48,13 @@ public function parse($uri)
4848

4949
/**
5050
* Builds a URI based on n array with the main components
51-
*
51+
*
5252
* @param array $components
53-
* @return string
53+
* @return string
5454
*/
5555
public function generate(array $components)
5656
{
57-
$uri = $components['scheme'] . '://'
57+
$uri = $components['scheme'] . '://'
5858
. $components['authority']
5959
. $components['path'];
6060

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

7171
/**
7272
* Resolves a URI
73-
*
73+
*
7474
* @param string $uri Absolute or relative
7575
* @param string $baseUri Optional base URI
7676
* @return string Absolute URI
@@ -146,7 +146,7 @@ private static function normalizePath($path)
146146

147147
/**
148148
* @param string $uri
149-
* @return boolean
149+
* @return boolean
150150
*/
151151
public function isValid($uri)
152152
{

src/JsonSchema/Validator.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@
1111

1212
use JsonSchema\Constraints\SchemaConstraint;
1313
use JsonSchema\Constraints\Constraint;
14-
1514
use JsonSchema\Exception\InvalidSchemaMediaTypeException;
1615
use JsonSchema\Exception\JsonDecodingException;
17-
1816
use JsonSchema\Uri\Retrievers\UriRetrieverInterface;
1917

2018
/**

tests/JsonSchema/Tests/Constraints/BaseTestCase.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function testInvalidCases($input, $schema, $checkMode = Validator::CHECK_
2323
$validator->check(json_decode($input), json_decode($schema));
2424

2525
if (array() !== $errors) {
26-
$this->assertEquals($errors, $validator->getErrors(), print_r($validator->getErrors(),true));
26+
$this->assertEquals($errors, $validator->getErrors(), print_r($validator->getErrors(), true));
2727
}
2828
$this->assertFalse($validator->isValid(), print_r($validator->getErrors(), true));
2929
}
@@ -42,4 +42,4 @@ public function testValidCases($input, $schema, $checkMode = Validator::CHECK_MO
4242
abstract public function getValidTests();
4343

4444
abstract public function getInvalidTests();
45-
}
45+
}

tests/JsonSchema/Tests/Constraints/DependenciesTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,4 @@ public function getValidTests()
145145
)
146146
);
147147
}
148-
}
148+
}

tests/JsonSchema/Tests/Constraints/PatternPropertiesTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,3 @@ public function getValidTests()
125125
);
126126
}
127127
}
128-

0 commit comments

Comments
 (0)