| Total Complexity | 5 |
| Total Lines | 44 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 15 | class PwnedPasswords extends Pwned |
||
| 16 | { |
||
| 17 | private $password; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * PwnedPasswords constructor. |
||
| 21 | */ |
||
| 22 | public function __construct() |
||
| 23 | { |
||
| 24 | parent::__construct(); |
||
| 25 | } |
||
| 26 | |||
| 27 | /** |
||
| 28 | * This function gets all pawned passwords. |
||
| 29 | * |
||
| 30 | * @return array |
||
| 31 | */ |
||
| 32 | public function get(): array |
||
| 33 | { |
||
| 34 | // No password has been set, return empty array. |
||
| 35 | if (!isset($this->password)) return []; |
||
| 36 | |||
| 37 | $url = $this->endpoint . 'pwnedpassword/' . $this->password; |
||
| 38 | $pwnedPasswords = $this->requestGet($url); |
||
| 39 | |||
| 40 | if (empty($pwnedPasswords)) { |
||
| 41 | return [ |
||
| 42 | 'code' => 200, |
||
| 43 | 'message' =>'Oh no — pwned! This password has previously appeared in a data breach and should never be used. If you\'ve ever used it anywhere before, change it immediately!' |
||
| 44 | ]; |
||
| 45 | } |
||
| 46 | return $pwnedPasswords; |
||
| 47 | } |
||
| 48 | |||
| 49 | /** |
||
| 50 | * Sets the password. |
||
| 51 | * |
||
| 52 | * @param string $password |
||
| 53 | * @return $this |
||
| 54 | */ |
||
| 55 | public function setPassword(string $password) |
||
| 59 | } |
||
| 60 | } |