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

SetActiveView   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 77
Duplicated Lines 3.9 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
dl 3
loc 77
rs 10
c 0
b 0
f 0
wmc 12
lcom 1
cbo 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
C handle() 3 50 11

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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