generated from ergebnis/php-package-template
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from ergebnis/feature/json-schema-validator
Enhancement: Import `Json` from `ergebnis/json-schema-validator`
- Loading branch information
Showing
25 changed files
with
457 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,19 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<files psalm-version="5.1.0@4defa177c89397c5e14737a80fe4896584130674"> | ||
<file src="src/Json.php"> | ||
<MixedArgument occurrences="1"> | ||
<MixedArgument occurrences="2"> | ||
<code>$decoded</code> | ||
<code>$decoded</code> | ||
</MixedArgument> | ||
<MixedAssignment occurrences="1"> | ||
<MixedAssignment occurrences="2"> | ||
<code>$decoded</code> | ||
<code>$decoded</code> | ||
</MixedAssignment> | ||
</file> | ||
<file src="test/Unit/JsonTest.php"> | ||
<InvalidArgument occurrences="1"> | ||
<code>testFromEncodedReturnsJson</code> | ||
</InvalidArgument> | ||
<file src="test/DataProvider/JsonProvider.php"> | ||
<MoreSpecificReturnType occurrences="2"> | ||
<code>\Generator<string, array{0: string}></code> | ||
<code>\Generator<string, array{0: string}></code> | ||
</MoreSpecificReturnType> | ||
</file> | ||
</files> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright (c) 2022 Andreas Möller | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE.md file that was distributed with this source code. | ||
* | ||
* @see https://github.com/ergebnis/json | ||
*/ | ||
|
||
namespace Ergebnis\Json\Exception; | ||
|
||
final class FileCanNotBeRead extends \InvalidArgumentException | ||
{ | ||
public static function file(string $name): self | ||
{ | ||
return new self(\sprintf( | ||
'File "%s" can not be read.', | ||
$name, | ||
)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright (c) 2022 Andreas Möller | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE.md file that was distributed with this source code. | ||
* | ||
* @see https://github.com/ergebnis/json | ||
*/ | ||
|
||
namespace Ergebnis\Json\Exception; | ||
|
||
final class FileDoesNotContainJson extends \InvalidArgumentException | ||
{ | ||
public static function file(string $name): self | ||
{ | ||
return new self(\sprintf( | ||
'File "%s" does not contain a valid JSON string.', | ||
$name, | ||
)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright (c) 2022 Andreas Möller | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE.md file that was distributed with this source code. | ||
* | ||
* @see https://github.com/ergebnis/json | ||
*/ | ||
|
||
namespace Ergebnis\Json\Exception; | ||
|
||
final class FileDoesNotExist extends \InvalidArgumentException | ||
{ | ||
public static function file(string $name): self | ||
{ | ||
return new self(\sprintf( | ||
'File "%s" does not exist.', | ||
$name, | ||
)); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright (c) 2022 Andreas Möller | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE.md file that was distributed with this source code. | ||
* | ||
* @see https://github.com/ergebnis/json | ||
*/ | ||
|
||
namespace Ergebnis\Json\Exception; | ||
|
||
final class NotJson extends \InvalidArgumentException implements Exception | ||
{ | ||
public static function value(string $value): self | ||
{ | ||
return new self(\sprintf( | ||
'Value "%s" is not a valid JSON string.', | ||
$value, | ||
)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright (c) 2022 Andreas Möller | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE.md file that was distributed with this source code. | ||
* | ||
* @see https://github.com/ergebnis/json | ||
*/ | ||
|
||
namespace Ergebnis\Json\Test\DataProvider; | ||
|
||
use Ergebnis\DataProvider; | ||
|
||
final class JsonProvider extends DataProvider\AbstractProvider | ||
{ | ||
/** | ||
* @return \Generator<string, array{0: string}> | ||
*/ | ||
public static function validString(): \Generator | ||
{ | ||
yield from self::provideDataForValues(\array_map(static function (string $file): string { | ||
$value = \file_get_contents($file); | ||
|
||
if (!\is_string($value)) { | ||
throw new \RuntimeException(\sprintf( | ||
'File "%s" does not exist or can not be read.', | ||
$file, | ||
)); | ||
} | ||
|
||
return \trim($value); | ||
}, self::filesContainingValidJson())); | ||
} | ||
|
||
/** | ||
* @return \Generator<string, array{0: string}> | ||
*/ | ||
public function validFile(): \Generator | ||
{ | ||
yield from self::provideDataForValues(self::filesContainingValidJson()); | ||
} | ||
|
||
/** | ||
* @return array<string, string> | ||
*/ | ||
private static function filesContainingValidJson(): array | ||
{ | ||
return [ | ||
'array' => __DIR__ . '/../Fixture/Json/valid/array.json', | ||
'bool-false' => __DIR__ . '/../Fixture/Json/valid/bool-false.json', | ||
'bool-true' => __DIR__ . '/../Fixture/Json/valid/bool-true.json', | ||
'float' => __DIR__ . '/../Fixture/Json/valid/float.json', | ||
'int' => __DIR__ . '/../Fixture/Json/valid/int.json', | ||
'object' => __DIR__ . '/../Fixture/Json/valid/object.json', | ||
'string-arbitrary' => __DIR__ . '/../Fixture/Json/valid/string-arbitrary.json', | ||
'string-empty' => __DIR__ . '/../Fixture/Json/valid/string-empty.json', | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{ | ||
"foo": |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[ | ||
"foo", | ||
"bar" | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
3.14 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
9001 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"foo": "bar", | ||
"bar": "baz" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"" |
Oops, something went wrong.