Passed
Push — master ( 501fc3...f64e27 )
by Paweł
47:53
created

AmpSupportChecker::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Superdesk Web Publisher Core Bundle.
7
 *
8
 * Copyright 2016 Sourcefabric z.ú. and contributors.
9
 *
10
 * For the full copyright and license information, please see the
11
 * AUTHORS and LICENSE files distributed with this source code.
12
 *
13
 * @copyright 2016 Sourcefabric z.ú
14
 * @license http://www.superdesk.org/license
15
 */
16
17
namespace SWP\Bundle\CoreBundle\Checker;
18
19
use SWP\Bundle\CoreBundle\Enhancer\RouteEnhancer;
20
use SWP\Bundle\CoreBundle\Model\TenantInterface;
21
use SWP\Component\MultiTenancy\Context\TenantContextInterface;
22
use Symfony\Component\HttpFoundation\RequestStack;
23
use Takeit\Bundle\AmpHtmlBundle\Checker\AmpSupportCheckerInterface;
24
25
final class AmpSupportChecker implements AmpSupportCheckerInterface
26
{
27
    /**
28
     * @var TenantContextInterface
29
     */
30
    private $tenantContext;
31
32
    /**
33
     * @var RequestStack
34
     */
35
    private $requestStack;
36
37
    /**
38
     * @param TenantContextInterface $tenantContext
39
     * @param RequestStack           $requestStack
40
     */
41 78
    public function __construct(TenantContextInterface $tenantContext, RequestStack $requestStack)
42
    {
43 78
        $this->tenantContext = $tenantContext;
44 78
        $this->requestStack = $requestStack;
45 78
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50 3
    public function isEnabled()
51
    {
52
        /** @var TenantInterface $tenant */
53 3
        $tenant = $this->tenantContext->getTenant();
54 3
        $request = $this->requestStack->getCurrentRequest();
55
56 3
        return $request->attributes->has(RouteEnhancer::ARTICLE_META)
57 3
            && null !== $request->attributes->get(RouteEnhancer::ARTICLE_META)
58 3
            && $tenant->isAmpEnabled();
59
    }
60
}
61