| Conditions | 6 |
| Paths | 16 |
| Total Lines | 52 |
| Code Lines | 33 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 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 |
||
| 33 | public function __construct(Builder $builder, $templatesPath) |
||
| 34 | { |
||
| 35 | // load layouts |
||
| 36 | $loader = new \Twig\Loader\FilesystemLoader($templatesPath); |
||
| 37 | // default options |
||
| 38 | $loaderOptions = [ |
||
| 39 | 'debug' => $builder->isDebug(), |
||
| 40 | 'strict_variables' => true, |
||
| 41 | 'autoescape' => false, |
||
| 42 | 'auto_reload' => true, |
||
| 43 | 'cache' => false, |
||
| 44 | ]; |
||
| 45 | // use Twig cache? |
||
| 46 | if ($builder->getConfig()->get('cache.templates.enabled')) { |
||
| 47 | $templatesCachePath = \Cecil\Util::joinFile( |
||
| 48 | $builder->getConfig()->getCachePath(), |
||
| 49 | (string) $builder->getConfig()->get('cache.templates.dir') |
||
| 50 | ); |
||
| 51 | $loaderOptions = array_replace($loaderOptions, ['cache' => $templatesCachePath]); |
||
| 52 | } |
||
| 53 | // create the Twig instance |
||
| 54 | $this->twig = new \Twig\Environment($loader, $loaderOptions); |
||
| 55 | // set date format & timezone |
||
| 56 | $this->twig->getExtension(\Twig\Extension\CoreExtension::class) |
||
| 57 | ->setDateFormat($builder->getConfig()->get('date.format')); |
||
| 58 | $this->twig->getExtension(\Twig\Extension\CoreExtension::class) |
||
| 59 | ->setTimezone($builder->getConfig()->get('date.timezone')); |
||
| 60 | // adds extensions |
||
| 61 | $this->twig->addExtension(new TwigExtension($builder)); |
||
| 62 | $this->twig->addExtension(new \Twig\Extension\StringLoaderExtension()); |
||
| 63 | // internationalisation |
||
| 64 | if (extension_loaded('intl')) { |
||
| 65 | $this->twig->addExtension(new \Twig_Extensions_Extension_Intl()); |
||
| 66 | $this->twig->registerUndefinedFilterCallback(function ($name) { |
||
| 67 | switch ($name) { |
||
| 68 | case 'localizeddate': |
||
| 69 | return new \Twig\TwigFilter($name, 'date'); |
||
| 70 | break; |
||
|
|
|||
| 71 | } |
||
| 72 | |||
| 73 | return false; |
||
| 74 | }); |
||
| 75 | } |
||
| 76 | if (extension_loaded('gettext')) { |
||
| 77 | $this->twig->addExtension(new \Twig_Extensions_Extension_I18n()); |
||
| 78 | } |
||
| 79 | if ($builder->isDebug()) { |
||
| 80 | // dump() |
||
| 81 | $this->twig->addExtension(new \Twig\Extension\DebugExtension()); |
||
| 82 | // profiler |
||
| 83 | $this->profile = new \Twig\Profiler\Profile(); |
||
| 84 | $this->twig->addExtension(new \Twig\Extension\ProfilerExtension($this->profile)); |
||
| 85 | } |
||
| 104 |
The
breakstatement is not necessary if it is preceded for example by areturnstatement:If you would like to keep this construct to be consistent with other
casestatements, you can safely mark this issue as a false-positive.