Completed
Push — master ( dc232d...5ccba3 )
by Song
02:47 queued 15s
created

Layout::addField()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 4
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;
9
use Encore\Admin\Grid\Filter;
10
use Illuminate\Support\Collection;
11
12
class Layout
13
{
14
    /**
15
     * @var Collection
16
     */
17
    protected $columns;
18
19
    /**
20
     * @var Column
21
     */
22
    protected $current;
23
24
    /**
25
     * @var Form
26
     */
27
    protected $parent;
28
29
    /**
30
     * Layout constructor.
31
     *
32
     * @param Form $form
33
     */
34
    public function __construct(Form $form)
35
    {
36
        $this->parent = $form;
37
38
        $this->current = new Column();
39
40
        $this->columns = new Collection();
41
    }
42
43
    /**
44
     * Add a filter to layout column.
45
     *
46
     * @param Form\Field $field
47
     */
48
    public function addField(Form\Field $field)
49
    {
50
        $this->current->add($field);
51
    }
52
53
    /**
54
     * Add a new column in layout.
55
     *
56
     * @param int      $width
57
     * @param \Closure $closure
58
     */
59 View Code Duplication
    public function column($width, \Closure $closure)
0 ignored issues
show
Duplication introduced by
This method 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...
60
    {
61
        if ($this->columns->isEmpty()) {
62
            $column = $this->current;
63
64
            $column->setWidth($width);
65
        } else {
66
            $column = new Column($width);
67
68
            $this->current = $column;
69
        }
70
71
        $this->columns->push($column);
72
73
        $closure($this->parent);
74
    }
75
76
    /**
77
     * Get all columns in filter layout.
78
     *
79
     * @return Collection
80
     */
81
    public function columns()
82
    {
83
        if ($this->columns->isEmpty()) {
84
            $this->columns->push($this->current);
85
        }
86
87
        return $this->columns;
88
    }
89
}
90