Passed
Push — v5 ( c0775f...b45ef7 )
by Alexey
16:22
created

Content   A

Complexity

Total Complexity 19

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 67
rs 10
c 0
b 0
f 0
wmc 19

4 Methods

Rating   Name   Duplication   Size   Complexity  
D getPaths() 0 37 13
A setPath() 0 5 3
A __construct() 0 4 1
A setData() 0 3 2
1
<?php
2
3
4
namespace Inji\View;
5
6
7
class Content {
8
    public $name = '';
9
    public $path = '';
10
    public $data = [];
11
    /**
12
     * @var Page
13
     */
14
    public $page;
15
16
    function __construct($params, ?Page $page) {
0 ignored issues
show
Unused Code introduced by
The parameter $page is not used and could be removed. ( Ignorable by Annotation )

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

16
    function __construct($params, /** @scrutinizer ignore-unused */ ?Page $page) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
17
        $this->name = $params['name'] ?? 'index';
18
        $this->setPath($params['path'] ?? false);
19
        $this->setData($params['data'] ?? []);
20
    }
21
22
    function setData($data = []) {
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...
23
        if ($data) {
24
            $this->data = array_merge($this->data, $data);
25
        }
26
    }
27
28
    function setPath($path = false) {
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...
29
        if ($path) {
30
            $this->path = $path;
31
        } elseif (!$this->path) {
32
            $this->path = \Inji\Tools::pathsResolve($this->getPaths($this->name), $this->path);
33
        }
34
35
    }
36
37
    public function getPaths($content = '') {
38
        if (!$content) {
39
            $content = $this->name;
40
        }
41
        $paths = [];
42
        if ($this->page && $this->page->module) {
43
            if (\Inji\Controller::$cur) {
44
                $paths['templateModuleController'] = $this->path . "/modules/{$this->page->module->name}/" . \Inji\Controller::$cur->name . "/{$content}.php";
45
            }
46
            $paths['templateModule'] = $this->path . "/modules/{$this->page->module->name}/{$content}.php";
47
        }
48
        if (\Inji\Module::$cur) {
49
            if (\Inji\Controller::$cur) {
50
                $paths['templateCurModuleController'] = $this->path . "/modules/" . \Inji\Module::$cur->name . "/" . \Inji\Controller::$cur->name . "/{$content}.php";
51
            }
52
            $paths['templateCurModule'] = $this->path . "/modules/" . \Inji\Module::$cur->name . "/{$content}.php";
53
        }
54
        if (\Inji\Controller::$cur) {
55
            $modulePaths = \Inji\Module::getModulePaths(\Inji\Controller::$cur->module->name);
56
            foreach ($modulePaths as $key => $modulePath) {
57
                $paths['module_' . $key . '_appType'] = $modulePath . '/views/' . \Inji\Controller::$cur->module->app->type . '/' . \Inji\Controller::$cur->name . "/{$content}.php";
58
                $paths['module_' . $key . '_appType_controllerName'] = $modulePath . '/views/' . \Inji\Controller::$cur->module->app->type . "/{$content}.php";
59
                $paths['module_' . $key] = $modulePath . '/views/' . "/{$content}.php";
60
            }
61
        }
62
63
        if ($this->page->module) {
64
            if (\Inji\Controller::$cur) {
65
                $paths['customModuleTemplateControllerContentController'] = $this->path . "/modules/" . $this->page->module->name . "/" . \Inji\Controller::$cur->name . "/{$content}.php";
66
            }
67
            $paths['customModuleTemplateControllerContent'] = $this->path . "/modules/" . $this->page->module->name . "/{$content}.php";
68
        }
69
        if ($this->page->module && \Inji\Controller::$cur) {
70
            $paths['customModuleControllerContentController'] = $this->page->module->path . '/' . \Inji\Controller::$cur->module->app->type . "Controllers/content/" . \Inji\Controller::$cur->name . "/{$content}.php";
71
            $paths['customModuleControllerContent'] = $this->page->module->path . '/' . \Inji\Controller::$cur->module->app->type . "Controllers/content/{$content}.php";
72
        }
73
        return $paths;
74
    }
75
}