| Conditions | 8 |
| Paths | 17 |
| Total Lines | 71 |
| Code Lines | 39 |
| 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 |
||
| 72 | public function __destruct() |
||
| 73 | { |
||
| 74 | if (!isset($this->template)) { |
||
| 75 | return; |
||
| 76 | } |
||
| 77 | |||
| 78 | if (!isset($this->theme)) { |
||
| 79 | $this->theme = 'alxarafe'; |
||
| 80 | } |
||
| 81 | |||
| 82 | if (!isset($this->title)) { |
||
| 83 | $this->title = 'Alxarafe'; |
||
| 84 | } |
||
| 85 | |||
| 86 | $this->alerts = static::getMessages(); |
||
| 87 | |||
| 88 | $vars = ['me' => $this]; |
||
| 89 | $viewPaths = [ |
||
| 90 | constant('APP_PATH') . '/Templates', |
||
| 91 | constant('APP_PATH') . '/Templates/theme/' . $this->theme, |
||
| 92 | constant('APP_PATH') . '/Templates/common', |
||
| 93 | constant('ALX_PATH') . '/Templates', |
||
| 94 | constant('ALX_PATH') . '/Templates/theme/' . $this->theme, |
||
| 95 | constant('ALX_PATH') . '/Templates/common', |
||
| 96 | ]; |
||
| 97 | |||
| 98 | if (isset($this->templatesPath)) { |
||
| 99 | array_unshift($viewPaths, $this->templatesPath); |
||
| 100 | } |
||
| 101 | |||
| 102 | $cachePaths = realpath(constant('BASE_PATH') . '/..') . '/tmp/blade'; |
||
| 103 | if (!is_dir($cachePaths) && !mkdir($cachePaths, 0777, true) && !is_dir($cachePaths)) { |
||
| 104 | die('Could not create cache directory for templates: ' . $cachePaths); |
||
|
|
|||
| 105 | } |
||
| 106 | |||
| 107 | $container = new Container(); |
||
| 108 | |||
| 109 | $container->singleton('files', function () { |
||
| 110 | return new Filesystem(); |
||
| 111 | }); |
||
| 112 | |||
| 113 | $container->singleton('view.finder', function ($app) use ($viewPaths) { |
||
| 114 | return new FileViewFinder($app['files'], $viewPaths); |
||
| 115 | }); |
||
| 116 | |||
| 117 | $container->singleton('blade.compiler', function ($app) use ($cachePaths) { |
||
| 118 | return new BladeCompiler($app['files'], $cachePaths); |
||
| 119 | }); |
||
| 120 | |||
| 121 | $container->singleton('view.engine.resolver', function ($app) { |
||
| 122 | $resolver = new EngineResolver(); |
||
| 123 | |||
| 124 | // Register Blade engine |
||
| 125 | $resolver->register('blade', function () use ($app) { |
||
| 126 | return new CompilerEngine($app['blade.compiler']); |
||
| 127 | }); |
||
| 128 | |||
| 129 | return $resolver; |
||
| 130 | }); |
||
| 131 | |||
| 132 | $container->singleton('view', function ($app) { |
||
| 133 | $resolver = $app['view.engine.resolver']; |
||
| 134 | $finder = $app['view.finder']; |
||
| 135 | $dispatcher = new Dispatcher($app); |
||
| 136 | |||
| 137 | return new Factory($resolver, $finder, $dispatcher); |
||
| 138 | }); |
||
| 139 | |||
| 140 | $viewFactory = $container['view']; |
||
| 141 | |||
| 142 | echo $viewFactory->make($this->template, $vars)->render(); |
||
| 143 | } |
||
| 170 |
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.