Completed
Push — master ( a0253d...70910a )
by Ryan
12:32 queued 06:51
created

SetActiveView::handle()   C

Complexity

Conditions 11
Paths 133

Size

Total Lines 50
Code Lines 23

Duplication

Lines 3
Ratio 6 %

Importance

Changes 0
Metric Value
cc 11
eloc 23
nc 133
nop 2
dl 3
loc 50
rs 5.1538
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 namespace Anomaly\Streams\Platform\Ui\Table\Component\View\Command;
2
3
use Anomaly\Streams\Platform\Ui\Table\Component\View\ViewHandler;
4
use Anomaly\Streams\Platform\Ui\Table\TableBuilder;
5
use Illuminate\Contracts\Container\Container;
6
use Illuminate\Http\Request;
7
8
/**
9
 * Class SetActiveView
10
 *
11
 * @link   http://pyrocms.com/
12
 * @author PyroCMS, Inc. <[email protected]>
13
 * @author Ryan Thompson <[email protected]>
14
 */
15
class SetActiveView
16
{
17
18
    /**
19
     * The table builder.
20
     *
21
     * @var TableBuilder
22
     */
23
    protected $builder;
24
25
    /**
26
     * Create a new BuildTableFiltersCommand instance.
27
     *
28
     * @param TableBuilder $builder
29
     */
30
    public function __construct(TableBuilder $builder)
31
    {
32
        $this->builder = $builder;
33
    }
34
35
    /**
36
     * Handle the command.
37
     *
38
     * @param Request $request
39
     * @param Container $container
0 ignored issues
show
Bug introduced by
There is no parameter named $container. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
40
     */
41
    public function handle(Request $request, ViewHandler $handler)
42
    {
43
        $table   = $this->builder->getTable();
44
        $options = $table->getOptions();
45
        $views   = $table->getViews();
46
47
        if ($views->active()) {
48
            return;
49
        }
50
51 View Code Duplication
        if ($view = $views->findBySlug($request->get($options->get('prefix') . 'view'))) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
52
            $view->setActive(true);
53
        }
54
55
        if (!$view && $view = $views->first()) {
56
            $view->setActive(true);
57
        }
58
59
        // Nothing to do.
60
        if (!$view) {
61
            return;
62
        }
63
64
        // Set filters from active view.
65
        if (($filters = $view->getFilters()) !== null) {
66
            $this->builder->setFilters($filters);
67
        }
68
69
        // Set columns from active view.
70
        if (($columns = $view->getColumns()) !== null) {
71
            $this->builder->setColumns($columns);
72
        }
73
74
        // Set buttons from active view.
75
        if (($buttons = $view->getButtons()) !== null) {
76
            $this->builder->setButtons($buttons);
77
        }
78
79
        // Set actions from active view.
80
        if (($actions = $view->getActions()) !== null) {
81
            $this->builder->setActions($actions);
82
        }
83
84
        // Set options from active view.
85
        if (($options = $view->getOptions()) !== null) {
86
            $this->builder->setOptions($options);
87
        }
88
89
        $handler->handle($this->builder, $view);
90
    }
91
}
92