Test Failed
Pull Request — master (#2)
by Mathieu
03:19
created

AuthTokenMetadata::enabled()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Charcoal\User;
4
5
use InvalidArgumentException;
6
7
// From 'charcoal-core'
8
use Charcoal\Model\ModelMetadata;
9
10
/**
11
 * User Auth Token metadata
12
 */
13
class AuthTokenMetadata extends ModelMetadata
14
{
15
    /**
16
     * @var boolean $enabled
17
     */
18
    private $enabled;
19
20
    /**
21
     * @var string $cookieName
22
     */
23
    private $cookieName;
24
25
    /**
26
     * @var string $cookieDuration
27
     */
28
    private $cookieDuration;
29
30
    /**
31
     * @var boolean $httpsOnly
32
     */
33
    private $httpsOnly;
34
35
    /**
36
     *
37
     * @return array
38
     * @see \Charcoal\Config\ConfigInterface::defaults()
39
     */
40
    public function defaults()
41
    {
42
        $parentDefaults = parent::defaults();
43
44
        $defaults = array_replace_recursive($parentDefaults, [
45
            'enabled'         => true,
46
            'cookie_name'     => 'charcoal_user_login',
47
            'cookie_duration' => '15 days',
48
            'https_only'      => false
49
        ]);
50
        return $defaults;
51
    }
52
53
    /**
54
     * @param boolean $enabled The enabled flag.
55
     * @return self
56
     */
57
    public function setEnabled($enabled)
58
    {
59
        $this->enabled = !!$enabled;
60
        return $this;
61
    }
62
63
    /**
64
     * @return boolean
65
     */
66
    public function getEnabled()
67
    {
68
        return $this->enabled;
69
    }
70
71
    /**
72
     * @param string $name The cookie name.
73
     * @throws InvalidArgumentException If the cookie name is not a string.
74
     * @return self
75
     */
76
    public function setCookieName($name)
77
    {
78
        if (!is_string($name)) {
79
            throw new InvalidArgumentException(
80
                'Can not set auth token\'s cookie  name: must be a string'
81
            );
82
        }
83
        $this->cookieName = $name;
84
        return $this;
85
    }
86
87
    /**
88
     * @return string
89
     */
90
    public function getCookieName()
91
    {
92
        return $this->cookieName;
93
    }
94
95
    /**
96
     * @param string $duration The cookie duration, or duration. Ex: "15 days".
97
     * @throws InvalidArgumentException If the cookie name is not a string.
98
     * @return self
99
     */
100
    public function setCookieDuration($duration)
101
    {
102
        if (!is_string($duration)) {
103
            throw new InvalidArgumentException(
104
                'Can not set auth token\'s cookie duration: must be a string'
105
            );
106
        }
107
        $this->cookieDuration = $duration;
108
        return $this;
109
    }
110
111
    /**
112
     * @return string
113
     */
114
    public function getCookieDuration()
115
    {
116
        return $this->cookieDuration;
117
    }
118
119
    /**
120
     * @param boolean $httpsOnly The "https only" flag.
121
     * @return self
122
     */
123
    public function setHttpsOnly($httpsOnly)
124
    {
125
        $this->httpsOnly = !!$httpsOnly;
126
        return $this;
127
    }
128
129
    /**
130
     * @return boolean
131
     */
132
    public function getHttpsOnly()
133
    {
134
        return $this->httpsOnly;
135
    }
136
}
137