Passed
Push — master ( 934657...c3ba90 )
by 世昌
02:07
created

Manager::getContext()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
namespace nebula\application\module;
3
4
use nebula\Context;
5
use nebula\application\module\Module;
6
use nebula\application\module\Builder;
7
use nebula\application\module\NameFinder;
8
use nebula\application\filesystem\FileSystem;
9
10
11
12
/**
13
 * 模板管理器
14
 */
15
class Manager
16
{
17
    /**
18
     * Nebula
19
     *
20
     * @var Context
21
     */
22
    protected $context;
23
24
    /**
25
     * 模块名称管理器
26
     *
27
     * @var NameFinder
28
     */
29
    protected $finder;
30
31
    /**
32
     * 激活的模块
33
     *
34
     * @var string
35
     */
36
    protected $active;
37
38
    /**
39
     * 可访问的模块
40
     *
41
     * @var array
42
     */
43
    protected $reachable;
44
45
    /**
46
     * 注册的模块
47
     *
48
     * @var Module[]
49
     */
50
    protected $register;
51
52
    /**
53
     * 构建管理器
54
     *
55
     * @param Application $app
0 ignored issues
show
Bug introduced by
The type nebula\application\module\Application was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
56
     */
57
    public function __construct(Context $context) {
58
        $this->context = $context;
59
        $this->finder = new NameFinder;
60
    }
61
62
    /**
63
     * Get 激活的模块
64
     *
65
     * @return  string
66
     */ 
67
    public function getActive()
68
    {
69
        return $this->active;
70
    }
71
72
    /**
73
     * Set 激活的模块
74
     *
75
     * @param  string  $active  激活的模块
76
     *
77
     * @return  self
78
     */ 
79
    public function setActive(string $active)
80
    {
81
        $this->active = $active;
82
83
        return $this;
84
    }
85
86
    /**
87
     * Get 可访问的模块
88
     *
89
     * @return  array
90
     */ 
91
    public function getReachable()
92
    {
93
        return $this->reachable;
94
    }
95
96
    /**
97
     * Set 可访问的模块
98
     *
99
     * @param  array  $reachable  可访问的模块
100
     *
101
     * @return  self
102
     */ 
103
    public function setReachable(array $reachable)
104
    {
105
        $this->reachable = $reachable;
106
107
        return $this;
108
    }
109
110
111
    /**
112
     * 注册模块
113
     *
114
     * @return void
115
     */
116
    public function registerModule()
117
    {
118
        $scan = $this->getContext()->getConfig()->get('app.module.scan-path', []);
119
        $cache = $this->getContext()->getDataPath() .'/module-cache';
0 ignored issues
show
introduced by
The method getDataPath() does not exist on nebula\Context. Maybe you want to declare this class abstract? ( Ignorable by Annotation )

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

119
        $cache = $this->getContext()->/** @scrutinizer ignore-call */ getDataPath() .'/module-cache';
Loading history...
120
        FileSystem::makes($cache);
121
        foreach (Builder::scan($scan, $cache) as $module) {
122
            $this->finder->add($module->getName(), $module->getVersion());
123
            $this->module[$module->getFullName()] = $module;
0 ignored issues
show
Bug Best Practice introduced by
The property module does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
124
            $this->getContext()->getDebugger()->info('register module {name} at {path}', ['name'=>$module->getFullName(), 'path'=>$module->getPath()]);
125
        }
126
    }
127
128
    /**
129
     * Get nebula
130
     *
131
     * @return  Context
132
     */ 
133
    public function getContext()
134
    {
135
        return $this->context;
136
    }
137
138
    /**
139
     * 查找模块
140
     *
141
     * @param string $name
142
     * @return Module|null
143
     */     
144
    public function find(string $name):?Module {
0 ignored issues
show
Unused Code introduced by
The parameter $name 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

144
    public function find(/** @scrutinizer ignore-unused */ string $name):?Module {

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...
145
        
146
    }
147
}
148