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

CrudField   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 28
ccs 0
cts 16
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getCrudField() 0 12 2
A addCrudFieldOptions() 0 6 2
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