Completed
Push — master ( a6e7a2...8a3554 )
by Ryan
06:51
created

BuildTable::handle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 53
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 53
rs 9.5797
cc 1
eloc 19
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 namespace Anomaly\Streams\Platform\Ui\Table\Command;
2
3
use Anomaly\Streams\Platform\Ui\Table\Component\Action\Command\BuildActions;
4
use Anomaly\Streams\Platform\Ui\Table\Component\Action\Command\SetActiveAction;
5
use Anomaly\Streams\Platform\Ui\Table\Component\Filter\Command\BuildFilters;
6
use Anomaly\Streams\Platform\Ui\Table\Component\Filter\Command\SetActiveFilters;
7
use Anomaly\Streams\Platform\Ui\Table\Component\Header\Command\BuildHeaders;
8
use Anomaly\Streams\Platform\Ui\Table\Component\Row\Command\BuildRows;
9
use Anomaly\Streams\Platform\Ui\Table\Component\View\Command\BuildViews;
10
use Anomaly\Streams\Platform\Ui\Table\Component\View\Command\SetActiveView;
11
use Anomaly\Streams\Platform\Ui\Table\TableBuilder;
12
use Illuminate\Contracts\Bus\SelfHandling;
13
use Illuminate\Foundation\Bus\DispatchesJobs;
14
15
/**
16
 * Class BuildTable
17
 *
18
 * @link          http://anomaly.is/streams-platform
19
 * @author        AnomalyLabs, Inc. <[email protected]>
20
 * @author        Ryan Thompson <[email protected]>
21
 * @package       Anomaly\Streams\Platform\Ui\Table\Command
22
 */
23
class BuildTable implements SelfHandling
24
{
25
26
    use DispatchesJobs;
27
28
    /**
29
     * The table builder.
30
     *
31
     * @var TableBuilder
32
     */
33
    protected $builder;
34
35
    /**
36
     * Create a new BuildTableColumnsCommand instance.
37
     *
38
     * @param TableBuilder $builder
39
     */
40
    public function __construct(TableBuilder $builder)
41
    {
42
        $this->builder = $builder;
43
    }
44
45
    /**
46
     * Handle the command.
47
     */
48
    public function handle()
49
    {
50
        /**
51
         * Resolve and set the table model and stream.
52
         */
53
        $this->dispatch(new SetTableModel($this->builder));
54
        $this->dispatch(new SetTableStream($this->builder));
55
        $this->dispatch(new SetDefaultParameters($this->builder));
56
        $this->dispatch(new SetRepository($this->builder));
57
58
        $this->dispatch(new SetTableOptions($this->builder));
59
        $this->dispatch(new SetDefaultOptions($this->builder));
60
        $this->dispatch(new SaveTableState($this->builder));
61
62
        /**
63
         * Before we go any further, authorize the request.
64
         */
65
        $this->dispatch(new AuthorizeTable($this->builder));
66
67
        /*
68
         * Build table views and mark active.
69
         */
70
        $this->dispatch(new BuildViews($this->builder));
71
        $this->dispatch(new SetActiveView($this->builder));
72
73
        /**
74
         * Build table filters and flag active.
75
         */
76
        $this->dispatch(new BuildFilters($this->builder));
77
        $this->dispatch(new SetActiveFilters($this->builder));
78
79
        /**
80
         * Build table actions and flag active.
81
         */
82
        $this->dispatch(new BuildActions($this->builder));
83
        $this->dispatch(new SetActiveAction($this->builder));
84
85
        /**
86
         * Build table headers.
87
         */
88
        $this->dispatch(new BuildHeaders($this->builder));
89
        $this->dispatch(new EagerLoadRelations($this->builder));
90
91
        /**
92
         * Get table entries.
93
         */
94
        $this->dispatch(new GetTableEntries($this->builder));
95
96
        /**
97
         * Lastly table rows.
98
         */
99
        $this->dispatch(new BuildRows($this->builder));
100
    }
101
}
102