1 | <?php |
||
21 | class Application extends Container |
||
22 | { |
||
23 | const |
||
24 | VERSION = '5.5.3', |
||
25 | DEFAULT_DISTFILE_SUFFIX = '-dist', |
||
26 | DEFAULT_CONF_DIRECTORY = 'env', |
||
27 | DEFAULT_MASTER_FILE = 'master.conf', |
||
28 | BACKUP_SUFFIX = '~', |
||
29 | FINDER_CACHE_DIRECTORY = 'cache/karma', |
||
30 | FINDER_CACHE_DURATION = 86400, |
||
31 | PROFILE_FILENAME = '.karma'; |
||
32 | |||
33 | 44 | public function __construct() |
|
34 | { |
||
35 | 44 | parent::__construct(); |
|
36 | |||
37 | 44 | $this->initializeParameters(); |
|
|
|||
38 | |||
39 | 44 | $this->initializeConfiguration(); |
|
40 | 44 | $this->initializeProfile(); |
|
41 | 44 | $this->initializeFinder(); |
|
42 | 44 | $this->initializeSourceFileSystem(); |
|
43 | 44 | $this->initializeVcs(); |
|
44 | |||
45 | 44 | $this->initializeServices(); |
|
46 | 44 | } |
|
47 | |||
48 | 44 | private function initializeParameters() |
|
49 | { |
||
50 | 44 | $this['configuration.path'] = 'conf'; |
|
51 | 44 | $this['configuration.masterFile'] = 'master.conf'; |
|
52 | |||
53 | 44 | $this['sources.path'] = 'src'; |
|
54 | 44 | $this['target.path'] = null; |
|
55 | 44 | $this['hydrator.allowNonDistFilesOverwrite'] = false; |
|
56 | |||
57 | 44 | $this['distFiles.suffix'] = '-dist'; |
|
58 | 44 | } |
|
59 | |||
60 | 44 | private function initializeConfiguration() |
|
61 | { |
||
62 | $this['configuration.fileSystem.adapter'] = $this->factory(function($c) { |
||
63 | return new Local($c['configuration.path']); |
||
64 | 44 | }); |
|
65 | |||
66 | $this['configuration.fileSystem'] = $this->factory(function($c) { |
||
67 | 33 | return new Filesystem($c['configuration.fileSystem.adapter']); |
|
68 | 44 | }); |
|
69 | |||
70 | $this['parser'] = function($c) { |
||
71 | 33 | $parser = new Parser($c['configuration.fileSystem']); |
|
72 | |||
73 | 33 | $parser->enableIncludeSupport() |
|
74 | 33 | ->enableExternalSupport() |
|
75 | 33 | ->enableGroupSupport() |
|
76 | 33 | ->setLogger($c['logger']) |
|
77 | 33 | ->parse($c['configuration.masterFile']); |
|
78 | |||
79 | 33 | return $parser; |
|
80 | }; |
||
81 | |||
82 | $this['configuration'] = function($c) { |
||
83 | 32 | $parser = $c['parser']; |
|
84 | |||
85 | 32 | return new Reader( |
|
86 | 32 | $parser->getVariables(), |
|
87 | 32 | $parser->getExternalVariables(), |
|
88 | 32 | $parser->getGroups(), |
|
89 | 32 | $parser->getDefaultEnvironmentsForGroups() |
|
90 | 32 | ); |
|
91 | }; |
||
92 | 44 | } |
|
93 | |||
94 | 44 | private function initializeProfile() |
|
95 | { |
||
96 | $this['profile.fileSystem.adapter'] = $this->factory(function($c) { |
||
97 | 2 | return new Local(getcwd()); |
|
98 | 44 | }); |
|
99 | |||
100 | $this['profile.fileSystem'] = $this->factory(function($c) { |
||
101 | 41 | return new Filesystem($c['profile.fileSystem.adapter']); |
|
102 | 44 | }); |
|
103 | |||
104 | $this['profile'] = function($c) { |
||
105 | 41 | return new ProfileReader($c['profile.fileSystem']); |
|
106 | }; |
||
107 | 44 | } |
|
108 | |||
109 | 44 | private function initializeSourceFileSystem() |
|
110 | { |
||
111 | $this['sources.fileSystem.adapter'] = $this->factory(function($c) { |
||
112 | |||
113 | 3 | $paths = $c['sources.path']; |
|
114 | |||
115 | 3 | if(! is_array($paths)) |
|
116 | 3 | { |
|
117 | 3 | $paths = array($paths); |
|
118 | 3 | } |
|
119 | |||
120 | 3 | $adapter = new MultipleAdapter(); |
|
121 | |||
122 | 3 | foreach($paths as $path) |
|
123 | { |
||
124 | 3 | $localAdapter = new Local($path); |
|
125 | |||
126 | 3 | if(is_file($path)) |
|
127 | 3 | { |
|
128 | $filename = basename($path); |
||
129 | $path = realpath(dirname($path)); |
||
130 | $localAdapter = new SingleLocalFile($filename, new Local($path)); |
||
131 | } |
||
132 | |||
133 | 3 | $adapter->mount($path, $localAdapter); |
|
134 | 3 | } |
|
135 | |||
136 | 3 | return $adapter; |
|
137 | 44 | }); |
|
138 | |||
139 | $this['target.fileSystem.adapter'] = $this->factory(function($c) { |
||
140 | |||
141 | 4 | if(! empty($c['target.path'])) |
|
142 | 4 | { |
|
143 | $c['hydrator.allowNonDistFilesOverwrite'] = true; |
||
144 | |||
145 | return new Local($c['target.path']); |
||
146 | } |
||
147 | |||
148 | 4 | return $this['sources.fileSystem.adapter']; |
|
149 | 44 | }); |
|
150 | |||
151 | $this['target.fileSystem'] = $this->factory(function($c) { |
||
152 | 14 | return new Filesystem($c['target.fileSystem.adapter']); |
|
153 | 44 | }); |
|
154 | |||
155 | $this['sources.fileSystem'] = $this->factory(function($c) { |
||
156 | 25 | return new Filesystem($c['sources.fileSystem.adapter']); |
|
157 | 44 | }); |
|
158 | |||
159 | $this['sources.fileSystem.finder'] = $this->factory(function($c) { |
||
160 | 17 | return $c['sources.fileSystem']; |
|
161 | 44 | }); |
|
162 | |||
163 | $this['sources.fileSystem.cached'] = $this->factory(function($c) { |
||
164 | 2 | $cache = $c['finder.cache.adapter']; |
|
165 | 2 | $adapter = new Cache( |
|
166 | 2 | $c['sources.fileSystem.adapter'], |
|
167 | 2 | $cache, |
|
168 | 2 | $c['finder.cache.duration'], |
|
169 | $cache |
||
170 | 2 | ); |
|
171 | |||
172 | 2 | return new Filesystem($adapter); |
|
173 | 44 | }); |
|
174 | 44 | } |
|
175 | |||
176 | 44 | private function initializeFinder() |
|
177 | { |
||
178 | 44 | $this['finder.cache.path'] = self::FINDER_CACHE_DIRECTORY; |
|
179 | 44 | $this['finder.cache.duration'] = self::FINDER_CACHE_DURATION; |
|
180 | |||
181 | $this['finder'] = $this->factory(function($c) { |
||
182 | 17 | return new Finder($this['sources.fileSystem.finder']); |
|
183 | 44 | }); |
|
184 | |||
185 | $this['finder.cache.adapter'] = $this->factory(function($c) { |
||
186 | return new Local($c['finder.cache.path'], true); |
||
187 | 44 | }); |
|
188 | 44 | } |
|
189 | |||
190 | 44 | private function initializeVcs() |
|
191 | { |
||
192 | 44 | $this['rootPath'] = getcwd(); |
|
193 | |||
194 | $this['vcs.fileSystem.adapter'] = $this->factory(function($c) { |
||
195 | return new Local($c['rootPath']); |
||
196 | 44 | }); |
|
197 | |||
198 | $this['vcs.fileSystem'] = $this->factory(function($c) { |
||
199 | return new Filesystem($c['vcs.fileSystem.adapter']); |
||
200 | 44 | }); |
|
201 | |||
202 | $this['git.command'] = $this->factory(function($c) { |
||
203 | return new GitWrapperAdapter(); |
||
204 | 44 | }); |
|
205 | |||
206 | $git = function($c) { |
||
207 | return new Git($this['vcs.fileSystem'], $this['rootPath'], $this['git.command']); |
||
208 | 44 | }; |
|
209 | |||
210 | 44 | $this['git'] = $this->factory($git); |
|
211 | 44 | $this['vcs'] = $this->factory($git); |
|
212 | |||
213 | $this['vcsHandler'] = $this->protect(function (Vcs $vcs) { |
||
214 | 2 | $handler = new VcsHandler($vcs, $this['finder']); |
|
215 | |||
216 | 2 | $handler->setLogger($this['logger']) |
|
217 | 2 | ->setSuffix($this['distFiles.suffix']); |
|
218 | |||
219 | 2 | return $handler; |
|
220 | 44 | }); |
|
221 | 44 | } |
|
222 | |||
223 | 44 | private function initializeServices() |
|
267 | } |
||
268 |
PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.
Let’s take a look at an example:
If we look at the
getEmail()
method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:On the hand, if we look at the
setEmail()
, this method _has_ side-effects. In the following case, we could not remove the method call: