StateDisplayer::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 2
c 2
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
nc 1
nop 2
crap 1
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 152
    public function __construct(Factory $view, array $config)
15
    {
16 152
        $this->view   = $view;
17 152
        $this->config = $config;
18
    }
19
20
    /**
21
     * @param string $class
22
     */
23 150
    public function setClass($class)
24
    {
25 150
        $this->class = $class;
26
    }
27
28
    // ------------------------------------------------------------------------------------------------
29
    // ------------------------------------------------------------------------------------------------
30
    // ------------------------------------------------------------------------------------------------
31
32
    /**
33
     * @param string $state
34
     */
35 120
    public function setState($state)
36
    {
37 120
        $this->states[] = $state;
38
    }
39
40
    // ------------------------------------------------------------------------------------------------
41
42
    /**
43
     * @param string $states
44
     */
45
    public function setStates($states)
46
    {
47
        $this->states = $states;
48
    }
49
50
51
    // ------------------------------------------------------------------------------------------------
52
    // ------------------------------------------------------------------------------------------------
53
    // ------------------------------------------------------------------------------------------------
54
55
56 120
    public function getRenderStateMenu($template = 'expendable::admin.form.state.menu')
57
    {
58 120
        return $this->view->make($template, [
59 120
            'states' => $this->getTableState(),
60 120
            'action' => '\\'.$this->class.'@'
61
        ]);
62
    }
63
64
65
    // ------------------------------------------------------------------------------------------------
66
67 120
    protected function getTableState()
68
    {
69 120
        $table  = [];
70 120
        $config = $this->config['state'];
71
72 120
        foreach ($this->states as $state)
73
        {
74
75 120
            if (in_array($state, array_keys($config)))
76
            {
77 120
                $table[] = $config[$state];
78
            }
79
        }
80
81
        $table = array_sort($table, function($value)
0 ignored issues
show
Deprecated Code introduced by
The function array_sort() has been deprecated: Arr::sort() should be used directly instead. Will be removed in Laravel 5.9. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

81
        $table = /** @scrutinizer ignore-deprecated */ array_sort($table, function($value)

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
82
        {
83 120
            return $value['position'];
84 120
        });
85
86 120
        return $table;
87
    }
88
}