Completed
Push — master ( 0975d4...e23347 )
by Song
02:20
created

Column   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 75
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 75
loc 75
rs 10
c 0
b 0
f 0
wmc 6
lcom 0
cbo 2

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 5 1
A add() 4 4 1
A removeFields() 6 6 1
A fields() 4 4 1
A setWidth() 4 4 1
A width() 4 4 1

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
2
/**
3
 * Copyright (c) 2019. Mallto.Co.Ltd.<mall-to.com> All rights reserved.
4
 */
5
6
namespace Encore\Admin\Form\Layout;
7
8
use Encore\Admin\Form\Field;
9
use Illuminate\Support\Collection;
10
11 View Code Duplication
class Column
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in 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...
12
{
13
    /**
14
     * @var Collection
15
     */
16
    protected $fields;
17
18
    /**
19
     * @var int
20
     */
21
    protected $width;
22
23
    /**
24
     * Column constructor.
25
     *
26
     * @param int $width
27
     */
28
    public function __construct($width = 12)
29
    {
30
        $this->width = $width;
31
        $this->fields = new Collection();
32
    }
33
34
    /**
35
     * Add a filter to this column.
36
     *
37
     * @param Field $field
38
     */
39
    public function add(Field $field)
40
    {
41
        $this->fields->push($field);
42
    }
43
44
    /**
45
     * Remove fields from column.
46
     *
47
     * @param $fields
48
     */
49
    public function removeFields($fields)
50
    {
51
        $this->fields = $this->fields->reject(function (Field $field) use ($fields) {
52
            return in_array($field->column(), $fields);
53
        });
54
    }
55
56
    /**
57
     * Get all filters in this column.
58
     *
59
     * @return Collection
60
     */
61
    public function fields()
62
    {
63
        return $this->fields;
64
    }
65
66
    /**
67
     * Set column width.
68
     *
69
     * @param int $width
70
     */
71
    public function setWidth($width)
72
    {
73
        $this->width = $width;
74
    }
75
76
    /**
77
     * Get column width.
78
     *
79
     * @return int
80
     */
81
    public function width()
82
    {
83
        return $this->width;
84
    }
85
}
86