Completed
Push — master ( 119a25...af28eb )
by Shcherbak
04:15
created

ToolsFilter::createFromString()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 19
ccs 0
cts 15
cp 0
rs 9.4285
cc 3
eloc 12
nc 3
nop 2
crap 12

2 Methods

Rating   Name   Duplication   Size   Complexity  
A ToolsFilter::getExclude() 0 3 1
A ToolsFilter::setExclude() 0 3 1
1
<?php
2
3
  namespace Funivan\Cs\FileTool;
4
5
  /**
6
   * @author Ivan Shcherbak <[email protected]> 2016
7
   */
8
  class ToolsFilter {
9
10
    /**
11
     * @var null|string[]
12
     */
13
    private $include = null;
14
15
    /**
16
     * @var null|string[]
17
     */
18
    private $exclude = null;
19
20
21
    /**
22
     * @return null|string[]
23
     */
24
    public function getInclude() {
25
      return $this->include;
26
    }
27
28
29
    /**
30
     * @param null|string[] $include
31
     * @return $this
32
     */
33
    public function setInclude(array $include = null) {
34
      $this->include = $include;
35
    }
36
37
38
    /**
39
     * @return null|\string[]
40
     */
41
    public function getExclude() {
42
      return $this->exclude;
43
    }
44
45
46
    /**
47
     * @param null|\string[] $exclude
48
     * @return $this
49
     */
50
    public function setExclude(array $exclude = null) {
51
      $this->exclude = $exclude;
0 ignored issues
show
Documentation Bug introduced by
It seems like $exclude can also be of type array<integer,object<string>>. However, the property $exclude is declared as type null|array<integer,string>. 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...
52
    }
53
54
55
    /**
56
     * @param FileTool $tool
57
     * @return bool
58
     */
59
    public function isValid(FileTool $tool) {
60
61
      $toolName = $tool->getName();
62
63
      if (null !== $this->exclude and in_array($toolName, $this->exclude)) {
64
        return false;
65
      }
66
67
      if (null !== $this->include and !in_array($toolName, $this->include)) {
68
        return false;
69
      }
70
71
72
      return true;
73
    }
74
75
  }