| Conditions | 1 |
| Paths | 1 |
| Total Lines | 60 |
| Code Lines | 36 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 64 | public function itCreatesADefaultClient() |
||
| 65 | { |
||
| 66 | $baseUrl = 'uri'; |
||
| 67 | |||
| 68 | $privateCertificate = DefaultCertificate::fromString('private-certificate'); |
||
| 69 | $bunqCertificate = DefaultCertificate::fromString('bunq-certificate'); |
||
| 70 | /** @var CertificateStorage|ObjectProphecy $certificateStorage */ |
||
| 71 | $certificateStorage = $this->prophesize(CertificateStorage::class); |
||
| 72 | $certificateStorage->load(CertificateType::PRIVATE_KEY())->willReturn($privateCertificate); |
||
| 73 | $certificateStorage->load(CertificateType::BUNQ_SERVER_KEY())->willReturn($bunqCertificate); |
||
| 74 | |||
| 75 | $sessionToken = DefaultToken::fromString('session-token'); |
||
| 76 | /** @var TokenService|ObjectProphecy $tokenService */ |
||
| 77 | $tokenService = $this->prophesize(TokenService::class); |
||
| 78 | $tokenService->sessionToken()->willReturn($sessionToken); |
||
| 79 | |||
| 80 | /** @var InstallationService|ObjectProphecy $installationService */ |
||
| 81 | $installationService = $this->prophesize(InstallationService::class); |
||
| 82 | |||
| 83 | /** @var TokenStorage|ObjectProphecy $tokenStorage */ |
||
| 84 | $tokenStorage = $this->prophesize(TokenStorage::class); |
||
| 85 | |||
| 86 | $client = HttpClientFactory::create( |
||
| 87 | $baseUrl, |
||
| 88 | $tokenService->reveal(), |
||
| 89 | $certificateStorage->reveal(), |
||
| 90 | $installationService->reveal(), |
||
| 91 | $tokenStorage->reveal() |
||
| 92 | ); |
||
| 93 | |||
| 94 | $expectedHandlerStack = HandlerStack::create(); |
||
| 95 | $expectedHandlerStack->push( |
||
| 96 | Middleware::mapRequest(new RequestIdMiddleware()) |
||
| 97 | ); |
||
| 98 | $expectedHandlerStack->push( |
||
| 99 | Middleware::mapRequest(new RequestAuthenticationMiddleware($sessionToken)) |
||
| 100 | ); |
||
| 101 | $expectedHandlerStack->push( |
||
| 102 | Middleware::mapRequest(new RequestSignatureMiddleware($bunqCertificate)) |
||
| 103 | ); |
||
| 104 | $expectedHandlerStack->push( |
||
| 105 | Middleware::mapResponse(new ResponseSignatureMiddleware($bunqCertificate)) |
||
| 106 | ); |
||
| 107 | $expectedHandlerStack->push( |
||
| 108 | Middleware::mapResponse(new RefreshSessionMiddleware($installationService->reveal(), $tokenStorage->reveal())) |
||
| 109 | ); |
||
| 110 | |||
| 111 | $expectedClient = new \GuzzleHttp\Client( |
||
| 112 | [ |
||
| 113 | 'base_uri' => $baseUrl, |
||
| 114 | 'handler' => $expectedHandlerStack, |
||
| 115 | 'headers' => [ |
||
| 116 | 'Content-Type' => 'application/json', |
||
| 117 | 'User-Agent' => 'bunq-api-client:user', |
||
| 118 | ], |
||
| 119 | ] |
||
| 120 | ); |
||
| 121 | |||
| 122 | $this->assertEquals($expectedClient, $client); |
||
| 123 | } |
||
| 124 | } |
||
| 126 |
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: