Conditions | 3 |
Paths | 1 |
Total Lines | 57 |
Code Lines | 30 |
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 |
||
35 | private function initializeServices() |
||
36 | { |
||
37 | $this['configuration'] = function($c) { |
||
38 | |||
39 | $configuration = array(); |
||
40 | |||
41 | $filename = '.solidifier.yml'; |
||
42 | $fs = $c['filesystem']; |
||
43 | |||
44 | if($fs->has($filename)) |
||
45 | { |
||
46 | $configuration = Yaml::parse($fs->read($filename)); |
||
47 | } |
||
48 | |||
49 | return $configuration; |
||
50 | }; |
||
51 | |||
52 | $this['event.dispatcher'] = function($c) { |
||
53 | return new EventDispatcher(); |
||
54 | }; |
||
55 | |||
56 | $this['dispatcher'] = function($c) { |
||
57 | return new Dispatchers\EventDispatcher($c['event.dispatcher']); |
||
58 | }; |
||
59 | |||
60 | $this['analyzer'] = function($c) { |
||
61 | $analyzer = new Analyzers\Analyzer($c['dispatcher'], $c['filesystem']); |
||
62 | |||
63 | $handler = new ConfigurationHandler($c['configuration'], $c['objectTypes.list']); |
||
64 | $handler->configure($analyzer); |
||
65 | |||
66 | return $analyzer; |
||
67 | }; |
||
68 | |||
69 | $this['twig.path'] = 'views'; |
||
70 | $this['twig.cache'] = false; |
||
71 | $this['twig.debug'] = true; |
||
72 | |||
73 | $this['twig'] = function($c) { |
||
74 | $loader = new \Twig_Loader_Filesystem($c['twig.path']); |
||
75 | $twig = new \Twig_Environment($loader, array( |
||
76 | 'cache' => $c['twig.cache'], |
||
77 | 'debug' => $c['twig.debug'], |
||
78 | )); |
||
79 | |||
80 | if($c['twig.debug'] === true) |
||
81 | { |
||
82 | $twig->addExtension(new \Twig_Extension_Debug()); |
||
83 | } |
||
84 | |||
85 | return $twig; |
||
86 | }; |
||
87 | |||
88 | $this['objectTypes.list'] = function($c) { |
||
89 | return new ObjectTypes(); |
||
90 | }; |
||
91 | } |
||
92 | |||
107 | } |
PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.
Let’s take a look at an example:
If we look at the
getEmail()
method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:On the hand, if we look at the
setEmail()
, this method _has_ side-effects. In the following case, we could not remove the method call: