AbstractLocator::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

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