Completed
Push — master ( 0c34b7...ef90f4 )
by Oscar
02:32
created

Loader::customRender()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 17
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 1 Features 0
Metric Value
c 3
b 1
f 0
dl 0
loc 17
rs 9.4285
cc 3
eloc 8
nc 2
nop 2
1
<?php
2
3
namespace Folk\Formats;
4
5
use FormManager\Containers;
6
use FormManager\Builder;
7
8
class Loader extends Containers\Loader
9
{
10
    use Traits\CommonTrait;
11
12
    public $list = false;
13
14
    public function __construct(Builder $builder, array $children = null)
15
    {
16
        parent::__construct($children);
17
18
        $this->class('format is-loader');
0 ignored issues
show
Documentation Bug introduced by
The method class does not exist on object<Folk\Formats\Loader>? 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...
19
20
        $this->set([
21
            'list' => false,
22
        ]);
23
    }
24
25
    public function label($html = null)
26
    {
27
        if ($html === null) {
28
            return $this['loader']->label->html();
29
        }
30
31
        $this['loader']->label($html);
32
33
        return $this;
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    protected function customRender($prepend = '', $append = '')
40
    {
41
        //Set class
42
        $class = $this->get('class');
0 ignored issues
show
Unused Code introduced by
$class 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...
43
44
        //Set module
45
        $this->data([
0 ignored issues
show
Documentation introduced by
array('module' => $this-...>get('config')) : null) is of type array<string,*,{"module"...config":"string|null"}>, but the function expects a null|string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
46
            'module' => $this->get('module'),
47
            'config' => $this->get('config') ? json_encode($this->get('config')) : null,
48
        ]);
49
50
        if ($this->error()) {
51
            $this->addClass('has-error');
52
        }
53
54
        return $this->toHtml($prepend, $append);
55
    }
56
}
57