Completed
Push — master ( bafc2b...789f6f )
by Oscar
03:26
created

RelationOne::__construct()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 0 Features 1
Metric Value
c 4
b 0
f 1
dl 0
loc 18
rs 9.4285
cc 3
eloc 10
nc 4
nop 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\Select implements FormatInterface
12
{
13
    use Traits\HtmlValueTrait;
14
    use Traits\RenderTrait;
15
16
    public function __construct(Builder $builder, EntityInterface $related, SearchQuery $search = null)
17
    {
18
        parent::__construct();
19
20
        $this->input[''] = '';
21
22
        if ($search === null) {
23
            $search = new SearchQuery();
24
        }
25
26
        foreach ($related->search($search) as $id => $row) {
27
            $this->input[$id] = $related->getLabel($id, $row);
28
        }
29
30
        $this->set('list', false);
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...
31
        $this->wrapper->class('format is-responsive');
32
        $this->data('module', 'format-select');
0 ignored issues
show
Documentation Bug introduced by
The method data 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...
33
    }
34
}
35