Completed
Push — master ( de6ffa...f677f6 )
by Aleksandr
12s queued 11s
created

Network::disconnect()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
c 0
b 0
f 0
dl 0
loc 7
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Sanchescom\WiFi\System\Darwin;
6
7
use Sanchescom\WiFi\Contracts\FrequencyInterface;
8
use Sanchescom\WiFi\System\AbstractNetwork;
9
use Sanchescom\WiFi\System\Frequency;
10
11
/**
12
 * Class Network.
13
 */
14
class Network extends AbstractNetwork implements FrequencyInterface
15
{
16
    use Frequency;
17
18
    /**
19
     * @param string $password
20
     * @param string $device
21
     *
22
     * @throws \Exception
23
     */
24
    public function connect(string $password, string $device): void
25
    {
26
        $this->getCommand()->execute(
27
            sprintf('networksetup -setairportnetwork %s %s %s', $device, $this->ssid, $password)
28
        );
29
    }
30
31
    /**
32
     * @param string $device
33
     *
34
     * @throws \Exception
35
     */
36
    public function disconnect(string $device): void
37
    {
38
        $this->getCommand()->execute(
39
            glue_commands(
40
                sprintf('networksetup -removepreferredwirelessnetwork %s %s', $device, $this->ssid),
41
                sprintf('networksetup -setairportpower %s %s', $device, 'off'),
42
                sprintf('networksetup -setairportpower %s %s', $device, 'on')
43
            )
44
        );
45
    }
46
47
    /**
48
     * @param array $network
49
     *
50
     * @return \Sanchescom\WiFi\System\Darwin\Network
51
     */
52
    public function createFromArray(array $network): AbstractNetwork
53
    {
54
        $this->ssid = $network[0];
55
        $this->bssid = $network[1];
56
        $this->channel = (int) $network[3];
57
        $this->security = $network[6];
58
        $this->securityFlags = $network[5];
59
        $this->quality = $network[2];
60
        $this->frequency = $this->getFrequency();
61
        $this->dbm = to_dbm((int) $network[2]);
62
        $this->connected = isset($network[7]);
63
64
        return $this;
65
    }
66
}
67