Test Failed
Push — master ( 8f2167...5d2217 )
by Georgi
08:27
created

HasLocation::location()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 11
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Epesi\Core\System\Modules\Concerns;
4
5
trait HasLocation
6
{
7
	use HasModule;
8
	
9
	/**
10
	 * Define the label for the module base location caption
11
	 * e.g Dashboard >> View, you should define $label = 'Dashboard'
12
	 * 
13
	 * @var string
14
	 */
15
	protected $label = '';
16
	
17
	/**
18
	 * Stores detailed labels for location caption to be displayed
19
	 * e.g Dashboard >> Edit >> Layout, you should set $location = ['Edit', 'Layout']
20
	 * 
21
	 * @var array
22
	 */
23
	protected $location = [];
24
	
25
	/**
26
	 * Get or set the location caption displayed
27
	 * 
28
	 * @param string | array $location
29
	 * @return \Epesi\Core\System\Modules\ModuleView|array
30
	 */
31
	public function location($location = null)
32
	{
33
		if ($location) {
34
			$this->location = $location;
0 ignored issues
show
Documentation Bug introduced by
It seems like $location can also be of type string. However, the property $location is declared as type array. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
35
			
36
			return $this;
37
		}
38
		
39
		$this->label = array_map('trans', (array) $this->label);
0 ignored issues
show
Documentation Bug introduced by
It seems like array_map('trans', (array)$this->label) of type array is incompatible with the declared type string of property $label.

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...
40
41
		return array_merge($this->label, (array) $this->location);
42
	}
43
	
44
	public function label($label)
45
	{
46
		if ($label) {
47
			$this->label = $label;
48
			
49
			return $this;
50
		}
51
		
52
		return $this->label;
53
	}
54
}
55