Completed
Push — master ( a098e8...501eb0 )
by Craig
40:53 queued 24:08
created

DefaultThemeExtension   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 9
c 1
b 0
f 1
dl 0
loc 26
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getStyleChoices() 0 7 1
A getFunctions() 0 4 1
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Zikula package.
7
 *
8
 * Copyright Zikula - https://ziku.la/
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Zikula\DefaultTheme\Twig;
15
16
use Symfony\Component\Yaml\Yaml;
17
use Twig\Extension\AbstractExtension;
18
use Twig\TwigFunction;
19
use Zikula\Bundle\CoreBundle\HttpKernel\ZikulaHttpKernelInterface;
20
21
class DefaultThemeExtension extends AbstractExtension
22
{
23
    /**
24
     * @var ZikulaHttpKernelInterface
25
     */
26
    private $kernel;
27
28
    public function __construct(ZikulaHttpKernelInterface $kernel)
29
    {
30
        $this->kernel = $kernel;
31
    }
32
33
    public function getFunctions()
34
    {
35
        return [
36
            new TwigFunction('getStyleChoices', [$this, 'getStyleChoices'])
37
        ];
38
    }
39
40
    public function getStyleChoices(): array
41
    {
42
        $themeBundle = $this->kernel->getBundle('ZikulaDefaultTheme');
43
        $themeVarsPath = $themeBundle->getConfigPath() . '/variables.yaml';
0 ignored issues
show
Bug introduced by
The method getConfigPath() does not exist on Symfony\Component\HttpKe...\Bundle\BundleInterface. It seems like you code against a sub-type of Symfony\Component\HttpKe...\Bundle\BundleInterface such as Zikula\ExtensionsModule\AbstractExtension. ( Ignorable by Annotation )

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

43
        $themeVarsPath = $themeBundle->/** @scrutinizer ignore-call */ getConfigPath() . '/variables.yaml';
Loading history...
44
        $variableDefinitions = Yaml::parse(file_get_contents($themeVarsPath));
45
46
        return $variableDefinitions['theme_style']['options']['choices'];
47
    }
48
}
49