Passed
Push — master ( fc972d...1e57ea )
by Petar
03:04
created

Renderer::getEmbedTemplateName()   B

Complexity

Conditions 7
Paths 40

Size

Total Lines 47
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 7
eloc 24
c 1
b 0
f 1
nc 40
nop 3
dl 0
loc 47
rs 8.6026
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Netgen\Bundle\EzPlatformSiteApiBundle\Core\FieldType\RichText;
6
7
use eZ\Publish\API\Repository\Repository;
8
use eZ\Publish\Core\MVC\ConfigResolverInterface;
9
use EzSystems\EzPlatformRichTextBundle\eZ\RichText\Renderer as CoreRenderer;
10
use Psr\Log\LoggerInterface;
11
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
12
use Symfony\Component\Templating\EngineInterface;
13
14
class Renderer extends CoreRenderer
15
{
16
    private $ngEmbedConfigurationNamespace;
17
18
    public function __construct(
19
        Repository $repository,
20
        AuthorizationCheckerInterface $authorizationChecker,
21
        ConfigResolverInterface $configResolver,
22
        EngineInterface $templateEngine,
23
        $tagConfigurationNamespace,
24
        $styleConfigurationNamespace,
25
        $embedConfigurationNamespace,
26
        $ngEmbedConfigurationNamespace,
27
        LoggerInterface $logger = null,
28
        array $customTagsConfiguration = [],
29
        array $customStylesConfiguration = []
30
    ) {
31
        parent::__construct(
32
            $repository,
33
            $authorizationChecker,
34
            $configResolver,
35
            $templateEngine,
36
            $tagConfigurationNamespace,
37
            $styleConfigurationNamespace,
38
            $embedConfigurationNamespace,
39
            $logger,
40
            $customTagsConfiguration,
41
            $customStylesConfiguration
42
        );
43
44
        $this->ngEmbedConfigurationNamespace = $ngEmbedConfigurationNamespace;
45
    }
46
47
    /**
48
     * Returns configured template reference for the given embed parameters.
49
     *
50
     * @param $resourceType
51
     * @param $isInline
52
     * @param $isDenied
53
     *
54
     * @return null|string
55
     */
56
    protected function getEmbedTemplateName($resourceType, $isInline, $isDenied): ?string
57
    {
58
        $configurationReference = $this->getConfigurationReference();
59
60
        if ($resourceType === static::RESOURCE_TYPE_CONTENT) {
61
            $configurationReference .= '.content';
62
        } else {
63
            $configurationReference .= '.location';
64
        }
65
66
        if ($isInline) {
67
            $configurationReference .= '_inline';
68
        }
69
70
        if ($isDenied) {
71
            $configurationReference .= '_denied';
72
        }
73
74
        if ($this->configResolver->hasParameter($configurationReference)) {
75
            $configuration = $this->configResolver->getParameter($configurationReference);
76
77
            return $configuration['template'];
78
        }
79
80
        $this->logger->warning(
0 ignored issues
show
Bug introduced by
The method warning() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

80
        $this->logger->/** @scrutinizer ignore-call */ 
81
                       warning(

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
81
            "Embed tag configuration '{$configurationReference}' was not found"
82
        );
83
84
        $configurationReference = $this->getConfigurationReference();
85
86
        $configurationReference .= '.default';
87
88
        if ($isInline) {
89
            $configurationReference .= '_inline';
90
        }
91
92
        if ($this->configResolver->hasParameter($configurationReference)) {
93
            $configuration = $this->configResolver->getParameter($configurationReference);
94
95
            return $configuration['template'];
96
        }
97
98
        $this->logger->warning(
99
            "Embed tag default configuration '{$configurationReference}' was not found"
100
        );
101
102
        return null;
103
    }
104
105
    private function getConfigurationReference(): string
106
    {
107
        $overrideViewAction = $this->configResolver->getParameter(
108
            'override_url_alias_view_action',
109
            'netgen_ez_platform_site_api'
110
        );
111
112
        if ($overrideViewAction) {
113
            return $this->ngEmbedConfigurationNamespace;
114
        }
115
116
        return $this->embedConfigurationNamespace;
117
    }
118
}
119