| Conditions | 10 |
| Paths | 7 |
| Total Lines | 34 |
| 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 |
||
| 25 | protected function match(RecordInterface $record, $query): bool |
||
| 26 | { |
||
| 27 | if ($record === $query) { |
||
| 28 | //Strict search |
||
| 29 | return true; |
||
| 30 | } |
||
| 31 | |||
| 32 | //Primary key comparision |
||
| 33 | if (is_scalar($query) && $record->primaryKey() == $query) { |
||
| 34 | return true; |
||
| 35 | } |
||
| 36 | |||
| 37 | //Record based comparision |
||
| 38 | if ($query instanceof RecordInterface) { |
||
| 39 | //Matched by PK (assuming both same class) |
||
| 40 | if (!empty($query->primaryKey()) && $query->primaryKey() == $record->primaryKey()) { |
||
| 41 | return true; |
||
| 42 | } |
||
| 43 | |||
| 44 | //Matched by content (this is a bit tricky!) |
||
| 45 | if ($record->packValue() == $query->packValue()) { |
||
| 46 | return true; |
||
| 47 | } |
||
| 48 | |||
| 49 | return false; |
||
| 50 | } |
||
| 51 | |||
| 52 | //Field intersection |
||
| 53 | if (is_array($query) && array_intersect_assoc($record->packValue(), $query) == $query) { |
||
| 54 | return true; |
||
| 55 | } |
||
| 56 | |||
| 57 | return false; |
||
| 58 | } |
||
| 59 | } |