Conditions | 10 |
Paths | 10 |
Total Lines | 29 |
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 |
||
32 | public function isSatisfiedBy($notification): bool |
||
33 | { |
||
34 | $value = (new Dot($notification->metadata()))->get($this->expression->getField()); |
||
35 | if (is_null($value)) { |
||
36 | return false; |
||
37 | } |
||
38 | $operator = $this->expression->getOperator(); |
||
39 | $expressionValue = $this->expression->getValue()->getValue(); |
||
40 | switch ($operator) { |
||
41 | case Comparison::EQ: |
||
42 | return $value === $expressionValue; |
||
43 | case Comparison::NEQ: |
||
44 | return $value !== $expressionValue; |
||
45 | case Comparison::CONTAINS: |
||
46 | return strpos($value, $expressionValue) !== false; |
||
47 | case Comparison::GT: |
||
48 | return $value > $expressionValue; |
||
49 | case Comparison::GTE: |
||
50 | return $value >= $expressionValue; |
||
51 | case Comparison::LT: |
||
52 | return $value < $expressionValue; |
||
53 | case Comparison::LTE: |
||
54 | return $value <= $expressionValue; |
||
55 | case Comparison::IN: |
||
56 | return in_array($value, $expressionValue, true); |
||
57 | default: |
||
58 | throw new RuntimeException(sprintf('Unknown operator: %s', $operator)); |
||
59 | } |
||
60 | } |
||
61 | } |
||
62 |