DisponsableChecker   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
dl 0
loc 58
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A isEnable() 0 3 1
A isDisponsable() 0 15 4
1
<?php
2
3
/*
4
 * This file is part of EmailChecker.
5
 *
6
 * (c) Corrado Ronci <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace sorciulus\EmailChecker;
13
14
use GuzzleHttp\Client;
15
use GuzzleHttp\Exception\TransferException;
16
use GuzzleHttp\Exception\ClientException;
17
use GuzzleHttp\Exception\RequestException;
18
use GuzzleHttp\Exception\ServerException;
19
use sorciulus\EmailChecker\Exception\DisponsableException;
20
/**
21
* Class to check if email is disponsable
22
* through https://open.kickbox.io API
23
*/
24
class DisponsableChecker
25
{
26
	/**
27
	 * Client HTTP
28
	 * 
29
	 * @var GuzzleHttp\Client
0 ignored issues
show
Bug introduced by
The type sorciulus\EmailChecker\GuzzleHttp\Client was not found. Did you mean GuzzleHttp\Client? If so, make sure to prefix the type with \.
Loading history...
30
	 */
31
	private $client;
32
33
	/**
34
	 *	This setting allows you to disable 
35
	 *	disponsable email checker. If FALSE
36
	 *	the function isDisponsable return NULL
37
	 * 
38
	 * @var boolean
39
	 */
40
	private $enable = TRUE;
41
42
	public function __construct()
43
	{
44
		$this->client = new Client([		    
0 ignored issues
show
Documentation Bug introduced by
It seems like new GuzzleHttp\Client(ar...io', 'timeout' => 2.0)) of type GuzzleHttp\Client is incompatible with the declared type sorciulus\EmailChecker\GuzzleHttp\Client of property $client.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
45
		    "base_uri" => "https://open.kickbox.io",		    
46
		    "timeout"  => 2.0,
47
		]);
48
	}	
49
50
	/**
51
    * Check if service is enabled
52
    *
53
    * @return boolean
54
    */
55
    public function isEnable()
56
    {
57
        return $this->enable;
58
    }
59
60
	/**
61
	 * Call Kickbox API and return the value
62
	 * 
63
	 * @param  string $domain
64
	 * @return boolean 
65
	 * @throws DisponsableException
66
	 */
67
	public function isDisponsable($domain)
68
	{
69
		if (!$this->enable) {
70
			throw new DisponsableException("DisponsableChecker is disable");
71
		}
72
		try {	
73
			$response = $this->client->get("/v1/disposable/" . $domain);
74
			$body = json_decode((string)$response->getBody());	
75
			if (property_exists($body, "disposable")) {
76
				return $body->disposable;	
77
			} else {
78
				throw new DisponsableException("Disponsable service unknown response"); 
79
			}					
80
		} catch (TransferException $e) {
81
			throw new DisponsableException($e->getMessage());
82
		}
83
		
84
	}
85
}