Conditions | 15 |
Paths | 132 |
Total Lines | 94 |
Code Lines | 59 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
Bugs | 3 | 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 |
||
167 | protected function _getEsiBlock($esiData) { |
||
168 | $block = null; |
||
169 | Varien_Profiler::start('turpentine::controller::esi::_getEsiBlock'); |
||
170 | foreach ($esiData->getSimpleRegistry() as $key => $value) { |
||
171 | Mage::register($key, $value, true); |
||
172 | } |
||
173 | foreach ($esiData->getComplexRegistry() as $key => $data) { |
||
174 | $value = Mage::getModel($data['model']); |
||
175 | if ( ! is_object($value)) { |
||
176 | Mage::helper('turpentine/debug')->logWarn( |
||
177 | 'Failed to register key/model: %s as %s(%s)', |
||
178 | $key, $data['model'], $data['id'] ); |
||
179 | continue; |
||
180 | } else { |
||
181 | $value->load($data['id']); |
||
182 | Mage::register($key, $value, true); |
||
183 | } |
||
184 | } |
||
185 | |||
186 | |||
187 | /** @var Mage_Core_Model_Layout $layout */ |
||
188 | $layout = Mage::getSingleton('core/layout'); |
||
189 | $layout->getUpdate()->addHandle( |
||
190 | $this->_swapCustomerHandles( |
||
191 | $esiData->getLayoutHandles() |
||
192 | ) |
||
193 | ); |
||
194 | $this->loadLayoutUpdates(); |
||
195 | |||
196 | foreach ($esiData->getDummyBlocks() as $blockName) { |
||
197 | $layout->createBlock('Mage_Core_Block_Template', $blockName); |
||
198 | } |
||
199 | |||
200 | $this->generateLayoutXml(); |
||
201 | |||
202 | /** @var Nexcessnet_Turpentine_Helper_Data $turpentineHelper */ |
||
203 | $turpentineHelper = Mage::helper('turpentine/data') |
||
204 | ->setLayout($layout); |
||
205 | |||
206 | $blockNode = current($layout->getNode()->xpath( |
||
207 | sprintf('//block[@name=\'%s\']', $esiData->getNameInLayout()) |
||
208 | )); |
||
209 | |||
210 | if ( ! ($blockNode instanceof Mage_Core_Model_Layout_Element)) { |
||
211 | Mage::helper('turpentine/debug')->logWarn( |
||
212 | 'No block node found with @name="%s"', |
||
213 | $esiData->getNameInLayout() ); |
||
214 | return null; |
||
215 | } |
||
216 | |||
217 | $nodesToGenerate = $turpentineHelper->getChildBlockNames($blockNode); |
||
218 | Mage::getModel('turpentine/shim_mage_core_layout') |
||
219 | ->shim_generateFullBlock($blockNode); |
||
220 | |||
221 | //find addional blocks that aren't defined in the <block/> but via <reference name="%s"> |
||
222 | $referenceNodes = $layout->getNode()->xpath(sprintf( |
||
223 | '//reference[@name=\'%s\']', |
||
224 | $esiData->getNameInLayout() )); |
||
225 | if ($referenceNodes) { |
||
226 | foreach ($referenceNodes as $referenceNode) { |
||
227 | if ($referenceNode instanceof Mage_Core_Model_Layout_Element) { |
||
228 | $referencesToGenerate = $turpentineHelper |
||
229 | ->getChildBlockNames($referenceNode); |
||
230 | $nodesToGenerate = |
||
231 | array_merge($nodesToGenerate, $referencesToGenerate); |
||
232 | } |
||
233 | } |
||
234 | } |
||
235 | |||
236 | // Global blocks to generate |
||
237 | $globalBlocks = array('formkey'); |
||
238 | |||
239 | // Add ignore attribute to all nodes that don't need to be generated |
||
240 | foreach ($layout->getNode() as $node) { |
||
241 | $attributes = $node->attributes(); |
||
242 | if ((bool)$attributes->ignore) { |
||
243 | continue; |
||
244 | } elseif ($node->getName() == 'block' && !in_array($attributes->name, $globalBlocks)) { |
||
245 | $node->addAttribute('ignore', true); |
||
246 | } elseif ($node->getName() == 'reference' && !in_array($attributes->name, $nodesToGenerate)) { |
||
247 | $node->addAttribute('ignore', true); |
||
248 | } |
||
249 | } |
||
250 | |||
251 | // Generate layout block that aren't ignored |
||
252 | $this->generateLayoutBlocks(); |
||
253 | |||
254 | // Get the requested ESI block |
||
255 | $block = $layout->getBlock($esiData->getNameInLayout()); |
||
256 | |||
257 | $this->_isLayoutLoaded = true; |
||
258 | Varien_Profiler::stop('turpentine::controller::esi::_getEsiBlock'); |
||
259 | return $block; |
||
260 | } |
||
261 | |||
284 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.