CookieBuilder   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 41
wmc 6
lcom 1
cbo 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setDefaultDomain() 0 4 1
A setDefaultPath() 0 4 1
A setDefaultSecure() 0 4 1
A setDefaultHttpOnly() 0 4 1
A build() 0 13 2
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
}