Conditions | 1 |
Paths | 1 |
Total Lines | 81 |
Code Lines | 48 |
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 |
||
71 | public function run() |
||
72 | { |
||
73 | // For debugger |
||
74 | $this->addTimer('<i>Application</i>'); |
||
75 | |||
76 | // Create fresh response |
||
77 | $timer = $this->addTimer('Create response'); |
||
78 | $response = new Ajde_Http_Response(); |
||
79 | $this->setResponse($response); |
||
|
|||
80 | $this->endTimer($timer); |
||
81 | |||
82 | Ajde_Event::trigger($this, 'onAfterResponseCreated'); |
||
83 | |||
84 | // Bootstrap init |
||
85 | $timer = $this->addTimer('Run bootstrap queue'); |
||
86 | $bootstrap = new Ajde_Core_Bootstrap(); |
||
87 | $bootstrap->run(); |
||
88 | $this->endTimer($timer); |
||
89 | |||
90 | Ajde_Event::trigger($this, 'onAfterBootstrap'); |
||
91 | |||
92 | // Get request |
||
93 | $timer = $this->addTimer('Read in global request'); |
||
94 | $request = $this->loadRequest(); |
||
95 | $this->endTimer($timer); |
||
96 | |||
97 | Ajde_Event::trigger($this, 'onAfterRequestCreated'); |
||
98 | |||
99 | // Get route |
||
100 | $timer = $this->addTimer('Initialize route'); |
||
101 | $route = $request->initRoute(); |
||
102 | $this->setRoute($route); |
||
103 | $this->endTimer($timer); |
||
104 | |||
105 | Ajde_Event::trigger($this, 'onAfterRouteInitialized'); |
||
106 | |||
107 | // Load document |
||
108 | $timer = $this->addTimer('Create document'); |
||
109 | $document = Ajde_Document::fromRoute($route); |
||
110 | $this->setDocument($document); |
||
111 | $this->endTimer($timer); |
||
112 | |||
113 | Ajde_Event::trigger($this, 'onAfterDocumentCreated'); |
||
114 | |||
115 | // Load controller |
||
116 | $timer = $this->addTimer('Load controller'); |
||
117 | $controller = Ajde_Controller::fromRoute($route); |
||
118 | $this->setController($controller); |
||
119 | $this->endTimer($timer); |
||
120 | |||
121 | Ajde_Event::trigger($this, 'onAfterControllerCreated'); |
||
122 | |||
123 | // Invoke controller action |
||
124 | $timer = $this->addTimer('Invoke controller'); |
||
125 | $actionResult = $controller->invoke(); |
||
126 | $document->setBody($actionResult); |
||
127 | $this->endTimer($timer); |
||
128 | |||
129 | Ajde_Event::trigger($this, 'onAfterControllerInvoked'); |
||
130 | |||
131 | // Get document contents |
||
132 | $timer = $this->addTimer('Render document'); |
||
133 | $contents = $document->render(); |
||
134 | $this->endTimer($timer); |
||
135 | |||
136 | Ajde_Event::trigger($this, 'onAfterDocumentRendered'); |
||
137 | |||
138 | // Let the cache handle the contents and have it saved to the response |
||
139 | $timer = $this->addTimer('Save to response'); |
||
140 | $cache = Ajde_Cache::getInstance(); |
||
141 | $cache->setContents($contents); |
||
142 | $cache->saveResponse(); |
||
143 | $this->endTimer($timer); |
||
144 | |||
145 | Ajde_Event::trigger($this, 'onAfterResponseSaved'); |
||
146 | |||
147 | // Output the buffer |
||
148 | $response->send(); |
||
149 | |||
150 | Ajde_Event::trigger($this, 'onAfterResponseSent'); |
||
151 | } |
||
152 | |||
229 |
If you implement
__call
and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__call
is implemented by a parent class and only the child class knows which methods exist: