Passed
Pull Request — master (#5)
by Aleksandr
02:53
created

WiFi::getCommandExecutor()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Sanchescom\WiFi;
6
7
use Sanchescom\WiFi\Exceptions\UnknownSystemException;
8
use Sanchescom\WiFi\System\AbstractNetworksCollection;
9
use Sanchescom\WiFi\System\Collection;
10
use Sanchescom\WiFi\System\Command;
11
use Sanchescom\WiFi\System\Linux\NetworksCollection as LinuxNetworks;
12
use Sanchescom\WiFi\System\Mac\NetworksCollection as MacNetworks;
13
use Sanchescom\WiFi\System\Windows\NetworksCollection as WindowsNetworks;
14
15
/**
16
 * Class WiFi.
17
 */
18
class WiFi
19
{
20
    /**
21
     * @var string
22
     */
23
    const OS_WIN = 'WIN';
24
25
    /**
26
     * @var string
27
     */
28
    const OS_LINUX = 'LINUX';
29
30
    /**
31
     * @var string
32
     */
33
    const OS_OSX = 'DAR';
34
35
    /**
36
     * @return Collection
37
     */
38
    public static function scan(): Collection
39
    {
40
        return (new static())->getSystemNetwork()->scan();
41
    }
42
43
    /**
44
     * Getting instance on network collections depended on operation system.
45
     *
46
     * @throws UnknownSystemException
47
     *
48
     * @return AbstractNetworksCollection
49
     */
50
    protected function getSystemNetwork(): AbstractNetworksCollection
51
    {
52
        if ($this->isWindows()) {
53
            return $this->windowsNetwork();
54
        } elseif ($this->isMac()) {
55
            return $this->macNetwork();
56
        } elseif ($this->isLinux()) {
57
            return $this->linuxNetwork();
58
        } else {
59
            throw new UnknownSystemException();
60
        }
61
    }
62
63
    /**
64
     * @return bool
65
     */
66
    protected function isWindows(): bool
67
    {
68
        return os_prefix() == self::OS_WIN;
69
    }
70
71
    /**
72
     * @return bool
73
     */
74
    protected function isMac(): bool
75
    {
76
        return os_prefix() == self::OS_OSX;
77
    }
78
79
    /**
80
     * @return bool
81
     */
82
    protected function isLinux(): bool
83
    {
84
        return os_prefix() == self::OS_LINUX;
85
    }
86
87
    /**
88
     * @return WindowsNetworks
89
     */
90
    protected function windowsNetwork(): AbstractNetworksCollection
91
    {
92
        return new WindowsNetworks($this->getCommandExecutor());
93
    }
94
95
    /**
96
     * @return MacNetworks
97
     */
98
    protected function macNetwork(): AbstractNetworksCollection
99
    {
100
        return new MacNetworks($this->getCommandExecutor());
101
    }
102
103
    /**
104
     * @return LinuxNetworks
105
     */
106
    protected function linuxNetwork(): AbstractNetworksCollection
107
    {
108
        return new LinuxNetworks($this->getCommandExecutor());
109
    }
110
111
    /**
112
     * @return Command
113
     */
114
    protected function getCommandExecutor()
115
    {
116
        return new Command();
117
    }
118
}
119