Conditions | 11 |
Paths | 8 |
Total Lines | 36 |
Code Lines | 20 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
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 |
||
61 | private function findRowsWithFields(NodeElement $table, array $fields) |
||
62 | { |
||
63 | $rows = $table->findAll('css', 'tr'); |
||
64 | |||
65 | if (!isset($rows[0])) { |
||
66 | throw new \InvalidArgumentException('There are no rows!'); |
||
67 | } |
||
68 | |||
69 | $fields = $this->replaceColumnNamesWithColumnIds($table, $fields); |
||
70 | |||
71 | /** @var NodeElement[] $rows */ |
||
72 | $rows = $table->findAll('css', 'tr'); |
||
73 | foreach ($rows as $row) { |
||
74 | /** @var NodeElement[] $columns */ |
||
75 | $columns = $row->findAll('css', 'th,td'); |
||
76 | foreach ($fields as $index => $searchedValue) { |
||
77 | if (!isset($columns[$index])) { |
||
78 | throw new \InvalidArgumentException(sprintf('There is no column with index %d', $index)); |
||
79 | } |
||
80 | |||
81 | $containing = false; |
||
82 | $searchedValue = trim($searchedValue); |
||
83 | if (0 === strpos($searchedValue, '%') && (strlen($searchedValue) - 1) === strrpos($searchedValue, '%')) { |
||
84 | $searchedValue = substr($searchedValue, 1, -2); |
||
85 | $containing = true; |
||
86 | } |
||
87 | |||
88 | $position = stripos(trim($columns[$index]->getText()), $searchedValue); |
||
89 | if (($containing && false === $position) || (!$containing && 0 !== $position)) { |
||
90 | continue 2; |
||
91 | } |
||
92 | } |
||
93 | |||
94 | yield $row; |
||
95 | } |
||
96 | } |
||
97 | |||
147 |