Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
7 / 7 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| BreachSiteTruncatedEntity | |
100.00% |
7 / 7 |
|
100.00% |
3 / 3 |
4 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| toArray | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| toJson | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Icawebdesign\Hibp\Breach; |
| 6 | |
| 7 | use Icawebdesign\Hibp\Interfaces\Arrayable; |
| 8 | use Icawebdesign\Hibp\Interfaces\Jsonable; |
| 9 | use RuntimeException; |
| 10 | use stdClass; |
| 11 | |
| 12 | use function get_object_vars; |
| 13 | |
| 14 | use const JSON_THROW_ON_ERROR; |
| 15 | |
| 16 | readonly class BreachSiteTruncatedEntity implements Arrayable, Jsonable |
| 17 | { |
| 18 | public string $name; |
| 19 | |
| 20 | public function __construct(?stdClass $data = null) |
| 21 | { |
| 22 | if (null === $data) { |
| 23 | throw new RuntimeException('Invalid BreachSite data'); |
| 24 | } |
| 25 | |
| 26 | $this->name = $data->Name; |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * @return array<string, string> |
| 31 | */ |
| 32 | public function toArray(): array |
| 33 | { |
| 34 | return [ |
| 35 | 'name' => $this->name, |
| 36 | ]; |
| 37 | } |
| 38 | |
| 39 | public function toJson(): string |
| 40 | { |
| 41 | return json_encode(get_object_vars($this), flags: JSON_THROW_ON_ERROR | JSON_UNESCAPED_SLASHES); |
| 42 | } |
| 43 | } |