Completed
Pull Request — develop (#716)
by Agel_Nash
12:28 queued 06:14
created

ManagerTheme::loadSnippets()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 11
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 0
dl 11
loc 11
rs 9.4285
c 0
b 0
f 0
1
<?php namespace EvolutionCMS;
2
3
use EvolutionCMS\Interfaces\ManagerThemeInterface;
4
use EvolutionCMS\Interfaces\CoreInterface;
5
use Exception;
6
7
class ManagerTheme implements ManagerThemeInterface
8
{
9
    /**
10
     * @var CoreInterface
11
     */
12
    protected $core;
13
14
    /**
15
     * @var $theme
16
     */
17
    protected $theme;
18
19
    protected $templateNamespace = 'manager';
20
21
    public function __construct(CoreInterface $core, $theme = '')
22
    {
23
        $this->core = $core;
24
25
        if (empty($theme)) {
26
            $theme = $this->core->getConfig('manager_theme');
27
        }
28
29
        $this->theme = $theme;
30
31
        $this->loadSnippets();
32
33
        $this->loadChunks();
34
		
35
    }
36
37 View Code Duplication
    public function loadSnippets()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
38
    {
39
        $found = $this->core->findElements(
40
            'chunk',
41
            MODX_MANAGER_PATH . 'media/style/'. $this->theme .'/snippets/',
42
            array('php')
43
        );
44
        foreach ($found as $name => $code) {
45
            $this->addSnippet($name, $code);
46
        }
47
    }
48
49 View Code Duplication
    public function loadChunks()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
50
    {
51
        $found = $this->core->findElements(
52
            'chunk',
53
            MODX_MANAGER_PATH . 'media/style/'. $this->theme .'/chunks/',
54
            array('tpl', 'html')
55
        );
56
        foreach ($found as $name => $code) {
57
            $this->addChunk($name, $code);
58
        }
59
    }
60
61
    public function addSnippet($name, $code)
62
    {
63
        $this->core->addSnippet(
64
            $name,
65
            $code,
66
            $this->templateNamespace  . '#',
67
            array(
68
                'managerTheme' => $this
69
            )
70
        );
71
    }
72
73
    public function addChunk($name, $code)
74
    {
75
        $this->core->addChunk($name, $code, $this->templateNamespace . '#');
76
    }
77
}
78