Conditions | 7 |
Paths | 9 |
Total Lines | 60 |
Code Lines | 31 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
125 | public function __destruct() |
||
126 | { |
||
127 | if (!isset($this->template)) { |
||
128 | return; |
||
129 | } |
||
130 | |||
131 | if (!isset(self::$theme)) { |
||
132 | self::$theme = 'alxarafe'; |
||
133 | } |
||
134 | |||
135 | if (!isset($this->title)) { |
||
136 | $this->title = 'Alxarafe'; |
||
137 | } |
||
138 | |||
139 | $this->alerts = self::getMessages(); |
||
140 | |||
141 | $vars = ['me' => $this]; |
||
142 | $viewPaths = self::getViewPaths(); |
||
143 | |||
144 | $cachePaths = realpath(constant('BASE_PATH') . '/..') . '/tmp/blade'; |
||
145 | if (!is_dir($cachePaths) && !mkdir($cachePaths, 0777, true) && !is_dir($cachePaths)) { |
||
146 | die('Could not create cache directory for templates: ' . $cachePaths); |
||
|
|||
147 | } |
||
148 | |||
149 | $container = new Container(); |
||
150 | |||
151 | $container->singleton('files', function () { |
||
152 | return new Filesystem(); |
||
153 | }); |
||
154 | |||
155 | $container->singleton('view.finder', function ($app) use ($viewPaths) { |
||
156 | return new FileViewFinder($app['files'], $viewPaths); |
||
157 | }); |
||
158 | |||
159 | $container->singleton('blade.compiler', function ($app) use ($cachePaths) { |
||
160 | return new BladeCompiler($app['files'], $cachePaths); |
||
161 | }); |
||
162 | |||
163 | $container->singleton('view.engine.resolver', function ($app) { |
||
164 | $resolver = new EngineResolver(); |
||
165 | |||
166 | // Register Blade engine |
||
167 | $resolver->register('blade', function () use ($app) { |
||
168 | return new CompilerEngine($app['blade.compiler']); |
||
169 | }); |
||
170 | |||
171 | return $resolver; |
||
172 | }); |
||
173 | |||
174 | $container->singleton('view', function ($app) { |
||
175 | $resolver = $app['view.engine.resolver']; |
||
176 | $finder = $app['view.finder']; |
||
177 | $dispatcher = new Dispatcher($app); |
||
178 | |||
179 | return new Factory($resolver, $finder, $dispatcher); |
||
180 | }); |
||
181 | |||
182 | $viewFactory = $container['view']; |
||
183 | |||
184 | echo $viewFactory->make($this->template, $vars)->render(); |
||
185 | } |
||
246 |
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.