SaveCookie   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 35
c 0
b 0
f 0
wmc 7
lcom 1
cbo 4
ccs 21
cts 21
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 12 1
A buildSetCookieHeaderValue() 0 9 4
A getSetCookieDatePart() 0 7 2
1
<?php
2
3
namespace Mcustiel\PowerRoute\Actions;
4
5
use Mcustiel\Mockable\DateTime;
6
use Mcustiel\PowerRoute\Common\TransactionData;
7
8
class SaveCookie implements ActionInterface
9
{
10
    use PlaceholderEvaluator;
11
12 1
    public function execute(TransactionData $transactionData, $argument = null)
13
    {
14 1
        $transactionData->setResponse(
15 1
            $transactionData->getResponse()->withHeader(
16 1
                'Set-Cookie',
17 1
                $this->buildSetCookieHeaderValue(
18 1
                    $argument,
19
                    $transactionData
20 1
                )
21 1
            )
22 1
        );
23 1
    }
24
25 1
    private function buildSetCookieHeaderValue($argument, $transactionData)
26
    {
27 1
        $value = $this->getValueOrPlaceholder($argument['value'], $transactionData);
28
29 1
        return $argument['name'] . '=' . $value . $this->getSetCookieDatePart($argument)
30 1
            . (isset($argument['domain']) ? '; domain=' . $argument['domain'] : '')
31 1
            . (isset($argument['path']) ? '; path=' . $argument['path'] : '')
32 1
            . (isset($argument['secure']) ? '; secure' : '');
33
    }
34
35 1
    private function getSetCookieDatePart($argument)
36
    {
37 1
        return isset($argument['ttl']) ? '; expires=' . date(
38 1
            DATE_COOKIE,
39 1
            ((new DateTime())->toPhpDateTime()->getTimestamp() + $argument['ttl'])
40 1
        ) : '';
41
    }
42
}
43