Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
PwnedPasswordEntity
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
3 / 3
3
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 toArray
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
 toJson
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace Icawebdesign\Hibp\Password;
6
7use Icawebdesign\Hibp\Interfaces\Arrayable;
8use Icawebdesign\Hibp\Interfaces\Jsonable;
9
10use function get_object_vars;
11
12use const JSON_THROW_ON_ERROR;
13
14readonly class PwnedPasswordEntity implements Arrayable, Jsonable
15{
16    public function __construct(
17        public string $hashSnippet,
18        public int $count,
19        public bool $matched,
20    ) {}
21
22    /**
23     * @return array<string, mixed>
24     */
25    public function toArray(): array
26    {
27        return [
28            'hash_snippet' => $this->hashSnippet,
29            'count' => $this->count,
30            'matched' => $this->matched,
31        ];
32    }
33
34    public function toJson(): string
35    {
36        return json_encode(get_object_vars($this), flags: JSON_THROW_ON_ERROR | JSON_UNESCAPED_SLASHES);
37    }
38}