template_model   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 20
dl 0
loc 42
rs 10
c 0
b 0
f 0
wmc 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A get_view_name() 0 2 1
A get_template_list() 0 12 4
A get_meta() 0 17 5
1
<?php
2
3
class template_model extends Model {
4
5
    function get_view_name($template_name) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
6
        return "templates/" . $template_name . "/index";
7
    }
8
9
    /**
10
     * Load template meta
11
     * @param string $template_name Name of template
12
     * @return array|false containing meta of template
13
     */
14
    function get_meta($template_name) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
15
        if (empty($template_name)) {
16
            return false;
17
        }
18
        $template_path = APPPATH . "views/templates/" . $template_name;
19
        $meta_path = $template_path . "/meta.json";
20
21
        if (!(is_dir($template_path) && is_file($meta_path))) {
22
            return false;
23
        }
24
25
        $meta_json = file_get_contents($meta_path);
26
27
        if (!$meta_json) {
28
            return false;
29
        }
30
        return json_decode($meta_json, true);
31
    }
32
33
    function get_template_list() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
34
        $file_list = scandir(APPPATH . 'views/templates/');
35
        foreach ($file_list as $i=>$file) {
36
            if (!is_dir(APPPATH . "views/templates/$file")
37
                || strpos($file, '.') === 0
38
            ) {
39
                unset($file_list[$i]);
40
            } else {
41
                $file_list[$i] = pathinfo($file)['filename'];
42
            }
43
        }
44
        return array_values(array_unique($file_list));
0 ignored issues
show
Bug introduced by
It seems like $file_list can also be of type false; however, parameter $array of array_unique() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

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

44
        return array_values(array_unique(/** @scrutinizer ignore-type */ $file_list));
Loading history...
45
    }
46
47
}
48