Passed
Push — master ( f4d366...672a66 )
by Thomas
03:42 queued 01:49
created

CrudField::getCrudField()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 0
cts 10
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 7
nc 2
nop 0
crap 6
1
<?php
2
3
namespace Webfactor\Laravel\Generators\Traits;
4
5
trait CrudField
6
{
7
    private $field = [];
8
9
    protected $crudFieldType;
10
11
    protected $crudFieldOptions = [];
12
13
    public function getCrudField(): array
14
    {
15
        $this->field['name'] = $this->name;
0 ignored issues
show
Bug introduced by
The property name does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
16
        $this->field['label'] = $this->name;
17
        $this->field['type'] = $this->crudFieldType;
18
19
        if ($this->crudFieldOptions) {
20
            $this->addCrudFieldOptions();
21
        }
22
23
        return $this->field;
24
    }
25
26
    private function addCrudFieldOptions()
27
    {
28
        foreach ($this->crudFieldOptions as $key => $option) {
29
            $this->field[$key] = $option;
30
        }
31
    }
32
}
33