| Conditions | 14 |
| Paths | 127 |
| Total Lines | 53 |
| Code Lines | 26 |
| 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 |
||
| 28 | public function compare(EntityFetcher $fetcher) |
||
| 29 | { |
||
| 30 | $result = 1; |
||
| 31 | |||
| 32 | // check if joins match |
||
| 33 | foreach ($this->joins as $condition) { |
||
| 34 | if (!in_array($condition, $fetcher->joins)) { |
||
| 35 | return 0; |
||
| 36 | } |
||
| 37 | $result++; |
||
| 38 | } |
||
| 39 | |||
| 40 | // check if where conditions match |
||
| 41 | foreach ($this->where as $condition) { |
||
| 42 | if (!in_array($condition, $fetcher->where)) { |
||
| 43 | return 0; |
||
| 44 | } |
||
| 45 | $result++; |
||
| 46 | } |
||
| 47 | |||
| 48 | // check if grouping matches |
||
| 49 | foreach ($this->groupBy as $condition) { |
||
| 50 | if (!in_array($condition, $fetcher->groupBy)) { |
||
| 51 | return 0; |
||
| 52 | } |
||
| 53 | $result++; |
||
| 54 | } |
||
| 55 | |||
| 56 | // check if order matches |
||
| 57 | foreach ($this->orderBy as $condition) { |
||
| 58 | if (!in_array($condition, $fetcher->orderBy)) { |
||
| 59 | return 0; |
||
| 60 | } |
||
| 61 | $result++; |
||
| 62 | } |
||
| 63 | |||
| 64 | // check if limit and offset matches |
||
| 65 | if ($this->limit) { |
||
| 66 | if ($this->limit !== $fetcher->limit || $this->offset !== $fetcher->offset) { |
||
| 67 | return 0; |
||
| 68 | } |
||
| 69 | $result++; |
||
| 70 | } |
||
| 71 | |||
| 72 | // check if regular expressions match |
||
| 73 | foreach ($this->regularExpressions as $expression) { |
||
| 74 | if (!preg_match($expression, $fetcher->getQuery())) { |
||
| 75 | return 0; |
||
| 76 | } |
||
| 77 | $result++; |
||
| 78 | } |
||
| 79 | |||
| 80 | return $result; |
||
| 81 | } |
||
| 120 |