| Conditions | 1 |
| Paths | 1 |
| Total Lines | 109 |
| Code Lines | 60 |
| 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 |
||
| 80 | function it_parses_expressions_with_string_parameters() |
||
| 81 | { |
||
| 82 | $request = new Request(); |
||
| 83 | $request->request->set('string', 'lorem ipsum'); |
||
| 84 | |||
| 85 | $this |
||
| 86 | ->parseRequestValues(['expression' => 'expr:$string === "lorem ipsum"'], $request) |
||
| 87 | ->shouldReturn(['expression' => true]) |
||
| 88 | ; |
||
| 89 | } |
||
| 90 | |||
| 91 | function it_parses_expressions_with_scalar_parameters() |
||
| 92 | { |
||
| 93 | $request = new Request(); |
||
| 94 | $request->request->set('number', 6); |
||
| 95 | |||
| 96 | $this |
||
| 97 | ->parseRequestValues(['expression' => 'expr:$number === 6'], $request) |
||
| 98 | ->shouldReturn(['expression' => true]) |
||
| 99 | ; |
||
| 100 | } |
||
| 101 | |||
| 102 | function it_throws_an_exception_if_array_parameter_is_injected_into_expression() |
||
| 103 | { |
||
| 104 | $request = new Request(); |
||
| 105 | $request->request->set('array', ['foo', 'bar']); |
||
| 106 | |||
| 107 | $this |
||
| 108 | ->shouldThrow(\InvalidArgumentException::class) |
||
| 109 | ->during('parseRequestValues', [['expression' => 'expr:"foo" in $array'], $request]) |
||
| 110 | ; |
||
| 111 | } |
||
| 112 | |||
| 113 | function it_throws_an_exception_if_object_parameter_is_injected_into_expression() |
||
| 114 | { |
||
| 115 | $request = new Request(); |
||
| 116 | $request->request->set('object', new \stdClass()); |
||
| 117 | |||
| 118 | $this |
||
| 119 | ->shouldThrow(\InvalidArgumentException::class) |
||
| 120 | ->during('parseRequestValues', [['expression' => 'expr:$object.callMethod()'], $request]) |
||
| 121 | ; |
||
| 122 | } |
||
| 123 | } |
||
| 124 |