EmailCount::domain()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Messerli90\Hunterio;
4
5
use Illuminate\Support\Facades\Http;
6
use Messerli90\Hunterio\Exceptions\InvalidRequestException;
7
use Messerli90\Hunterio\Interfaces\EndpointInterface;
8
9
class EmailCount extends HunterClient
10
{
11
    /**
12
     * Domain name from which you want to find the email addresses
13
     *
14
     * @var string
15
     */
16
    public $domain;
17
18
    /**
19
     * The company name from which you want to find the email addresses
20
     *
21
     * @var string
22
     */
23
    public $company;
24
25
    /**
26
     * Specifies the type of email addresses to return
27
     *
28
     * @var string
29
     */
30
    public $type;
31
32
    public function __construct()
33
    {
34
        $this->endpoint = 'email-count';
35
    }
36
37
    /**
38
     * Sets domain to search
39
     *
40
     * @param string $domain
41
     * @return DomainSearch
42
     */
43
    public function domain(string $domain): self
44
    {
45
        $this->domain = $domain;
46
47
        return $this;
48
    }
49
50
    /**
51
     * Set company name to search
52
     *
53
     * @param string $company
54
     * @return DomainSearch
55
     */
56
    public function company(string $company): self
57
    {
58
        $this->company = $company;
59
60
        return $this;
61
    }
62
63
    /**
64
     * Set the type of email addresses to include in search
65
     * A "generic" email address is a role-based email address, like [email protected].
66
     * On the contrary, a "personal" email address is the address of someone in the company.
67
     *
68
     * @param string $type
69
     * @return DomainSearch
70
     */
71 View Code Duplication
    public function type(string $type): self
0 ignored issues
show
Duplication introduced by
This method 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...
72
    {
73
        if (!in_array($type, ['generic', 'personal'])) {
74
            throw new InvalidRequestException('Type must be either "generic" or "personal".');
75
        }
76
        $this->type = $type;
77
78
        return $this;
79
    }
80
81
    public function make()
82
    {
83
        if (empty($this->company) && empty($this->domain)) {
84
            throw new InvalidRequestException('Either Domain or Company fields are required.');
85
        }
86
87
        $this->query_params = [
88
            'company' => $this->company ?? null,
89
            'domain' => $this->domain ?? null,
90
            'type' => $this->type ?? null
91
        ];
92
93
        return $this->query_params;
94
    }
95
}
96