Passed
Pull Request — master (#5)
by Aleksandr
03:12
created

AbstractNetwork::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Sanchescom\WiFi\System;
6
7
/**
8
 * Class AbstractNetwork.
9
 */
10
abstract class AbstractNetwork
11
{
12
    /** @var string */
13
    public $bssid;
14
15
    /** @var string */
16
    public $ssid;
17
18
    /** @var int */
19
    public $channel;
20
21
    /** @var float */
22
    public $quality;
23
24
    /** @var float */
25
    public $dbm;
26
27
    /** @var string */
28
    public $security;
29
30
    /** @var string */
31
    public $securityFlags;
32
33
    /** @var int */
34
    public $frequency;
35
36
    /** @var bool */
37
    public $connected;
38
39
    /** @var array */
40
    protected static $securityTypes = [
41
        'WPA2',
42
        'WPA',
43
        'WEP',
44
    ];
45
46
    /** @var Command */
47
    protected $command;
48
49
    /**
50
     * AbstractNetwork constructor.
51
     *
52
     * @param Command $command
53
     */
54
    public function __construct(Command $command)
55
    {
56
        $this->command = $command;
57
    }
58
59
    /**
60
     * @return string
61
     */
62
    public function getSecurityType(): string
63
    {
64
        $securityType = 'Unknown';
65
66
        foreach (self::$securityTypes as $securityType) {
67
            if (strpos($this->security, $securityType) !== false) {
68
                break;
69
            }
70
        }
71
72
        return $securityType;
73
    }
74
75
    /**
76
     * @return string
77
     */
78
    public function __toString(): string
79
    {
80
        return implode('|', [
81
            $this->bssid,
82
            $this->ssid,
83
            $this->quality,
84
            $this->dbm,
85
            $this->security,
86
            $this->securityFlags,
87
            $this->frequency,
88
            var_export($this->connected, true),
89
        ]);
90
    }
91
92
    /**
93
     * @param string $password
94
     * @param string $device
95
     */
96
    abstract public function connect(string $password, string $device): void;
97
98
    /**
99
     * @param string $device
100
     */
101
    abstract public function disconnect(string $device): void;
102
103
    /**
104
     * @param array   $network
105
     * @param Command $command
106
     *
107
     * @return AbstractNetwork
108
     */
109
    abstract public function createFromArray(array $network, Command $command): self;
110
}
111