groupFieldTrait   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 4
Bugs 0 Features 2
Metric Value
wmc 10
c 4
b 0
f 2
lcom 1
cbo 1
dl 0
loc 43
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
B group() 0 17 5
A getGroup() 0 3 1
A groupChecked() 0 6 2
A groupRules() 0 5 2
1
<?php
2
namespace Code4\Forms\Traits;
3
4
use Illuminate\Support\Collection;
5
6
trait groupFieldTrait {
7
8
    protected $group = null;
9
10
    public function group($elements = null) {
11
12
        if (is_null($this->group)) {
13
            $this->group = new Collection();
14
        }
15
16
        if (is_null($elements)) {
17
            return $this->group;
18
        }
19
20
        if (is_array($elements)) {
21
            foreach ($elements as $fieldName => $fieldValue) {
22
                $newField = \FormsFactory::makeField($this->_type, $fieldName, $fieldValue);
0 ignored issues
show
Bug introduced by
The property _type 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...
23
                $this->group->put($fieldName, $newField);
24
            }
25
        }
26
    }
27
28
    public function getGroup() {
29
        return $this->group;
30
    }
31
32
    public function groupChecked($value) {
33
        foreach($this->group as $fieldName => $field) {
34
            $field->checked($value);
35
        }
36
        return $this;
37
    }
38
39
    /**
40
     * Fixes rules for group fields
41
     */
42
    public function groupRules() {
43
        foreach($this->group as $element) {
44
45
        }
46
    }
47
48
}