Completed
Push — master ( a2ceb5...af9cc0 )
by Ryan
13:18
created

LoadThemeVariables::handle()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 28
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 11
c 0
b 0
f 0
nc 3
nop 3
dl 0
loc 28
rs 8.8571
1
<?php namespace Anomaly\Streams\Platform\Asset\Command;
2
3
use Anomaly\Streams\Platform\Addon\Theme\ThemeCollection;
4
use Anomaly\Streams\Platform\Asset\Event\ThemeVariablesHaveLoaded;
5
use Anomaly\Streams\Platform\Support\Collection;
6
use Illuminate\Config\Repository;
7
use Illuminate\Contracts\Events\Dispatcher;
8
use Websemantics\Lcss2php\Lcss2php;
9
10
/**
11
 * Class LoadThemeVariables
12
 *
13
 * @link   http://pyrocms.com/
14
 * @author PyroCMS, Inc. <[email protected]>
15
 * @author Ryan Thompson <[email protected]>
16
 */
17
class LoadThemeVariables
18
{
19
20
    /**
21
     * The theme variables.
22
     *
23
     * @var Collection
24
     */
25
    protected $variables;
26
27
    /**
28
     * The default variables files.
29
     *
30
     * @var array
31
     */
32
    protected $default = [
33
        'resources/less/theme/variables.less',
34
        'resources/scss/theme/_variables.scss',
35
    ];
36
37
    /**
38
     * Create a new ThemeVariablesHaveLoaded instance.
39
     *
40
     * @param ThemeCollection $themes
0 ignored issues
show
Bug introduced by
There is no parameter named $themes. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
41
     */
42
    public function __construct(Collection $variables)
43
    {
44
        $this->variables = $variables;
45
    }
46
47
    /**
48
     * Handle the command.
49
     *
50
     * @param Dispatcher $events
51
     * @param Repository $config
52
     * @param ThemeCollection $themes
53
     * @internal param Repository $config
54
     */
55
    public function handle(Dispatcher $events, Repository $config, ThemeCollection $themes)
56
    {
57
        if (!$theme = $themes->current()) {
58
            return;
59
        }
60
61
        /**
62
         * Look for a list of variables files theme configuration:
63
         *
64
         * 'variables' => env('THEME_VARIABLES', ['resources/less/theme/variables.less']),
65
         *
66
         * If none exist, use defaults.
67
         */
68
        $files = array_map(
69
            function ($file) use ($theme) {
70
                return $theme->getPath($file);
71
            },
72
            $config->get($theme->getNamespace('config.variables'), $this->default)
73
        );
74
75
        $variables = (new Lcss2php($files))->ignore([\Leafo\ScssPhp\Type::T_MAP, \Leafo\ScssPhp\Type::T_MIXIN]);
76
77
        foreach ($variables->all() as $key => $value) {
78
            $this->variables->put($key, $value);
79
        }
80
81
        $events->fire(new ThemeVariablesHaveLoaded($this->variables));
82
    }
83
}
84