| Conditions | 13 |
| Paths | 32 |
| Total Lines | 80 |
| Code Lines | 48 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 7 | ||
| Bugs | 3 | Features | 1 |
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 |
||
| 45 | public function __construct(Builder $builder, $templatesPath) |
||
| 46 | { |
||
| 47 | $this->builder = $builder; |
||
| 48 | // load layouts |
||
| 49 | $loader = new \Twig\Loader\FilesystemLoader($templatesPath); |
||
| 50 | // default options |
||
| 51 | $loaderOptions = [ |
||
| 52 | 'debug' => $this->builder->isDebug(), |
||
| 53 | 'strict_variables' => true, |
||
| 54 | 'autoescape' => false, |
||
| 55 | 'auto_reload' => true, |
||
| 56 | 'cache' => false, |
||
| 57 | ]; |
||
| 58 | // use Twig cache? |
||
| 59 | if ($this->builder->getConfig()->get('cache.templates.enabled')) { |
||
| 60 | $loaderOptions = array_replace($loaderOptions, ['cache' => $this->builder->getConfig()->getCacheTemplatesPath()]); |
||
| 61 | } |
||
| 62 | // create the Twig instance |
||
| 63 | $this->twig = new \Twig\Environment($loader, $loaderOptions); |
||
| 64 | // set date format |
||
| 65 | $this->twig->getExtension(\Twig\Extension\CoreExtension::class) |
||
| 66 | ->setDateFormat($this->builder->getConfig()->get('date.format')); |
||
| 67 | // set timezone |
||
| 68 | if ($this->builder->getConfig()->has('date.timezone')) { |
||
| 69 | $this->twig->getExtension(\Twig\Extension\CoreExtension::class) |
||
| 70 | ->setTimezone($this->builder->getConfig()->get('date.timezone')); |
||
| 71 | } |
||
| 72 | // adds extensions |
||
| 73 | $this->twig->addExtension(new TwigExtension($this->builder)); |
||
| 74 | $this->twig->addExtension(new \Twig\Extension\StringLoaderExtension()); |
||
| 75 | // l10n |
||
| 76 | $this->translator = new Translator( |
||
| 77 | $this->builder->getConfig()->getLanguageProperty('locale'), |
||
| 78 | new MessageFormatter(new IdentityTranslator()), |
||
| 79 | $this->builder->getConfig()->get('cache.templates.enabled') ? $this->builder->getConfig()->getCacheTranslationsPath() : null, |
||
| 80 | $this->builder->isDebug() |
||
| 81 | ); |
||
| 82 | if ($this->builder->getConfig()->getLanguages()) { |
||
| 83 | foreach ($this->builder->getConfig()->get('translations.formats') as $format) { |
||
| 84 | $loader = \sprintf('Symfony\Component\Translation\Loader\%sFileLoader', ucfirst($format)); |
||
| 85 | if (class_exists($loader)) { |
||
| 86 | $this->translator->addLoader($format, new $loader()); |
||
| 87 | $this->builder->getLogger()->debug(\sprintf('Translation loader for format "%s" found.', $format)); |
||
| 88 | } |
||
| 89 | } |
||
| 90 | foreach ($this->builder->getConfig()->getLanguages() as $lang) { |
||
| 91 | // themes |
||
| 92 | if ($themes = $this->builder->getConfig()->getTheme()) { |
||
| 93 | foreach ($themes as $theme) { |
||
| 94 | $this->addTransResource($this->builder->getConfig()->getThemeDirPath($theme, 'translations'), $lang['locale']); |
||
| 95 | } |
||
| 96 | } |
||
| 97 | // site |
||
| 98 | $this->addTransResource($this->builder->getConfig()->getTranslationsPath(), $lang['locale']); |
||
| 99 | } |
||
| 100 | } |
||
| 101 | $this->twig->addExtension(new TranslationExtension($this->translator)); |
||
| 102 | // intl |
||
| 103 | $this->twig->addExtension(new IntlExtension()); |
||
| 104 | if (extension_loaded('intl')) { |
||
| 105 | $this->builder->getLogger()->debug('Intl extension is loaded'); |
||
| 106 | } |
||
| 107 | // filters fallback |
||
| 108 | $this->twig->registerUndefinedFilterCallback(function ($name) { |
||
| 109 | switch ($name) { |
||
| 110 | case 'localizeddate': |
||
| 111 | return new \Twig\TwigFilter($name, function (\DateTime $value = null) { |
||
| 112 | return date((string) $this->builder->getConfig()->get('date.format'), $value->getTimestamp()); |
||
|
|
|||
| 113 | }); |
||
| 114 | } |
||
| 115 | |||
| 116 | return false; |
||
| 117 | }); |
||
| 118 | // debug |
||
| 119 | if ($this->builder->isDebug()) { |
||
| 120 | // dump() |
||
| 121 | $this->twig->addExtension(new \Twig\Extension\DebugExtension()); |
||
| 122 | // profiler |
||
| 123 | $this->profile = new \Twig\Profiler\Profile(); |
||
| 124 | $this->twig->addExtension(new \Twig\Extension\ProfilerExtension($this->profile)); |
||
| 125 | } |
||
| 177 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.