| 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 |
||
| 160 | protected function _getEsiBlock($esiData) { |
||
| 161 | $block = null; |
||
| 162 | Varien_Profiler::start('turpentine::controller::esi::_getEsiBlock'); |
||
| 163 | foreach ($esiData->getSimpleRegistry() as $key => $value) { |
||
| 164 | Mage::register($key, $value, true); |
||
| 165 | } |
||
| 166 | foreach ($esiData->getComplexRegistry() as $key => $data) { |
||
| 167 | $value = Mage::getModel($data['model']); |
||
| 168 | if ( ! is_object($value)) { |
||
| 169 | Mage::helper('turpentine/debug')->logWarn( |
||
| 170 | 'Failed to register key/model: %s as %s(%s)', |
||
| 171 | $key, $data['model'], $data['id'] ); |
||
| 172 | continue; |
||
| 173 | } else { |
||
| 174 | $value->load($data['id']); |
||
| 175 | Mage::register($key, $value, true); |
||
| 176 | } |
||
| 177 | } |
||
| 178 | $layout = Mage::getSingleton('core/layout'); |
||
| 179 | |||
| 180 | // dispatch event for adding handles to layout update |
||
| 181 | Mage::dispatchEvent( |
||
| 182 | 'controller_action_layout_load_before', |
||
| 183 | array('action'=>$this, 'layout'=>$layout) |
||
| 184 | ); |
||
| 185 | |||
| 186 | $layoutUpdate = $layout->getUpdate(); |
||
| 187 | $layoutUpdate->load($this->_swapCustomerHandles( |
||
| 188 | $esiData->getLayoutHandles() )); |
||
| 189 | foreach ($esiData->getDummyBlocks() as $blockName) { |
||
| 190 | $layout->createBlock('Mage_Core_Block_Template', $blockName); |
||
| 191 | } |
||
| 192 | |||
| 193 | if ( ! $this->getFlag('', self::FLAG_NO_DISPATCH_BLOCK_EVENT)) { |
||
| 194 | Mage::dispatchEvent( |
||
| 195 | 'controller_action_layout_generate_xml_before', |
||
| 196 | array('action'=>$this, 'layout'=>$layout) |
||
| 197 | ); |
||
| 198 | } |
||
| 199 | $layout->generateXml(); |
||
| 200 | |||
| 201 | /** @var Nexcessnet_Turpentine_Helper_Data $turpentineHelper */ |
||
| 202 | $turpentineHelper = Mage::helper('turpentine/data') |
||
| 203 | ->setLayout($layout); |
||
| 204 | |||
| 205 | $blockNode = current($layout->getNode()->xpath( |
||
| 206 | sprintf('//block[@name=\'%s\']', $esiData->getNameInLayout()) |
||
| 207 | )); |
||
| 208 | |||
| 209 | if ( ! ($blockNode instanceof Mage_Core_Model_Layout_Element)) { |
||
| 210 | Mage::helper('turpentine/debug')->logWarn( |
||
| 211 | 'No block node found with @name="%s"', |
||
| 212 | $esiData->getNameInLayout() ); |
||
| 213 | return null; |
||
| 214 | } |
||
| 215 | |||
| 216 | $nodesToGenerate = $turpentineHelper->getChildBlockNames($blockNode); |
||
| 217 | Mage::getModel('turpentine/shim_mage_core_layout') |
||
| 218 | ->shim_generateFullBlock($blockNode); |
||
| 219 | |||
| 220 | //find addional blocks that aren't defined in the <block/> but via <reference name="%s"> |
||
| 221 | $referenceNodes = $layout->getNode()->xpath(sprintf( |
||
| 222 | '//reference[@name=\'%s\']', |
||
| 223 | $esiData->getNameInLayout() )); |
||
| 224 | if ($referenceNodes) { |
||
| 225 | foreach ($referenceNodes as $referenceNode) { |
||
| 226 | if ($referenceNode instanceof Mage_Core_Model_Layout_Element) { |
||
| 227 | $referencesToGenerate = $turpentineHelper |
||
| 228 | ->getChildBlockNames($referenceNode); |
||
| 229 | $nodesToGenerate = |
||
| 230 | array_merge($nodesToGenerate, $referencesToGenerate); |
||
| 231 | } |
||
| 232 | } |
||
| 233 | } |
||
| 234 | |||
| 235 | // dispatch event for adding xml layout elements |
||
| 236 | if ( ! $this->getFlag('', self::FLAG_NO_DISPATCH_BLOCK_EVENT)) { |
||
| 237 | Mage::dispatchEvent( |
||
| 238 | 'controller_action_layout_generate_blocks_before', |
||
| 239 | array('action'=>$this, 'layout'=>$layout) |
||
| 240 | ); |
||
| 241 | } |
||
| 242 | |||
| 243 | foreach (array_unique($nodesToGenerate) as $nodeName) { |
||
| 244 | foreach ($layout->getNode()->xpath(sprintf( |
||
| 245 | '//reference[@name=\'%s\']', $nodeName )) as $node) { |
||
| 246 | $layout->generateBlocks($node); |
||
| 247 | } |
||
| 248 | } |
||
| 249 | $block = $layout->getBlock($esiData->getNameInLayout()); |
||
| 250 | |||
| 251 | if ( ! $this->getFlag('', self::FLAG_NO_DISPATCH_BLOCK_EVENT)) { |
||
| 252 | Mage::dispatchEvent( |
||
| 253 | 'controller_action_layout_generate_blocks_after', |
||
| 254 | array('action'=>$this, 'layout'=>$layout) |
||
| 255 | ); |
||
| 256 | } |
||
| 257 | |||
| 258 | $this->_isLayoutLoaded = true; |
||
| 259 | Varien_Profiler::stop('turpentine::controller::esi::_getEsiBlock'); |
||
| 260 | return $block; |
||
| 261 | } |
||
| 262 | |||
| 305 |
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.