Breach   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 100 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 3 3 1
A setDomain() 4 4 1
A get() 9 9 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Ridvanbaluyos\Pwned;
4
5
use \Ridvanbaluyos\Pwned\Pwned as Pwned;
6
/**
7
 * Getting a single breached site
8
 * https://haveibeenpwned.com/API/v2#SingleBreach
9
 *
10
 * @package    Pwned
11
 * @author     Ridvan Baluyos <[email protected]>
12
 * @link       https://github.com/ridvanbaluyos/haveibeenpwned
13
 * @license    MIT
14
 */
15 View Code Duplication
class Breach extends Pwned
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
16
{
17
    /**
18
     * Breaches constructor.
19
     */
20
    public function __construct()
21
    {
22
        parent::__construct();
23
    }
24
25
    /**
26
     * This function gets a specific breach.
27
     *
28
     * @return array
29
     */
30
    public function get(): array
31
    {
32
        // No domain has been set, return empty array.
33
        if (!isset($this->domain)) return [];
34
35
        $url = $this->endpoint . 'breach/' . $this->domain;
36
        $breaches = $this->requestGet($url);
37
38
        return $breaches;
39
    }
40
41
    /**
42
     * Sets the domain filter. Filter the results only to the domain specified.
43
     *
44
     * @param string $domain
45
     * @return $this
46
     */
47
    public function setDomain(string $domain)
48
    {
49
        $this->domain = $domain;
0 ignored issues
show
Bug Best Practice introduced by
The property domain does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
50
        return $this;
51
    }
52
}