Completed
Push — master ( 9fe7e8...7331b7 )
by Aurimas
12:47
created

CookieParamParser   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 24
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A parse() 0 17 3
1
<?php
2
3
namespace Thruster\Component\Http\Parser;
4
5
use Psr\Http\Message\ServerRequestInterface;
6
7
/**
8
 * Class CookieParamParser
9
 *
10
 * @package Thruster\Component\Http\Parser
11
 * @author  Aurimas Niekis <[email protected]>
12
 */
13
class CookieParamParser implements ParserInterface
14
{
15
    /**
16
     * @inheritDoc
17
     */
18
    public function parse(ServerRequestInterface $request) : ServerRequestInterface
19
    {
20
        $headerValues = $request->getHeader('Cookie');
21
        $cookies = [];
22
23
        foreach ($headerValues as $headerValue) {
24
            $parts = explode(';', str_replace('; ', ';', $headerValue));
25
26
            foreach ($parts as $part) {
27
                list($key, $value) = explode('=', $part);
28
29
                $cookies[$key] = $value;
30
            }
31
        }
32
33
        return $request->withCookieParams($cookies);
34
    }
35
36
}
37