Conditions | 5 |
Paths | 4 |
Total Lines | 23 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
13 | public static function validate( |
||
14 | \stdClass $std, |
||
15 | string $jsonschema, |
||
16 | string $definitions |
||
17 | ) { |
||
18 | if (!is_file($jsonschema) || !is_file($definitions)) { |
||
19 | return []; |
||
20 | } |
||
21 | $jsonSchemaObject = json_decode((string)file_get_contents($jsonschema)); |
||
22 | $schemaStorage = new SchemaStorage(); |
||
23 | $schemaStorage->addSchema("file:{$definitions}", $jsonSchemaObject); |
||
24 | $jsonValidator = new Validator(new Factory($schemaStorage)); |
||
25 | $jsonValidator->validate($std, $jsonSchemaObject, Constraint::CHECK_MODE_COERCE_TYPES); |
||
26 | if ($jsonValidator->isValid()) { |
||
27 | return []; |
||
28 | } |
||
29 | $resp = []; |
||
30 | foreach ($jsonValidator->getErrors() as $error) { |
||
31 | $error['message'] = TranslateJsonValidation::translate($error['message']); |
||
32 | $resp[] = $error; |
||
33 | } |
||
34 | return $resp; |
||
35 | } |
||
36 | } |
||
37 |
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: