_prepareCollection()   B
last analyzed

Complexity

Conditions 11
Paths 20

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 11
nc 20
nop 0
dl 0
loc 24
rs 7.3166
c 0
b 0
f 0

How to fix   Complexity   

Long Method

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:

1
<?php
2
3
/**
4
 * User: [email protected]
5
 * Date: 2018-02-19
6
 */
7
8
class Nexcessnet_Turpentine_Block_Adminhtml_Cache_Grid extends Mage_Adminhtml_Block_Cache_Grid
9
{
10
11
    /**
12
     * Prepare grid collection
13
     */
14
    protected function _prepareCollection()
15
    {
16
        parent::_prepareCollection();
17
        $collection = $this->getCollection();
18
        $turpentineEnabled = false;
19
        $fullPageEnabled = false;
20
        foreach ($collection as $key=>$item) {
21
            if ($item->getStatus() == 1 && ($item->getId() == 'turpentine_pages' || $item->getId() == 'turpentine_esi_blocks')) {
22
                $turpentineEnabled = true;
23
            }
24
            if ($item->getStatus() == 1 && $item->getId() == 'full_page') {
25
                $fullPageEnabled = true;
26
            }
27
        }
28
        if ($turpentineEnabled  && !$fullPageEnabled) {
29
            $collection->removeItemByKey('full_page');
30
        }
31
        if ($fullPageEnabled && !$turpentineEnabled) {
32
            $collection->removeItemByKey('turpentine_pages');
33
            $collection->removeItemByKey('turpentine_esi_blocks');
34
        }
35
        $this->setCollection($collection);
36
        return $this;
37
    }
38
39
}
40