WifiFormat::getText()   A
last analyzed

Complexity

Conditions 4
Paths 8

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 0
cts 8
cp 0
rs 9.9666
c 0
b 0
f 0
cc 4
nc 8
nop 0
crap 20
1
<?php
2
3
/*
4
 * This file is part of the 2amigos/qrcode-library 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 https://www.2amigos.us/
21
 * @package Da\QrCode\Format
22
 */
23
class WifiFormat extends AbstractFormat
24
{
25
    /**
26
     * @var string the authentication type. e.g., WPA
27
     */
28
    public $authentication;
29
    /**
30
     * @var string the network SSID
31
     */
32
    public $ssid;
33
    /**
34
     * @var string the wifi password
35
     */
36
    public $password;
37
    /**
38
     * @var string hidden SSID (optional; equals false if omitted): either true or false
39
     */
40
    public $hidden;
41
42
    /**
43
     * @throws InvalidConfigException
44
     */
45
    public function init(): void
46
    {
47
        if ($this->ssid === null) {
48
            throw new InvalidConfigException("'ssid' cannot be null");
49
        }
50
    }
51
52
    /**
53
     * @inheritdoc
54
     */
55
    public function getText(): string
56
    {
57
        $data = [];
58
        $data[] = $this->authentication !== null ? "T:{$this->authentication}" : '';
59
        $data[] = "S:{$this->ssid}";
60
        $data[] = $this->password !== null ? "P:{$this->password}" : '';
61
        $data[] = $this->hidden !== null ? "H:{$this->hidden}" : '';
62
        return 'WIFI:' . implode(';', $data) . ';';
63
    }
64
}
65