Completed
Pull Request — develop (#716)
by Agel_Nash
06:45 queued 44s
created

ManagerTheme   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 71
Duplicated Lines 30.99 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 22
loc 71
rs 10
c 0
b 0
f 0
wmc 8
lcom 1
cbo 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 15 2
A loadSnippets() 11 11 2
A loadChunks() 11 11 2
A addSnippet() 0 11 1
A addChunk() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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