Passed
Push — master ( ad9ec3...91c3c2 )
by Lawrence
01:30
created

Checker   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
dl 0
loc 47
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A whoisServers() 0 3 1
A availability() 0 21 3
1
<?php
2
/*
3
 +-----------------------------------------------------------------------------+
4
 | PHPPackage - Domain Checker
5
 +-----------------------------------------------------------------------------+
6
 | Copyright (c)2018 (http://github.com/phppackage/domaincheck)
7
 +-----------------------------------------------------------------------------+
8
 | This source file is subject to MIT License
9
 | that is bundled with this package in the file LICENSE.
10
 |
11
 | If you did not receive a copy of the license and are unable to
12
 | obtain it through the world-wide-web, please send an email
13
 | to [email protected] so we can send you a copy immediately.
14
 +-----------------------------------------------------------------------------+
15
 | Authors:
16
 |   Lawrence Cherone <[email protected]>
17
 +-----------------------------------------------------------------------------+
18
 */
19
20
namespace PHPPackage\DomainCheck;
21
22
class Checker
23
{
24
    /**
25
     * @var
26
     */
27
    private $tlds = [];
28
29
    /**
30
     *
31
     */
32 9
    public function __construct(array $tlds = [])
33
    {
34 9
        $this->tlds = $tlds;
35 9
    }
36
    
37
    /**
38
     *
39
     */
40 5
    public function whoisServers(array $tlds = [], string $servers_file = 'whois-servers.json')
41
    {
42 5
        return (new Whois($this->tlds))->servers($tlds, $servers_file);
43
    }
44
45
    /**
46
     *
47
     */
48 2
    public function availability($name)
49
    {
50 2
        $whois = new Whois();
51
        
52 2
        $result = [];
53 2
        $result[$name] = [];
54 2
        foreach ($whois->servers($this->tlds) as $server) {
55 2
            if ($whois->checkDomain(
56 2
                trim($name).'.',
57 2
                $server['server'],
58 2
                $server['pattern']['available']
59
            )) {
60
                // domain is available
61 1
                $result[$name][$server['tld']] = true;
62
            } else {
63
                // domain is registered
64 2
                $result[$name][$server['tld']] = false;
65
            }
66
        }
67
        
68 2
        return $result;
69
    }
70
}
71