Conditions | 5 |
Paths | 12 |
Total Lines | 70 |
Code Lines | 41 |
Lines | 0 |
Ratio | 0 % |
Tests | 22 |
CRAP Score | 5.6116 |
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:
Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.
There are several approaches to avoid long parameter lists:
1 | <?php |
||
26 | 12 | public static function createTwigEnvironment( |
|
27 | Configuration $configuration, |
||
28 | CollectionManager $collectionManager, |
||
29 | DataManager $dataManager, |
||
30 | PageManager $pageManager, |
||
31 | MenuManager $menuManager, |
||
32 | TwigExtension $twigExtension, |
||
33 | EventDispatcherInterface $eventDispatcher, |
||
|
|||
34 | LoggerInterface $logger |
||
35 | ) { |
||
36 | 12 | $fs = new Filesystem(); |
|
37 | 12 | $loader = new TwigFileLoader(array( |
|
38 | 12 | Service::getWorkingDirectory(), |
|
39 | )); |
||
40 | |||
41 | 12 | $theme = $configuration->getTheme(); |
|
42 | |||
43 | // Only load a theme if one is specified and actually exists |
||
44 | 12 | if ($theme !== null) |
|
45 | { |
||
46 | try |
||
47 | { |
||
48 | $loader->addPath($fs->absolutePath('_themes', $theme), 'theme'); |
||
49 | } |
||
50 | catch (\Twig_Error_Loader $e) |
||
51 | { |
||
52 | $logger->error('The following theme could not be loaded: {theme}', array( |
||
53 | 'theme' => $theme, |
||
54 | )); |
||
55 | $logger->error($e->getMessage()); |
||
56 | } |
||
57 | } |
||
58 | |||
59 | 12 | $twig = new Twig_Environment($loader, array( |
|
60 | 12 | 'autoescape' => $configuration->getTwigAutoescape(), |
|
61 | 'auto_reload' => true, |
||
62 | 12 | 'cache' => $fs->absolutePath('.stakx-cache/twig'), |
|
63 | )); |
||
64 | |||
65 | // We'll use this to access the current file in our Twig filters |
||
66 | 12 | $twig->addGlobal('__currentTemplate', ''); |
|
67 | |||
68 | // Global variables maintained by stakx |
||
69 | 12 | $twig->addGlobal('site', $configuration->getConfiguration()); |
|
70 | 12 | $twig->addGlobal('data', $dataManager->getJailedDataItems()); |
|
71 | 12 | $twig->addGlobal('collections', $collectionManager->getJailedCollections()); |
|
72 | 12 | $twig->addGlobal('menu', $menuManager->getSiteMenu()); |
|
73 | 12 | $twig->addGlobal('pages', $pageManager->getJailedStaticPageViews()); |
|
74 | |||
75 | 12 | $twig->addExtension($twigExtension); |
|
76 | |||
77 | 12 | $profiler = null; |
|
78 | |||
79 | 12 | if (Service::getParameter(BuildableCommand::BUILD_PROFILE)) |
|
80 | { |
||
81 | $profiler = new \Twig_Profiler_Profile(); |
||
82 | $twig->addExtension(new \Twig_Extension_Profiler($profiler)); |
||
83 | } |
||
84 | |||
85 | 12 | if ($configuration->isDebug()) |
|
86 | { |
||
87 | $twig->addExtension(new Twig_Extension_Debug()); |
||
88 | $twig->enableDebug(); |
||
89 | } |
||
90 | |||
91 | 12 | $bridge = new TwigStakxBridge($twig); |
|
92 | 12 | $bridge->setProfiler($profiler); |
|
93 | |||
94 | 12 | return $bridge; |
|
95 | } |
||
96 | } |
||
97 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.