Completed
Push — master ( 506ee6...2ad65e )
by Oscar
02:37
created

RelationOne   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 3
c 3
b 0
f 1
lcom 0
cbo 5
dl 0
loc 29
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 24 3
1
<?php
2
3
namespace Folk\Formats;
4
5
use FormManager\Fields;
6
use FormManager\Elements;
7
use FormManager\Builder;
8
use Folk\Entities\EntityInterface;
9
use Folk\SearchQuery;
10
11
class RelationOne extends Fields\Field
12
{
13
    use Traits\FieldTrait;
14
15
    public function __construct(Builder $builder, EntityInterface $related, SearchQuery $search = null)
16
    {
17
        $this->datalistAllowed = false;
18
19
        $this->input = new Elements\Select();
20
21
        $this->input[''] = '';
22
23
        if ($search === null) {
24
            $search = new SearchQuery();
0 ignored issues
show
Unused Code introduced by
$search is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
25
        }
26
27
        foreach ($related->search() as $id => $row) {
0 ignored issues
show
Bug introduced by
The call to search() misses a required argument $search.

This check looks for function calls that miss required arguments.

Loading history...
28
            $this->input[$id] = $related->getLabel($id, $row);
29
        }
30
31
        parent::__construct();
32
33
        $this->set([
0 ignored issues
show
Documentation Bug introduced by
The method set does not exist on object<Folk\Formats\RelationOne>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
34
            'list' => false,
35
            'class' => 'is-responsive',
36
            'module' => 'entity-select',
37
        ]);
38
    }
39
}
40