Conditions | 2 |
Paths | 1 |
Total Lines | 65 |
Code Lines | 40 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
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 |
||
23 | public function __construct (array $urlParams = array()) { |
||
24 | parent::__construct('documents', $urlParams); |
||
25 | |||
26 | $container = $this->getContainer(); |
||
27 | |||
28 | /** |
||
29 | * Controllers |
||
30 | */ |
||
31 | $container->registerService('UserController', function($c) { |
||
32 | return new UserController( |
||
33 | $c->query('AppName'), |
||
34 | $c->query('Request') |
||
35 | ); |
||
36 | }); |
||
37 | $container->registerService('SessionController', function($c) { |
||
38 | return new SessionController( |
||
39 | $c->query('AppName'), |
||
40 | $c->query('Request'), |
||
41 | $c->query('Logger'), |
||
42 | $c->query('UserId') |
||
43 | ); |
||
44 | }); |
||
45 | $container->registerService('DocumentController', function($c) { |
||
46 | return new DocumentController( |
||
47 | $c->query('AppName'), |
||
48 | $c->query('Request'), |
||
49 | $c->query('CoreConfig'), |
||
50 | $c->query('L10N'), |
||
51 | $c->query('UserId') |
||
52 | ); |
||
53 | }); |
||
54 | $container->registerService('SettingsController', function($c) { |
||
55 | return new SettingsController( |
||
56 | $c->query('AppName'), |
||
57 | $c->query('Request'), |
||
58 | $c->query('L10N'), |
||
59 | $c->query('AppConfig'), |
||
60 | $c->query('UserId') |
||
61 | ); |
||
62 | }); |
||
63 | |||
64 | $container->registerService('AppConfig', function($c) { |
||
65 | return new AppConfig( |
||
66 | $c->query('CoreConfig') |
||
67 | ); |
||
68 | }); |
||
69 | |||
70 | /** |
||
71 | * Core |
||
72 | */ |
||
73 | $container->registerService('Logger', function($c) { |
||
74 | return $c->query('ServerContainer')->getLogger(); |
||
75 | }); |
||
76 | $container->registerService('CoreConfig', function($c) { |
||
77 | return $c->query('ServerContainer')->getConfig(); |
||
78 | }); |
||
79 | $container->registerService('L10N', function($c) { |
||
80 | return $c->query('ServerContainer')->getL10N($c->query('AppName')); |
||
81 | }); |
||
82 | $container->registerService('UserId', function($c) { |
||
83 | $user = $c->query('ServerContainer')->getUserSession()->getUser(); |
||
84 | $uid = is_null($user) ? '' : $user->getUID(); |
||
85 | return $uid; |
||
86 | }); |
||
87 | } |
||
88 | } |
||
89 |