Passed
Push — master ( 843207...29f725 )
by mark
36:53 queued 19:40
created

CmsChartContentWidgetPlugin::resolveTemplatePath()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
5
 * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6
 */
7
8
namespace SprykerShop\Yves\CmsContentWidgetChartConnector\Plugin\CmsContentWidget;
9
10
use Spryker\Shared\CmsContentWidget\Dependency\CmsContentWidgetConfigurationProviderInterface;
11
use Spryker\Yves\CmsContentWidget\Dependency\CmsContentWidgetPluginInterface;
12
use Spryker\Yves\Kernel\AbstractPlugin;
13
use Twig_Environment;
1 ignored issue
show
Bug introduced by
The type Twig_Environment was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
15
/**
16
 * @method \SprykerShop\Yves\CmsContentWidgetChartConnector\CmsContentWidgetChartConnectorFactory getFactory()
17
 */
18
class CmsChartContentWidgetPlugin extends AbstractPlugin implements CmsContentWidgetPluginInterface
19
{
20
    /**
21
     * @var \Spryker\Shared\CmsContentWidget\Dependency\CmsContentWidgetConfigurationProviderInterface
22
     */
23
    protected $widgetConfiguration;
24
25
    /**
26
     * @param \Spryker\Shared\CmsContentWidget\Dependency\CmsContentWidgetConfigurationProviderInterface $widgetConfiguration
27
     */
28
    public function __construct(CmsContentWidgetConfigurationProviderInterface $widgetConfiguration)
29
    {
30
        $this->widgetConfiguration = $widgetConfiguration;
31
    }
32
33
    /**
34
     * @return callable
35
     */
36
    public function getContentWidgetFunction()
37
    {
38
        return [$this, 'contentWidgetFunction'];
0 ignored issues
show
Bug Best Practice introduced by
The expression return array($this, 'contentWidgetFunction') returns the type array<integer,string|Spr...artContentWidgetPlugin> which is incompatible with the documented return type callable.
Loading history...
39
    }
40
41
    /**
42
     * @param \Twig_Environment $twig
43
     * @param array $context
44
     * @param string $chartPluginName
45
     * @param string|null $dataIdentifier
46
     * @param string|null $templateIdentifier
47
     *
48
     * @return string
49
     */
50
    public function contentWidgetFunction(Twig_Environment $twig, array $context, $chartPluginName, $dataIdentifier = null, $templateIdentifier = null): string
51
    {
52
        $widgetContainerRegistry = $this->getFactory()->createWidgetContainerRegistry();
53
        $widgetContainerRegistry->add(
54
            $this->getFactory()->createCmsChartContentWidgetCollection()
55
        );
56
57
        $result = $twig->render(
58
            $this->resolveTemplatePath($templateIdentifier),
59
            $this->getContent($context, $chartPluginName, $dataIdentifier)
60
        );
61
62
        $widgetContainerRegistry->removeLastAdded();
63
64
        return $result;
65
    }
66
67
    /**
68
     * @param null|string $templateIdentifier
69
     *
70
     * @return string
71
     */
72
    protected function resolveTemplatePath($templateIdentifier = null): string
73
    {
74
        if (!$templateIdentifier) {
75
            $templateIdentifier = CmsContentWidgetConfigurationProviderInterface::DEFAULT_TEMPLATE_IDENTIFIER;
76
        }
77
78
        return $this->widgetConfiguration->getAvailableTemplates()[$templateIdentifier];
79
    }
80
81
    /**
82
     * @param array $context
83
     * @param string $chartPluginName
84
     * @param string|null $dataIdentifier
85
     *
86
     * @return array
87
     */
88
    protected function getContent(array $context, $chartPluginName, $dataIdentifier = null): array
1 ignored issue
show
Unused Code introduced by
The parameter $context is not used and could be removed. ( Ignorable by Annotation )

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

88
    protected function getContent(/** @scrutinizer ignore-unused */ array $context, $chartPluginName, $dataIdentifier = null): array

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
89
    {
90
        return [
91
            'chartPluginName' => $chartPluginName,
92
            'dataIdentifier' => $dataIdentifier,
93
        ];
94
    }
95
}
96