Completed
Push — master ( 0d59f6...75ea25 )
by wen
02:38
created

Form::setModel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 4
nc 1
nop 1
1
<?php
2
3
namespace Sco\Admin\Form;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Sco\Admin\Contracts\Form\Elements\ElementInterface;
7
use Sco\Admin\Contracts\Form\FormInterface;
8
use Sco\Admin\Contracts\WithModel;
9
10
class Form implements FormInterface, WithModel
11
{
12
    /**
13
     * @var \Sco\Admin\Form\ElementsCollection
14
     */
15
    protected $elements;
16
17
    /**
18
     * @var \Illuminate\Database\Eloquent\Model
19
     */
20
    protected $model;
21
22
    public function __construct(array $elements = [])
23
    {
24
        $this->setElements($elements);
25
    }
26
27
    /**
28
     * {@inheritdoc}
29
     */
30
    public function getElements()
31
    {
32
        return $this->elements;
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function setElements(array $elements)
39
    {
40
        $this->elements = new ElementsCollection($elements);
41
42
        return $this;
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    public function addElement(ElementInterface $element)
49
    {
50
        $this->elements->push($element);
51
52
        return $this;
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58
    public function getModel()
59
    {
60
        return $this->model;
61
    }
62
63
    /**
64
     * {@inheritdoc}
65
     */
66
    public function setModel(Model $model)
67
    {
68
        $this->model = $model;
69
70
        $this->setElementModel($model);
71
72
        return $this;
73
    }
74
75
    /**
76
     * {@inheritdoc}
77
     */
78
    public function setElementModel(Model $model)
79
    {
80
        $this->elements->each(function (ElementInterface $element) use ($model) {
81
            //if ($element instanceof WithModel) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
82
                $element->setModel($model);
83
            //}
84
        });
85
86
        return $this;
87
    }
88
}
89