1 | <?php |
||
7 | class Asserter |
||
8 | { |
||
9 | protected $formater; |
||
10 | |||
11 | public function __construct(TextFormater $formater) |
||
15 | |||
16 | public function assertArrayEquals(array $expected, array $real, $fullText = false) |
||
34 | |||
35 | public function assertArrayContains(array $expected, array $real, $message = null) |
||
36 | { |
||
37 | $message = $message ?: sprintf("The given array\r\n\r\n%s\r\ndoes not contain the following rows\r\n\r\n%s", $this->explode($real), $this->explode($expected)); |
||
38 | $indexes = []; |
||
|
|||
39 | |||
40 | foreach ($expected as $row) { |
||
41 | $this->assert(is_array($row), $message); |
||
42 | } |
||
43 | |||
44 | foreach ($real as $row) { |
||
45 | $this->assert(is_array($row), $message); |
||
46 | } |
||
47 | |||
48 | $nodes = (new NodesBuilder)->build($real); |
||
49 | $nodes = $nodes->search(current(current($expected))); |
||
50 | |||
51 | foreach ($nodes as $initial) { |
||
52 | $result = true; |
||
53 | $cells = $expected; |
||
54 | $lineStart = $initial; |
||
55 | do { |
||
56 | $columns = array_shift($cells); |
||
57 | $columnElement = $lineStart; |
||
58 | do { |
||
59 | $content = array_shift($columns); |
||
60 | $result = $columnElement |
||
61 | ? $content === $columnElement->getContent() |
||
62 | : false |
||
63 | ; |
||
64 | $columnElement = $columnElement ? $columnElement->getRight() : null; |
||
65 | } while (!empty($columns) && $result); |
||
66 | $lineStart = $lineStart ? $lineStart->getBottom() : null; |
||
67 | } while (!empty($cells) && $result); |
||
68 | |||
69 | if ($result) { |
||
70 | |||
71 | return true; |
||
72 | } |
||
73 | } |
||
74 | |||
75 | $this->assert(false, $message); |
||
76 | } |
||
77 | |||
78 | public function assertEquals($expected, $real, $message = "Failing to assert equals.") |
||
82 | |||
83 | public function assertNotEquals($expected, $real, $message = "Failing to assert not equals.") |
||
87 | |||
88 | public function assert($result, $message = "Assert failure") |
||
96 | |||
97 | private function explode($value) |
||
105 | } |
||
106 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
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.