Conditions | 13 |
Paths | 136 |
Total Lines | 42 |
Code Lines | 28 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
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 | |||
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.