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 | |||
81 | $request = new Request(); |
||
82 | |||
83 | $this->beConstructedWith($container, $expression); |
||
84 | |||
85 | $this |
||
86 | ->parseRequestValues(['nested' => ['service' => 'expr:service("service")']], $request) |
||
87 | ->shouldReturn(['nested' => ['service' => $service]]) |
||
88 | ; |
||
89 | } |
||
90 | |||
91 | function it_should_parse_expressions_with_parameters() |
||
92 | { |
||
93 | $service = new \stdClass(); |
||
94 | |||
95 | $container = new Container(); |
||
96 | $container->set('service', $service); |
||
97 | |||
98 | $expression = new ExpressionLanguage(); |
||
99 | |||
100 | $request = new Request(); |
||
101 | $request->request->set('serviceName', 'service'); |
||
102 | |||
103 | $this->beConstructedWith($container, $expression); |
||
104 | |||
105 | $this |
||
106 | ->parseRequestValues(['nested' => ['service' => 'expr:service($serviceName)']], $request) |
||
107 | ->shouldReturn(['nested' => ['service' => $service]]) |
||
108 | ; |
||
109 | } |
||
110 | |||
111 | function it_should_throw_an_exception_if_array_parameter_is_injected_into_expression() |
||
112 | { |
||
113 | $request = new Request(); |
||
114 | $request->request->set('array', ['foo', 'bar']); |
||
115 | |||
116 | $this->beConstructedWith(new Container(), new ExpressionLanguage()); |
||
117 | |||
118 | $this |
||
119 | ->shouldThrow(\InvalidArgumentException::class) |
||
120 | ->during('parseRequestValues', [['contains' => 'expr:"foo" in $array'], $request]) |
||
121 | ; |
||
122 | } |
||
123 | |||
124 | function it_should_throw_an_exception_if_object_parameter_is_injected_into_expression() |
||
125 | { |
||
126 | $request = new Request(); |
||
127 | $request->request->set('object', new \stdClass()); |
||
128 | |||
129 | $this->beConstructedWith(new Container(), new ExpressionLanguage()); |
||
130 | |||
131 | $this |
||
132 | ->shouldThrow(\InvalidArgumentException::class) |
||
133 | ->during('parseRequestValues', [['object' => 'expr:$object.callMethod()'], $request]) |
||
134 | ; |
||
135 | } |
||
136 | } |
||
137 |