CookieBuilder::setDefaultPath()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Http;
4
5
class CookieBuilder
6
{
7
    private $defaultDomain;
8
    private $defaultPath = '/';
9
    private $defaultSecure = true;
10
    private $defaultHttpOnly = true;
11
12
    public function setDefaultDomain($domain)
13
    {
14
        $this->defaultDomain = (string) $domain;
15
    }
16
17
    public function setDefaultPath($path)
18
    {
19
        $this->defaultPath = (string) $path;
20
    }
21
22
    public function setDefaultSecure($secure)
23
    {
24
        $this->defaultSecure = (bool) $secure;
25
    }
26
27
    public function setDefaultHttpOnly($httpOnly)
28
    {
29
        $this->defaultHttpOnly = (bool) $httpOnly;
30
    }
31
32
    public function build($name, $value)
33
    {
34
        $cookie = new HttpCookie($name, $value);
35
        $cookie->setPath($this->defaultPath);
36
        $cookie->setSecure($this->defaultSecure);
37
        $cookie->setHttpOnly($this->defaultHttpOnly);
38
39
        if ($this->defaultDomain !== null) {
40
            $cookie->setDomain($this->defaultDomain);
41
        }
42
43
        return $cookie;
44
    }
45
}