Completed
Push — master ( 786b39...7594a2 )
by wen
03:20
created

Config::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
4
namespace Sco\Admin\Config;
5
6
7
use Sco\Admin\Traits\HasAttributes;
8
9
class Config
10
{
11
    use HasAttributes;
12
13
    protected $default = [
14
        'title'      => '',
15
        'permission' => true,
16
    ];
17
18
    public function __construct(array $attributes)
19
    {
20
        $this->attributes = $this->merge($this->default, $attributes);
0 ignored issues
show
Unused Code introduced by
The call to Config::merge() has too many arguments starting with $attributes.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
Documentation Bug introduced by
It seems like $this->merge($this->default, $attributes) of type this<Sco\Admin\Config\Config> is incompatible with the declared type array of property $attributes.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
21
        $this->parse();
22
    }
23
24
    protected function parse()
25
    {
26
        $permission = $this->getAttribute('permission');
27
        if ($permission instanceof \Closure) {
28
            $permission = $permission();
29
        }
30
        $this->setAttribute('permission', $permission ? true : false);
31
    }
32
33
}