Completed
Push — master ( 6ffc3f...4609e3 )
by Antonio
51:14 queued 46:44
created

WifiFormat   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 42
ccs 0
cts 15
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 6 2
A getText() 0 9 4
1
<?php
2
3
/*
4
 * This file is part of the 2amigos/yii2-qrcode-component project.
5
 *
6
 * (c) 2amigOS! <http://2amigos.us/>
7
 *
8
 * For the full copyright and license information, please view
9
 * the LICENSE file that was distributed with this source code.
10
 */
11
12
namespace Da\QrCode\Format;
13
14
use Da\QrCode\Exception\InvalidConfigException;
15
16
/**
17
 * Class Wifi formats a string to properly create a Wifi QrCode
18
 *
19
 * @author Antonio Ramirez <[email protected]>
20
 * @link http://www.ramirezcobos.com/
21
 * @link http://www.2amigos.us/
22
 * @package Da\QrCode\Format
23
 */
24
class WifiFormat extends AbstractFormat
25
{
26
    /**
27
     * @var string the authentication type. e.g., WPA
28
     */
29
    public $authentication;
30
    /**
31
     * @var string the network SSID
32
     */
33
    public $ssid;
34
    /**
35
     * @var string the wifi password
36
     */
37
    public $password;
38
    /**
39
     * @var string hidden SSID (optional; equals false if omitted): either true or false
40
     */
41
    public $hidden;
42
43
    /**
44
     * @throws InvalidConfigException
45
     */
46
    public function init()
47
    {
48
        if ($this->ssid === null) {
49
            throw new InvalidConfigException("'ssid' cannot be null");
50
        }
51
    }
52
53
    /**
54
     * @inheritdoc
55
     */
56
    public function getText()
57
    {
58
        $data = [];
59
        $data[] = $this->authentication !== null ? "T:{$this->authentication}" : "";
60
        $data[] = "S:{$this->ssid}";
61
        $data[] = $this->password !== null ? "P:{$this->password}" : "";
62
        $data[] = $this->hidden !== null ? "H:{$this->hidden}" : "";
63
        return "WIFI:" . implode(";", $data) . ";";
64
    }
65
}
66