| Conditions | 14 |
| Paths | 600 |
| Total Lines | 102 |
| Code Lines | 67 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 2 | 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 | $layout = Mage::getSingleton('core/layout'); |
||
| 186 | |||
| 187 | // dispatch event for adding handles to layout update |
||
| 188 | Mage::dispatchEvent( |
||
| 189 | 'controller_action_layout_load_before', |
||
| 190 | array('action'=>$this, 'layout'=>$layout) |
||
| 191 | ); |
||
| 192 | |||
| 193 | $layoutUpdate = $layout->getUpdate(); |
||
| 194 | $layoutUpdate->load($this->_swapCustomerHandles( |
||
| 195 | $esiData->getLayoutHandles() )); |
||
| 196 | foreach ($esiData->getDummyBlocks() as $blockName) { |
||
| 197 | $layout->createBlock('Mage_Core_Block_Template', $blockName); |
||
| 198 | } |
||
| 199 | |||
| 200 | if ( ! $this->getFlag('', self::FLAG_NO_DISPATCH_BLOCK_EVENT)) { |
||
| 201 | Mage::dispatchEvent( |
||
| 202 | 'controller_action_layout_generate_xml_before', |
||
| 203 | array('action'=>$this, 'layout'=>$layout) |
||
| 204 | ); |
||
| 205 | } |
||
| 206 | $layout->generateXml(); |
||
| 207 | |||
| 208 | /** @var Nexcessnet_Turpentine_Helper_Data $turpentineHelper */ |
||
| 209 | $turpentineHelper = Mage::helper('turpentine/data') |
||
| 210 | ->setLayout($layout); |
||
| 211 | |||
| 212 | $blockNode = current($layout->getNode()->xpath( |
||
| 213 | sprintf('//block[@name=\'%s\']', $esiData->getNameInLayout()) |
||
| 214 | )); |
||
| 215 | |||
| 216 | if ( ! ($blockNode instanceof Mage_Core_Model_Layout_Element)) { |
||
| 217 | Mage::helper('turpentine/debug')->logWarn( |
||
| 218 | 'No block node found with @name="%s"', |
||
| 219 | $esiData->getNameInLayout() ); |
||
| 220 | return null; |
||
| 221 | } |
||
| 222 | |||
| 223 | $nodesToGenerate = $turpentineHelper->getChildBlockNames($blockNode); |
||
| 224 | Mage::getModel('turpentine/shim_mage_core_layout') |
||
| 225 | ->shim_generateFullBlock($blockNode); |
||
| 226 | |||
| 227 | //find addional blocks that aren't defined in the <block/> but via <reference name="%s"> |
||
| 228 | $referenceNodes = $layout->getNode()->xpath(sprintf( |
||
| 229 | '//reference[@name=\'%s\']', |
||
| 230 | $esiData->getNameInLayout() )); |
||
| 231 | if ($referenceNodes) { |
||
| 232 | foreach ($referenceNodes as $referenceNode) { |
||
| 233 | if ($referenceNode instanceof Mage_Core_Model_Layout_Element) { |
||
| 234 | $referencesToGenerate = $turpentineHelper |
||
| 235 | ->getChildBlockNames($referenceNode); |
||
| 236 | $nodesToGenerate = |
||
| 237 | array_merge($nodesToGenerate, $referencesToGenerate); |
||
| 238 | } |
||
| 239 | } |
||
| 240 | } |
||
| 241 | |||
| 242 | // dispatch event for adding xml layout elements |
||
| 243 | if ( ! $this->getFlag('', self::FLAG_NO_DISPATCH_BLOCK_EVENT)) { |
||
| 244 | Mage::dispatchEvent( |
||
| 245 | 'controller_action_layout_generate_blocks_before', |
||
| 246 | array('action'=>$this, 'layout'=>$layout) |
||
| 247 | ); |
||
| 248 | } |
||
| 249 | |||
| 250 | foreach (array_unique($nodesToGenerate) as $nodeName) { |
||
| 251 | foreach ($layout->getNode()->xpath(sprintf( |
||
| 252 | '//reference[@name=\'%s\']', $nodeName )) as $node) { |
||
| 253 | $layout->generateBlocks($node); |
||
| 254 | } |
||
| 255 | } |
||
| 256 | $block = $layout->getBlock($esiData->getNameInLayout()); |
||
| 257 | |||
| 258 | if ( ! $this->getFlag('', self::FLAG_NO_DISPATCH_BLOCK_EVENT)) { |
||
| 259 | Mage::dispatchEvent( |
||
| 260 | 'controller_action_layout_generate_blocks_after', |
||
| 261 | array('action'=>$this, 'layout'=>$layout) |
||
| 262 | ); |
||
| 263 | } |
||
| 264 | |||
| 265 | $this->_isLayoutLoaded = true; |
||
| 266 | Varien_Profiler::stop('turpentine::controller::esi::_getEsiBlock'); |
||
| 267 | return $block; |
||
| 268 | } |
||
| 269 | |||
| 292 |
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.