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

Column::removeFields()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 6
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 6
loc 6
rs 10
c 0
b 0
f 0
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