| Conditions | 17 |
| Paths | 1176 |
| Total Lines | 112 |
| 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 |
||
| 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 | Mage::getSingleton('core/design_package') |
||
| 187 | ->setPackageName($esiData->getDesignPackage()) |
||
| 188 | ->setTheme($esiData->getDesignTheme()); |
||
| 189 | |||
| 190 | // dispatch event for adding handles to layout update |
||
| 191 | Mage::dispatchEvent( |
||
| 192 | 'controller_action_layout_load_before', |
||
| 193 | array('action'=>$this, 'layout'=>$layout) |
||
| 194 | ); |
||
| 195 | |||
| 196 | $layoutUpdate = $layout->getUpdate(); |
||
| 197 | $layoutUpdate->load($this->_swapCustomerHandles( |
||
| 198 | $esiData->getLayoutHandles() )); |
||
| 199 | foreach ($esiData->getDummyBlocks() as $blockName) { |
||
| 200 | $layout->createBlock('Mage_Core_Block_Template', $blockName); |
||
| 201 | } |
||
| 202 | |||
| 203 | if ( ! $this->getFlag('', self::FLAG_NO_DISPATCH_BLOCK_EVENT)) { |
||
| 204 | Mage::dispatchEvent( |
||
| 205 | 'controller_action_layout_generate_xml_before', |
||
| 206 | array('action'=>$this, 'layout'=>$layout) |
||
| 207 | ); |
||
| 208 | } |
||
| 209 | $layout->generateXml(); |
||
| 210 | |||
| 211 | /** @var Nexcessnet_Turpentine_Helper_Data $turpentineHelper */ |
||
| 212 | $turpentineHelper = Mage::helper('turpentine/data') |
||
| 213 | ->setLayout($layout); |
||
| 214 | |||
| 215 | $blockNode = Mage::helper('turpentine/esi')->getEsiLayoutBlockNode( |
||
| 216 | $layout, $esiData->getNameInLayout()); |
||
| 217 | if ( ! ($blockNode instanceof Mage_Core_Model_Layout_Element)) { |
||
| 218 | Mage::helper('turpentine/debug')->logWarn( |
||
| 219 | 'No block node found with @name="%s"', |
||
| 220 | $esiData->getNameInLayout() ); |
||
| 221 | return null; |
||
| 222 | } |
||
| 223 | |||
| 224 | $nodesToGenerate = $turpentineHelper->getChildBlockNames($blockNode); |
||
| 225 | Mage::getModel('turpentine/shim_mage_core_layout') |
||
| 226 | ->shim_generateFullBlock($blockNode); |
||
| 227 | |||
| 228 | //find addional blocks that aren't defined in the <block/> but via <reference name="%s"> |
||
| 229 | $referenceNodes = $layout->getNode()->xpath(sprintf( |
||
| 230 | '//reference[@name=\'%s\']', |
||
| 231 | $esiData->getNameInLayout() )); |
||
| 232 | if ($referenceNodes) { |
||
| 233 | foreach ($referenceNodes as $referenceNode) { |
||
| 234 | if ($referenceNode instanceof Mage_Core_Model_Layout_Element) { |
||
| 235 | $referencesToGenerate = $turpentineHelper |
||
| 236 | ->getChildBlockNames($referenceNode); |
||
| 237 | $nodesToGenerate = |
||
| 238 | array_merge($nodesToGenerate, $referencesToGenerate); |
||
| 239 | } |
||
| 240 | } |
||
| 241 | } |
||
| 242 | |||
| 243 | // dispatch event for adding xml layout elements |
||
| 244 | if ( ! $this->getFlag('', self::FLAG_NO_DISPATCH_BLOCK_EVENT)) { |
||
| 245 | Mage::dispatchEvent( |
||
| 246 | 'controller_action_layout_generate_blocks_before', |
||
| 247 | array('action'=>$this, 'layout'=>$layout) |
||
| 248 | ); |
||
| 249 | } |
||
| 250 | |||
| 251 | foreach (array_unique($nodesToGenerate) as $nodeName) { |
||
| 252 | foreach ($layout->getNode()->xpath(sprintf( |
||
| 253 | '//reference[@name=\'%s\']', $nodeName )) as $node) { |
||
| 254 | $layout->generateBlocks($node); |
||
| 255 | } |
||
| 256 | } |
||
| 257 | if ($roots = $layout->getNode()->xpath('//block[@name=\'root\']')) { |
||
| 258 | foreach (array('formkey') as $globalBlock) { |
||
| 259 | if ($blocks = $layout->getNode()->xpath(sprintf('//block[@name=\'%s\']', $globalBlock))) { |
||
| 260 | $dummy = $roots[0]->addChild('reference'); |
||
| 261 | $dummy->appendChild($blocks[0]); |
||
| 262 | $layout->generateBlocks($dummy); |
||
| 263 | } |
||
| 264 | } |
||
| 265 | } |
||
| 266 | $block = $layout->getBlock($esiData->getNameInLayout()); |
||
| 267 | |||
| 268 | if ( ! $this->getFlag('', self::FLAG_NO_DISPATCH_BLOCK_EVENT)) { |
||
| 269 | Mage::dispatchEvent( |
||
| 270 | 'controller_action_layout_generate_blocks_after', |
||
| 271 | array('action'=>$this, 'layout'=>$layout) |
||
| 272 | ); |
||
| 273 | } |
||
| 274 | |||
| 275 | $this->_isLayoutLoaded = true; |
||
| 276 | Varien_Profiler::stop('turpentine::controller::esi::_getEsiBlock'); |
||
| 277 | return $block; |
||
| 278 | } |
||
| 279 | |||
| 302 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.