EmailVerifier::make()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.8333
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
namespace Messerli90\Hunterio;
4
5
use Illuminate\Support\Facades\Http;
6
use Messerli90\Hunterio\Exceptions\AuthorizationException;
7
use Messerli90\Hunterio\Exceptions\InvalidRequestException;
8
use Messerli90\Hunterio\Exceptions\UsageException;
9
use Messerli90\Hunterio\Interfaces\EndpointInterface;
10
11
class EmailVerifier extends HunterClient
12
{
13
    /**
14
     * The email address you want to verify.
15
     *
16
     * @var string
17
     */
18
    public $email;
19
20
    public function __construct(string $api_key = null)
21
    {
22
        parent::__construct($api_key);
23
24
        $this->endpoint = 'email-verifier';
25
    }
26
27
    /**
28
     * Sets email to search
29
     *
30
     * @param string $email
31
     * @return EmailVerifier
32
     */
33
    public function email(string $email): self
34
    {
35
        $this->email = $email;
36
37
        return $this;
38
    }
39
40
    /**
41
     * Shortcut to set email and make request
42
     *
43
     * @param string $email
44
     * @return mixed
45
     * @throws InvalidRequestException
46
     * @throws AuthorizationException
47
     * @throws UsageException
48
     */
49
    public function verify(string $email)
50
    {
51
        $this->email($email)->make();
52
        return $this->get();
53
    }
54
55
    public function make()
56
    {
57
        if (empty($this->email)) {
58
            throw new InvalidRequestException('Email is required.');
59
        }
60
61
        $this->query_params = [
62
            'email' => $this->email ?? null,
63
            'api_key' => $this->api_key ?? null
64
        ];
65
66
        return $this->query_params;
67
    }
68
}
69