Completed
Push — master ( ddb6e9...348f46 )
by Klochok
16:41
created

RequestGridLegend::items()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 53
Code Lines 32

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 53
rs 9.5797
cc 1
eloc 32
nc 1
nop 0

How to fix   Long Method   

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
namespace hipanel\modules\hosting\grid;
4
5
use hipanel\widgets\gridLegend\BaseGridLegend;
6
use hipanel\widgets\gridLegend\GridLegendInterface;
7
use Yii;
8
9
class RequestGridLegend extends BaseGridLegend implements GridLegendInterface
10
{
11
    public function items()
12
    {
13
        return [
14
            [
15
                'label' => Yii::t('hipanel:hosting', 'Scheduled time:'),
16
                'tag' => 'h4',
17
            ],
18
            [
19
                'label' => Yii::t('hipanel:hosting', 'Already'),
20
                'color' => '#E0E0E0',
21
                'rule' => false,
22
                'columns' => ['time'],
23
            ],
24
            [
25
                'label' => Yii::t('hipanel:hosting', 'Deferred'),
26
                'color' => '#AAAAFF',
27
                'rule' => false,
28
                'columns' => ['time'],
29
            ],
30
            [
31
                'label' => Yii::t('hipanel:hosting', 'State:'),
32
                'tag' => 'h4',
33
            ],
34
            [
35
                'label' => Yii::t('hipanel:hosting', 'New'),
36
                'color' => '#FFFF99',
37
                'rule' => $this->model->state === 'new',
0 ignored issues
show
Bug introduced by
Accessing state on the interface yii\db\ActiveRecordInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
38
                'columns' => ['state'],
39
            ],
40
            [
41
                'label' => Yii::t('hipanel:hosting', 'In progress'),
42
                'color' => '#AAFFAA',
43
                'rule' => $this->model->state === 'progress',
0 ignored issues
show
Bug introduced by
Accessing state on the interface yii\db\ActiveRecordInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
44
                'columns' => ['state'],
45
            ],
46
            [
47
                'label' => Yii::t('hipanel:hosting', 'Done'),
48
                'columns' => ['state'],
49
            ],
50
            [
51
                'label' => Yii::t('hipanel:hosting', 'Error'),
52
                'color' => '#FFCCCC',
53
                'rule' => $this->model->state === 'error',
0 ignored issues
show
Bug introduced by
Accessing state on the interface yii\db\ActiveRecordInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
54
                'columns' => ['state'],
55
            ],
56
            [
57
                'label' => Yii::t('hipanel:hosting', 'Buzzed'),
58
                'color' => '#FFCCCC',
59
                'rule' => $this->model->state === 'buzzed',
0 ignored issues
show
Bug introduced by
Accessing state on the interface yii\db\ActiveRecordInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
60
                'columns' => ['state'],
61
            ],
62
        ];
63
    }
64
}