Breaches   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 42
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setDomain() 0 4 1
A get() 0 14 2
A __construct() 0 3 1
1
<?php
2
3
namespace Ridvanbaluyos\Pwned;
4
5
use \Ridvanbaluyos\Pwned\Pwned as Pwned;
6
/**
7
 * Getting all breached sites in the system
8
 * https://haveibeenpwned.com/API/v2#AllBreaches
9
 *
10
 * @package    Pwned
11
 * @author     Ridvan Baluyos <[email protected]>
12
 * @link       https://github.com/ridvanbaluyos/haveibeenpwned
13
 * @license    MIT
14
 */
15
class Breaches extends Pwned
16
{
17
    private $domain;
18
19
    /**
20
     * Breaches constructor.
21
     */
22
    public function __construct()
23
    {
24
        parent::__construct();
25
    }
26
27
    /**
28
     * This function gets all breaches.
29
     * @return array
30
     */
31
    public function get(): array
32
    {
33
        $filters = [];
34
        $url = $this->endpoint . 'breaches/';
35
36
        // Filter domain, if available.
37
        if (isset($this->domain)) {
38
            $filters['domain'] = $this->domain;
39
        }
40
41
        $url = $this->setFilters($url, $filters);
42
        $breaches = $this->requestGet($url);
43
44
        return $breaches;
45
    }
46
47
    /**
48
     * Sets the domain filter. Filter the results only to the domain specified.
49
     *
50
     * @param string $domain
51
     * @return $this
52
     */
53
    public function setDomain(string $domain)
54
    {
55
        $this->domain = $domain;
56
        return $this;
57
    }
58
}