SearchTarget   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 9
c 2
b 0
f 0
lcom 1
cbo 1
dl 0
loc 56
ccs 0
cts 18
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
B isAll() 0 20 5
A fromString() 0 8 2
A toString() 0 8 2
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