Completed
Push — master ( 6173e8...cd5e7f )
by Daniel
03:05
created

AbstractLocator::getLastMatch()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
namespace MallardDuck\Whois\WhoisServerList;
3
4
/**
5
 * Whois Server List Locator Class
6
 *
7
 * This class loads a TLD whois list and allows for easy look up.
8
 *
9
 * @author mallardduck <[email protected]>
10
 *
11
 * @copyright lucidinternets.com 2018
12
 *
13
 * @version 0.3.0
14
 */
15
abstract class AbstractLocator
16
{
17
18
    /**
19
     * The path where the tld json file exists.
20
     *
21
     * @var string
22
     */
23
    protected $whoisListPath;
24
25
    /**
26
     * A collection of the TLDs and whois server list.
27
     *
28
     * @var \Tightenco\Collect\Support\Collection
29
     */
30
    protected $whoisCollection;
31
32
    /**
33
     * The results of the last looked up domain.
34
     *
35
     * @var array
36
     */
37
    protected $lastMatch;
38
39
    /**
40
     * Build the TLD Whois Server Locator class.
41
     */
42 108
    public function __construct()
43
    {
44 108
        $fileData = file_get_contents($this->whoisListPath);
45 108
        $tldData = json_decode($fileData);
46 108
        $this->whoisCollection = collect((array) $tldData);
47 108
    }
48
49
    /**
50
     * Gets and returns the last match looked up.
51
     *
52
     * @return array The results of the last looked up domain.
53
     */
54 2
    public function getLastMatch()
55
    {
56 2
        return $this->lastMatch;
57
    }
58
59
    /**
60
     * Finds and returns the last match looked up.
61
     *
62
     * @param string $domain Either an ID or a username.
63
     *
64
     * @return self Returns the same instance for fluent usage.
65
     */
66
    abstract public function findWhoisServer($domain);
67
68
    /**
69
     * Get the Whois server of the domain provided, or previously found domain.
70
     *
71
     * @param  string $domain The domain being looked up via whois.
72
     *
73
     * @return string         Returns the domain name of the whois server.
74
     */
75
    abstract public function getWhoisServer($domain = '');
76
}
77