| Conditions | 1 |
| Paths | 1 |
| Total Lines | 55 |
| Code Lines | 25 |
| 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 |
||
| 51 | public function itCallsTheInstallationCallWithPublicKey() |
||
| 52 | { |
||
| 53 | $publicKey = DefaultCertificate::fromString('-----BEGIN PUBLIC KEY-----KEY-----END PUBLIC KEY-----'); |
||
| 54 | |||
| 55 | $this->certificateStorage->load(CertificateType::PUBLIC_KEY())->willReturn($publicKey); |
||
|
|
|||
| 56 | |||
| 57 | $postOptions = [ |
||
| 58 | 'json' => [ |
||
| 59 | 'client_public_key' => $publicKey->toString(), |
||
| 60 | ], |
||
| 61 | ]; |
||
| 62 | |||
| 63 | $expectedToken = 'installation-token'; |
||
| 64 | $expectedKey = '-----BEGIN PUBLIC KEY-----NEW-KEY-----END PUBLIC KEY-----'; |
||
| 65 | |||
| 66 | /** @var ResponseInterface|ObjectProphecy $response */ |
||
| 67 | $response = $this->prophesize(ResponseInterface::class); |
||
| 68 | $response->getBody()->willReturn( |
||
| 69 | \json_encode( |
||
| 70 | [ |
||
| 71 | 'Response' => [ |
||
| 72 | [ |
||
| 73 | 'Id' => [ |
||
| 74 | 'id' => 1, |
||
| 75 | ], |
||
| 76 | ], |
||
| 77 | [ |
||
| 78 | 'Token' => [ |
||
| 79 | 'token' => $expectedToken, |
||
| 80 | ], |
||
| 81 | ], |
||
| 82 | [ |
||
| 83 | 'ServerPublicKey' => [ |
||
| 84 | 'server_public_key' => $expectedKey, |
||
| 85 | ], |
||
| 86 | ], |
||
| 87 | ], |
||
| 88 | ] |
||
| 89 | ) |
||
| 90 | ); |
||
| 91 | |||
| 92 | $this->httpClient->request('POST', '/v1/installation', $postOptions)->willReturn( |
||
| 93 | $response->reveal() |
||
| 94 | ); |
||
| 95 | |||
| 96 | $result = $this->service->install(); |
||
| 97 | |||
| 98 | $this->assertEquals( |
||
| 99 | [ |
||
| 100 | 'token' => $expectedToken, |
||
| 101 | 'public_key' => $expectedKey, |
||
| 102 | ], |
||
| 103 | $result |
||
| 104 | ); |
||
| 105 | } |
||
| 106 | |||
| 179 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: