| Conditions | 1 |
| Paths | 1 |
| Total Lines | 62 |
| Code Lines | 44 |
| 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 |
||
| 86 | public function testUnpackAggregatedClaims(): void |
||
| 87 | { |
||
| 88 | $jwt = implode('.', [ |
||
| 89 | base64url_encode((string) json_encode(['alg' => 'none'])), |
||
| 90 | base64url_encode((string) json_encode(['age' => 30])), |
||
| 91 | '.', |
||
| 92 | ]); |
||
| 93 | |||
| 94 | $algorithmManager = $this->prophesize(AlgorithmManager::class); |
||
| 95 | $JWSVerifier = $this->prophesize(JWSVerifier::class); |
||
| 96 | $issuerBuilder = $this->prophesize(IssuerBuilderInterface::class); |
||
| 97 | $httpClient = $this->prophesize(HttpClient::class); |
||
| 98 | $requestFactory = $this->prophesize(RequestFactoryInterface::class); |
||
| 99 | $client = $this->prophesize(ClientInterface::class); |
||
| 100 | $issuer = $this->prophesize(IssuerInterface::class); |
||
| 101 | $request = $this->prophesize(RequestInterface::class); |
||
| 102 | $response = $this->prophesize(ResponseInterface::class); |
||
| 103 | $stream = $this->prophesize(StreamInterface::class); |
||
| 104 | |||
| 105 | $requestFactory->createRequest('GET', 'https://endpoint.url/claims') |
||
| 106 | ->willReturn($request->reveal()); |
||
| 107 | |||
| 108 | $request->withHeader('accept', 'application/jwt') |
||
| 109 | ->willReturn($request->reveal()); |
||
| 110 | $request->withHeader('authorization', 'Bearer ' . 'access-token') |
||
| 111 | ->willReturn($request->reveal()); |
||
| 112 | |||
| 113 | $response->getStatusCode()->willReturn(201); |
||
| 114 | $response->getBody()->willReturn($stream->reveal()); |
||
| 115 | $stream->__toString()->willReturn($jwt); |
||
| 116 | |||
| 117 | $httpClient->sendRequest($request->reveal()) |
||
| 118 | ->willReturn($response->reveal()); |
||
| 119 | |||
| 120 | $client->getIssuer()->willReturn($issuer->reveal()); |
||
| 121 | |||
| 122 | $service = new DistributedParser( |
||
| 123 | $issuerBuilder->reveal(), |
||
| 124 | $httpClient->reveal(), |
||
| 125 | $requestFactory->reveal(), |
||
| 126 | $algorithmManager->reveal(), |
||
| 127 | $JWSVerifier->reveal() |
||
| 128 | ); |
||
| 129 | |||
| 130 | $claims = [ |
||
| 131 | 'sub' => 'foo', |
||
| 132 | '_claim_names' => [ |
||
| 133 | 'age' => 'src1', |
||
| 134 | ], |
||
| 135 | '_claim_sources' => [ |
||
| 136 | 'src1' => [ |
||
| 137 | 'endpoint' => 'https://endpoint.url/claims', |
||
| 138 | 'access_token' => 'access-token', |
||
| 139 | ], |
||
| 140 | ], |
||
| 141 | ]; |
||
| 142 | |||
| 143 | $unpacked = $service->fetch($client->reveal(), $claims); |
||
| 144 | |||
| 145 | static::assertSame(30, $unpacked['age'] ?? null); |
||
| 146 | static::assertArrayNotHasKey('_claim_names', $unpacked); |
||
| 147 | static::assertArrayNotHasKey('_claim_sources', $unpacked); |
||
| 148 | } |
||
| 213 |