Completed
Push — master ( ae1877...f4c876 )
by Maxime
128:48 queued 121:52
created

StateDisplayer::setStates()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php namespace Distilleries\Expendable\States;
2
3
use Distilleries\Expendable\Contracts\StateDisplayerContract;
4
use Illuminate\Contracts\View\Factory;
5
6
class StateDisplayer implements StateDisplayerContract {
7
8
9
    protected $states = [];
10
    protected $class = '';
11
    protected $view;
12
    public $config;
13
14 288
    public function __construct(Factory $view, array $config)
15
    {
16 288
        $this->view   = $view;
17 288
        $this->config = $config;
18
    }
19
20
    /**
21
     * @param string $class
22
     */
23 284
    public function setClass($class)
24
    {
25 284
        $this->class = $class;
26
    }
27
28
    // ------------------------------------------------------------------------------------------------
29
    // ------------------------------------------------------------------------------------------------
30
    // ------------------------------------------------------------------------------------------------
31
32
    /**
33
     * @param string $state
34
     */
35 224
    public function setState($state)
36
    {
37 224
        $this->states[] = $state;
38
    }
39
40
    // ------------------------------------------------------------------------------------------------
41
42
    /**
43
     * @param string $states
44
     */
45
    public function setStates($states)
46
    {
47
        $this->states = $states;
0 ignored issues
show
Documentation Bug introduced by
It seems like $states of type string is incompatible with the declared type array of property $states.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
48
    }
49
50
51
    // ------------------------------------------------------------------------------------------------
52
    // ------------------------------------------------------------------------------------------------
53
    // ------------------------------------------------------------------------------------------------
54
55
56 224
    public function getRenderStateMenu($template = 'expendable::admin.form.state.menu')
57
    {
58 224
        return $this->view->make($template, [
59 224
            'states' => $this->getTableState(),
60 224
            'action' => '\\' . $this->class . '@'
61
        ]);
62
    }
63
64
65
    // ------------------------------------------------------------------------------------------------
66
67 224
    protected function getTableState()
68
    {
69 224
        $table  = [];
70 224
        $config = $this->config['state'];
71
72 224
        foreach ($this->states as $state)
73
        {
74
75 224
            if (in_array($state, array_keys($config)))
76
            {
77 224
                $table[] = $config[$state];
78
            }
79
        }
80
81
        $table = array_sort($table, function($value)
82
        {
83 224
            return $value['position'];
84 224
        });
85
86 224
        return $table;
87
    }
88
}