Completed
Push — master ( 5bd0a6...5cfde8 )
by Kamil
20:21
created

FakeChannelPersister   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A onKernelResponse() 0 15 3
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sylius\Bundle\ChannelBundle\Context\FakeChannel;
13
14
use Symfony\Component\HttpFoundation\Cookie;
15
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
16
use Symfony\Component\HttpKernel\HttpKernelInterface;
17
18
/**
19
 * @author Kamil Kokot <[email protected]>
20
 */
21
final class FakeChannelPersister
22
{
23
    /**
24
     * @var FakeChannelCodeProviderInterface
25
     */
26
    private $fakeChannelCodeProvider;
27
28
    /**
29
     * @param FakeChannelCodeProviderInterface $fakeChannelCodeProvider
30
     */
31
    public function __construct(FakeChannelCodeProviderInterface $fakeChannelCodeProvider)
32
    {
33
        $this->fakeChannelCodeProvider = $fakeChannelCodeProvider;
34
    }
35
36
    /**
37
     * @param FilterResponseEvent $filterResponseEvent
38
     */
39
    public function onKernelResponse(FilterResponseEvent $filterResponseEvent)
40
    {
41
        if (HttpKernelInterface::SUB_REQUEST === $filterResponseEvent->getRequestType()) {
42
            return;
43
        }
44
45
        $fakeChannelCode = $this->fakeChannelCodeProvider->getCode($filterResponseEvent->getRequest());
46
47
        if (null === $fakeChannelCode) {
48
            return;
49
        }
50
51
        $response = $filterResponseEvent->getResponse();
52
        $response->headers->setCookie(new Cookie('_channel_code', $fakeChannelCode));
53
    }
54
}
55