| Conditions | 1 |
| Paths | 1 |
| Total Lines | 61 |
| Code Lines | 43 |
| 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 |
||
| 150 | public function testUnpackAggregatedClaimsWithResourceError(): void |
||
| 151 | { |
||
| 152 | $jwt = implode('.', [ |
||
| 153 | base64url_encode((string) json_encode(['alg' => 'none'])), |
||
| 154 | base64url_encode((string) json_encode(['age' => 30])), |
||
| 155 | '.', |
||
| 156 | ]); |
||
| 157 | |||
| 158 | $algorithmManager = $this->prophesize(AlgorithmManager::class); |
||
| 159 | $JWSVerifier = $this->prophesize(JWSVerifier::class); |
||
| 160 | $issuerBuilder = $this->prophesize(IssuerBuilderInterface::class); |
||
| 161 | $httpClient = $this->prophesize(HttpClient::class); |
||
| 162 | $requestFactory = $this->prophesize(RequestFactoryInterface::class); |
||
| 163 | $client = $this->prophesize(ClientInterface::class); |
||
| 164 | $issuer = $this->prophesize(IssuerInterface::class); |
||
| 165 | $request = $this->prophesize(RequestInterface::class); |
||
| 166 | $response = $this->prophesize(ResponseInterface::class); |
||
| 167 | $stream = $this->prophesize(StreamInterface::class); |
||
| 168 | |||
| 169 | $requestFactory->createRequest('GET', 'https://endpoint.url/claims') |
||
| 170 | ->willReturn($request->reveal()); |
||
| 171 | |||
| 172 | $request->withHeader('accept', 'application/jwt') |
||
| 173 | ->willReturn($request->reveal()); |
||
| 174 | $request->withHeader('authorization', 'Bearer ' . 'access-token') |
||
| 175 | ->willReturn($request->reveal()); |
||
| 176 | |||
| 177 | $response->getReasonPhrase()->willReturn('foo'); |
||
| 178 | $response->getStatusCode()->willReturn(401); |
||
| 179 | $response->getBody()->willReturn($stream->reveal()); |
||
| 180 | $stream->__toString()->willReturn($jwt); |
||
| 181 | |||
| 182 | $httpClient->sendRequest($request->reveal()) |
||
| 183 | ->willReturn($response->reveal()); |
||
| 184 | |||
| 185 | $client->getIssuer()->willReturn($issuer->reveal()); |
||
| 186 | |||
| 187 | $service = new DistributedParser( |
||
| 188 | $issuerBuilder->reveal(), |
||
| 189 | $httpClient->reveal(), |
||
| 190 | $requestFactory->reveal(), |
||
| 191 | $algorithmManager->reveal(), |
||
| 192 | $JWSVerifier->reveal() |
||
| 193 | ); |
||
| 194 | |||
| 195 | $claims = [ |
||
| 196 | 'sub' => 'foo', |
||
| 197 | '_claim_names' => [ |
||
| 198 | 'age' => 'src1', |
||
| 199 | ], |
||
| 200 | '_claim_sources' => [ |
||
| 201 | 'src1' => [ |
||
| 202 | 'endpoint' => 'https://endpoint.url/claims', |
||
| 203 | 'access_token' => 'access-token', |
||
| 204 | ], |
||
| 205 | ], |
||
| 206 | ]; |
||
| 207 | |||
| 208 | $unpacked = $service->fetch($client->reveal(), $claims); |
||
| 209 | |||
| 210 | static::assertSame($claims, $unpacked); |
||
| 211 | } |
||
| 213 |