Conditions | 9 |
Paths | 16 |
Total Lines | 74 |
Code Lines | 44 |
Lines | 0 |
Ratio | 0 % |
Tests | 35 |
CRAP Score | 9.0397 |
Changes | 6 | ||
Bugs | 2 | 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 |
||
43 | 1 | public function __construct(Builder $builder, $templatesPath) |
|
44 | { |
||
45 | // load layouts |
||
46 | 1 | $loader = new \Twig\Loader\FilesystemLoader($templatesPath); |
|
47 | // default options |
||
48 | $loaderOptions = [ |
||
49 | 1 | 'debug' => $builder->isDebug(), |
|
50 | 'strict_variables' => true, |
||
51 | 'autoescape' => false, |
||
52 | 'auto_reload' => true, |
||
53 | 'cache' => false, |
||
54 | ]; |
||
55 | // use Twig cache? |
||
56 | 1 | if ($builder->getConfig()->get('cache.templates.enabled')) { |
|
57 | 1 | $templatesCachePath = \Cecil\Util::joinFile( |
|
58 | 1 | $builder->getConfig()->getCachePath(), |
|
59 | 1 | (string) $builder->getConfig()->get('cache.templates.dir') |
|
60 | ); |
||
61 | 1 | $loaderOptions = array_replace($loaderOptions, ['cache' => $templatesCachePath]); |
|
62 | } |
||
63 | // create the Twig instance |
||
64 | 1 | $this->twig = new \Twig\Environment($loader, $loaderOptions); |
|
65 | // set date format |
||
66 | 1 | $this->twig->getExtension(\Twig\Extension\CoreExtension::class) |
|
67 | 1 | ->setDateFormat($builder->getConfig()->get('date.format')); |
|
68 | // set timezone |
||
69 | 1 | if ($builder->getConfig()->has('date.timezone')) { |
|
70 | $this->twig->getExtension(\Twig\Extension\CoreExtension::class) |
||
71 | ->setTimezone($builder->getConfig()->get('date.timezone')); |
||
72 | } |
||
73 | // adds extensions |
||
74 | 1 | $this->twig->addExtension(new TwigExtension($builder)); |
|
75 | 1 | $this->twig->addExtension(new \Twig\Extension\StringLoaderExtension()); |
|
76 | // i18n |
||
77 | 1 | $this->twig->addExtension(new IntlExtension()); |
|
78 | // filters fallback |
||
79 | 1 | $this->twig->registerUndefinedFilterCallback(function ($name) use ($builder) { |
|
80 | switch ($name) { |
||
81 | 1 | case 'localizeddate': |
|
82 | 1 | return new \Twig\TwigFilter($name, function (\DateTime $value = null) use ($builder) { |
|
83 | 1 | return date((string) $builder->getConfig()->get('date.format'), $value->getTimestamp()); |
|
|
|||
84 | }); |
||
85 | } |
||
86 | |||
87 | return false; |
||
88 | }); |
||
89 | // l10n |
||
90 | 1 | if (count($builder->getConfig()->getLanguages()) > 1) { |
|
91 | 1 | $this->translator = new Translator( |
|
92 | 1 | $builder->getConfig()->getLanguageProperty('locale'), |
|
93 | 1 | new MessageFormatter(new IdentityTranslator()), |
|
94 | 1 | Util::joinFile($builder->getConfig()->getCachePath(), 'translations'), |
|
95 | 1 | $builder->isDebug() |
|
96 | ); |
||
97 | 1 | $this->translator->addLoader('mo', new MoFileLoader()); |
|
98 | 1 | foreach ($builder->getConfig()->getLanguages() as $lang) { |
|
99 | 1 | // themes |
|
100 | 1 | if ($themes = $builder->getConfig()->getTheme()) { |
|
101 | 1 | foreach ($themes as $theme) { |
|
102 | $this->addTransResource($builder->getConfig()->getThemeDirPath($theme, 'translations'), $lang['locale']); |
||
103 | } |
||
104 | 1 | } |
|
105 | // site |
||
106 | $this->addTransResource($builder->getConfig()->getTranslationsPath(), $lang['locale']); |
||
107 | 1 | } |
|
108 | $this->twig->addExtension(new TranslationExtension($this->translator)); |
||
109 | 1 | } |
|
110 | // debug |
||
111 | 1 | if ($builder->isDebug()) { |
|
112 | 1 | // dump() |
|
113 | $this->twig->addExtension(new \Twig\Extension\DebugExtension()); |
||
114 | // profiler |
||
115 | $this->profile = new \Twig\Profiler\Profile(); |
||
116 | $this->twig->addExtension(new \Twig\Extension\ProfilerExtension($this->profile)); |
||
117 | } |
||
156 |
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.