SearchTarget::fromString()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 8
ccs 0
cts 4
cp 0
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
crap 6
1
<?php
2
/**
3
 * This file is part of the Ssdp project.
4
 *
5
 * @author Daniel Schröder <[email protected]>
6
 */
7
8
namespace GravityMedia\Ssdp;
9
10
/**
11
 * Search target
12
 *
13
 * @package GravityMedia\Ssdp
14
 */
15
class SearchTarget extends NotificationType
16
{
17
    /**
18
     * Return whether to search for all devices
19
     *
20
     * @return bool
21
     */
22
    public function isAll()
23
    {
24
        if (null !== $this->getId()) {
25
            return false;
26
        }
27
28
        if ($this->isRootDevice()) {
29
            return false;
30
        }
31
32
        if ($this->isDevice()) {
33
            return false;
34
        }
35
36
        if ($this->isService()) {
37
            return false;
38
        }
39
40
        return true;
41
    }
42
43
    /**
44
     * Create search target from string.
45
     *
46
     * @param string $searchTarget
47
     *
48
     * @return self
49
     */
50
    public static function fromString($searchTarget)
51
    {
52
        if (strtolower(trim($searchTarget)) === 'ssdp:all') {
53
            return new static();
54
        }
55
56
        return parent::fromString($searchTarget);
57
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62
    public function toString()
63
    {
64
        if ($this->isAll()) {
65
            return 'ssdp:all';
66
        }
67
68
        return parent::toString();
69
    }
70
}
71