Model   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 70
Duplicated Lines 10 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 7
loc 70
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getThemesList() 7 7 1
A getTotalNumber() 0 4 1
A getList() 0 30 4

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
2
3
namespace Rudolf\Modules\Appearance\Roll\Admin;
4
5
use Rudolf\Framework\Model\AdminModel;
6
7
class Model extends AdminModel
8
{
9
    /**
10
     * @var array
11
     */
12
    private $themes;
13
14
    public function __construct()
15
    {
16
        parent::__construct();
17
18
        $this->themes = $this->getThemesList();
19
    }
20
21
    /**
22
     * @return array
23
     */
24 View Code Duplication
    private function getThemesList()
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...
25
    {
26
        return array_diff(
27
            scandir(THEMES_ROOT.'/front', SCANDIR_SORT_ASCENDING),
28
            array('.', '..')
29
        );
30
    }
31
32
    /**
33
     * @return int
34
     */
35
    public function getTotalNumber()
36
    {
37
        return count($this->themes);
38
    }
39
40
    /**
41
     * @param int $limit
42
     * @param int $onPage
43
     *
44
     * @return array
45
     */
46
    public function getList($limit, $onPage)
47
    {
48
        $array = [];
49
50
        if (empty($this->themes)) {
51
            return $array;
52
        }
53
54
        $i = 1;
55
        foreach ($this->themes as $key => $value) {
56
            $path = THEMES_ROOT.'/front/'.$value.'/theme.php';
57
58
            if (file_exists($path)) {
59
                include_once $path;
60
            }
61
62
            $array[] = [
63
                'id' => $i++,
64
                'path' => str_replace(['/theme.php', 'public/'], '', $path),
65
                'name' => $value,
66
                'description' => $value::DESCRIPTION,
67
                'full-name' => $value::NAME,
68
                'author' => $value::AUTHOR,
69
                'version' => $value::VERSION,
70
                'active' => FRONT_THEME === $value,
71
            ];
72
        }
73
74
        return array_slice($array, $limit, $onPage);
75
    }
76
}
77