Conditions | 3 |
Paths | 4 |
Total Lines | 62 |
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 |
||
117 | public function testCheck(string $lockPath, string $expectedType, string $expected) |
||
118 | { |
||
119 | if ('exception' === $expectedType) { |
||
120 | $this->expectException(ParseException::class); |
||
121 | $this->expectExceptionMessage($expected); |
||
122 | } |
||
123 | |||
124 | $this->container |
||
125 | ->expects($this->any()) |
||
126 | ->method('getParameter') |
||
127 | ->will($this->onConsecutiveCalls('url', 300, true, 'title')) |
||
128 | ; |
||
129 | |||
130 | $requestMock = $this->createMock(Request::class); |
||
131 | |||
132 | $stackMock = $this->createMock(RequestStack::class); |
||
133 | $stackMock |
||
134 | ->expects($this->once()) |
||
135 | ->method('getCurrentRequest') |
||
136 | ->willReturn($requestMock) |
||
137 | ; |
||
138 | |||
139 | $translatorMock = $this->createMock(Translator::class); |
||
140 | $translatorMock |
||
141 | ->expects($this->any()) |
||
142 | ->method('trans') |
||
143 | ->willReturn('translated') |
||
144 | ; |
||
145 | |||
146 | $kernelMock = $this->createMock(Kernel::class); |
||
147 | |||
148 | $this->container |
||
149 | ->expects($this->exactly(3)) |
||
150 | ->method('get') |
||
151 | ->will($this->onConsecutiveCalls($stackMock, $kernelMock, $translatorMock)) |
||
152 | ; |
||
153 | |||
154 | $mock = new MockHandler([ |
||
155 | new Response(200, ['X-Foo' => 'Bar'], \json_encode(['foo' => 'bar'])), |
||
156 | ]); |
||
157 | |||
158 | $handler = HandlerStack::create($mock); |
||
159 | $client = new Client(['handler' => $handler]); |
||
160 | |||
161 | $versionCheckerMock = $this->setUpVersionCheckerMock(['getClient', 'getLockPath']); |
||
162 | $versionCheckerMock |
||
163 | ->expects($this->any()) |
||
164 | ->method('getClient') |
||
165 | ->willReturn($client) |
||
166 | ; |
||
167 | $versionCheckerMock |
||
168 | ->expects($this->once()) |
||
169 | ->method('getLockPath') |
||
170 | ->willReturn($lockPath) |
||
171 | ; |
||
172 | |||
173 | if ('instanceOf' === $expectedType) { |
||
174 | $this->assertInstanceOf($expected, $versionCheckerMock->check()); |
||
175 | } else { |
||
176 | $versionCheckerMock->check(); |
||
177 | } |
||
178 | } |
||
179 | |||
192 |
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..