Conditions | 1 |
Paths | 1 |
Total Lines | 83 |
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 |
||
92 | public function shouldBuildCallArguments() |
||
93 | { |
||
94 | /** @var ReflectionMethod $methodReflection */ |
||
95 | $methodReflection = $this->createMock(ReflectionMethod::class); |
||
96 | |||
97 | /** @var ReflectionParameter $parameterFooReflection */ |
||
98 | $parameterFooReflection = $this->createMock(ReflectionParameter::class); |
||
99 | $parameterFooReflection->method('getName')->willReturn("foo"); |
||
100 | |||
101 | /** @var ReflectionParameter $parameterBarReflection */ |
||
102 | $parameterBarReflection = $this->createMock(ReflectionParameter::class); |
||
103 | $parameterBarReflection->method('getName')->willReturn("bar"); |
||
104 | |||
105 | /** @var ReflectionParameter $parameterBazReflection */ |
||
106 | $parameterBazReflection = $this->createMock(ReflectionParameter::class); |
||
107 | $parameterBazReflection->method('getName')->willReturn("baz"); |
||
108 | |||
109 | /** @var ReflectionType $parameterType */ |
||
110 | $parameterType = $this->createMock(ReflectionType::class); |
||
111 | $parameterType->method('__toString')->willReturn(SampleService::class); |
||
112 | |||
113 | /** @var ReflectionParameter $parameterFazReflection */ |
||
114 | $parameterFazReflection = $this->createMock(ReflectionParameter::class); |
||
115 | $parameterFazReflection->method('getName')->willReturn("faz"); |
||
116 | $parameterFazReflection->method('hasType')->willReturn(true); |
||
117 | $parameterFazReflection->method('getType')->willReturn($parameterType); |
||
118 | |||
119 | $methodReflection->method("getParameters")->willReturn([ |
||
120 | $parameterFooReflection, |
||
121 | $parameterBarReflection, |
||
122 | $parameterBazReflection, |
||
123 | $parameterFazReflection |
||
124 | ]); |
||
125 | |||
126 | /** @var Request $request */ |
||
127 | $request = $this->createMock(Request::class); |
||
128 | $request->method('get')->will($this->returnValueMap([ |
||
129 | ['lorem', null, 'ipsum'], |
||
130 | ['bar', null, 'blah'], |
||
131 | ])); |
||
132 | |||
133 | /** @var array<string, mixed> $argumentsConfiguration */ |
||
134 | $argumentsConfiguration = array( |
||
135 | "foo" => '$lorem', |
||
136 | "baz" => '@some.service', |
||
137 | "faz" => [ |
||
138 | 'id' => 'some.service', |
||
139 | 'method' => 'someCall', |
||
140 | 'arguments' => [ |
||
141 | 'foo' => '$lorem' |
||
142 | ] |
||
143 | ] |
||
144 | ); |
||
145 | |||
146 | $someService = new SampleService(); |
||
147 | |||
148 | $this->container->method('get')->will($this->returnValueMap([ |
||
149 | ['some.service', $someService], |
||
150 | ])); |
||
151 | |||
152 | $this->entityManager->expects($this->once())->method('find')->with( |
||
153 | $this->equalTo(SampleService::class), |
||
154 | $this->equalTo('ipsum') |
||
155 | )->willReturn($someService); |
||
156 | |||
157 | /** @var array<int, mixed> $expectedCallArguments */ |
||
158 | $expectedCallArguments = array( |
||
159 | 'ipsum', |
||
160 | 'blah', |
||
161 | $someService, |
||
162 | $someService |
||
163 | ); |
||
164 | |||
165 | /** @var array<int, mixed> $actualCallArguments */ |
||
166 | $actualCallArguments = $this->argumentCompiler->buildCallArguments( |
||
167 | $methodReflection, |
||
168 | $argumentsConfiguration, |
||
169 | $request |
||
170 | ); |
||
171 | |||
172 | $this->assertEquals($expectedCallArguments, $actualCallArguments); |
||
173 | $this->assertEquals('ipsum', $someService->foo); |
||
174 | } |
||
175 | |||
280 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..