Completed
Push — master ( 144202...6a00f8 )
by Peter
11:59
created

CriteriaAwareTrait   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 2
c 2
b 0
f 0
lcom 0
cbo 0
dl 0
loc 30
ccs 0
cts 9
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getCriteria() 0 4 1
A setCriteria() 0 5 1
1
<?php
2
3
/*
4
 * To change this license header, choose License Headers in Project Properties.
5
 * To change this template file, choose Tools | Templates
6
 * and open the template in the editor.
7
 */
8
9
namespace Maslosoft\Mangan\Traits;
10
11
use Maslosoft\Mangan\Interfaces\CriteriaInterface;
12
13
/**
14
 * The most simple Criteria Aware Interface implementation.
15
 *
16
 * @author Piotr Maselkowski <pmaselkowski at gmail.com>
17
 */
18
trait CriteriaAwareTrait
19
{
20
21
	/**
22
	 * Criteria instance holder.
23
	 * @var CriteriaInterface
24
	 */
25
	private $criteria = null;
26
27
	/**
28
	 * Get criteria
29
	 * @return CriteriaInterface
30
	 */
31
	public function getCriteria()
32
	{
33
		return $this->criteria;
34
	}
35
36
	/**
37
	 * Set criteria
38
	 * @param CriteriaInterface|array $criteria
39
	 * @return static
40
	 */
41
	public function setCriteria($criteria)
42
	{
43
		$this->criteria = $criteria;
0 ignored issues
show
Documentation Bug introduced by
It seems like $criteria can also be of type array. However, the property $criteria is declared as type object<Maslosoft\Mangan\...aces\CriteriaInterface>. 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...
44
		return $this;
45
	}
46
47
}
48