AliveOptions::getServerString()   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 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
ccs 0
cts 4
cp 0
rs 9.4285
cc 2
eloc 4
nc 2
nop 0
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\Options;
9
10
/**
11
 * Alive request options class
12
 *
13
 * @package GravityMedia\Ssdp\Request\Options
14
 */
15
class AliveOptions extends UpdateOptions
16
{
17
    /**
18
     * Default message lifetime (seconds until advertisement expires)
19
     */
20
    const DEFAULT_MESSAGE_LIFETIME = 1800;
21
22
    /**
23
     * Default server name
24
     */
25
    const DEFAULT_SERVER_NAME = 'GravityMedia-Ssdp';
26
27
    /**
28
     * Default server version
29
     */
30
    const DEFAULT_SERVER_VERSION = '1.0.x-dev';
31
32
    /**
33
     * @var string
34
     */
35
    private static $defaultServerString;
36
37
    /**
38
     * @var int
39
     */
40
    protected $messageLifetime;
41
42
    /**
43
     * @var string
44
     */
45
    protected $serverString;
46
47
    /**
48
     * Get default server string
49
     *
50
     * @return string
51
     */
52
    public function getDefaultServerString()
53
    {
54
        if (null === self::$defaultServerString) {
55
            self::$defaultServerString = sprintf(
56
                '%s/%s UPnP/1.1 %s/%s',
57
                PHP_OS,
58
                php_uname('r'),
59
                self::DEFAULT_SERVER_NAME,
60
                self::DEFAULT_SERVER_VERSION
61
            );
62
        }
63
64
        return self::$defaultServerString;
65
    }
66
67
    /**
68
     * Get message lifetime
69
     *
70
     * @return int
71
     */
72
    public function getMessageLifetime()
73
    {
74
        if (null === $this->messageLifetime) {
75
            return self::DEFAULT_MESSAGE_LIFETIME;
76
        }
77
78
        return $this->messageLifetime;
79
    }
80
81
    /**
82
     * Set message lifetime
83
     *
84
     * @param int $messageLifetime
85
     *
86
     * @return $this
87
     */
88
    public function setMessageLifetime($messageLifetime)
89
    {
90
        $this->messageLifetime = $messageLifetime;
91
        return $this;
92
    }
93
94
    /**
95
     * Get server string
96
     *
97
     * @return string
98
     */
99
    public function getServerString()
100
    {
101
        if (null === $this->serverString) {
102
            return $this->getDefaultServerString();
103
        }
104
105
        return $this->serverString;
106
    }
107
108
    /**
109
     * Set server string
110
     *
111
     * @param string $serverString
112
     *
113
     * @return $this
114
     */
115
    public function setServerString($serverString)
116
    {
117
        $this->serverString = $serverString;
118
        return $this;
119
    }
120
}
121