Passed
Branch master (9edd41)
by Lawrence
01:29
created

Checker::filterServers()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 6
cts 6
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 2
crap 2
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[$name] = [];
0 ignored issues
show
Comprehensibility Best Practice introduced by
$result was never initialized. Although not strictly required by PHP, it is generally a good practice to add $result = array(); before regardless.
Loading history...
53 2
        foreach ($whois->servers($this->tlds) as $server) {
54
            //query whois and check domain
55
            if (
56 2
                $whois->checkDomain(
57 2
                    trim($name).".",
58 2
                    $server['server'],
59 2
                    $server['pattern']['available']
60
                )
61
            ) {
62
                // domain is available
63 1
                $result[$name][$server['tld']] = true;
64
            } else {
65
                // domain is registered
66 2
                $result[$name][$server['tld']] = false;
67
            }
68
        }
69
        
70 2
        return $result;
71
    }
72
}
73