| Conditions | 1 |
| Paths | 1 |
| Total Lines | 65 |
| 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 |
||
| 122 | public function testUnpackAggregatedClaimsWithSignedJWT(): void |
||
| 123 | { |
||
| 124 | $jwk = JWKFactory::createRSAKey(2048, ['alg' => 'RS256', 'use' => 'sig']); |
||
| 125 | $jwkPublic = $jwk->toPublic(); |
||
| 126 | |||
| 127 | $jwsBuilder = new JWSBuilder(new AlgorithmManager([new RS256()])); |
||
| 128 | $serializer = new CompactSerializer(); |
||
| 129 | $jws = $jwsBuilder->create() |
||
| 130 | ->withPayload((string) json_encode([ |
||
| 131 | 'eye_color' => 'blue', |
||
| 132 | ])) |
||
| 133 | ->addSignature($jwk, ['alg' => 'RS256', 'use' => 'sig']) |
||
| 134 | ->build(); |
||
| 135 | |||
| 136 | $jwt = $serializer->serialize($jws, 0); |
||
| 137 | |||
| 138 | $algorithmManager = $this->prophesize(AlgorithmManager::class); |
||
| 139 | $JWSVerifier = $this->prophesize(JWSVerifier::class); |
||
| 140 | $client = $this->prophesize(ClientInterface::class); |
||
| 141 | $issuer = $this->prophesize(IssuerInterface::class); |
||
| 142 | $issuerMetadata = $this->prophesize(IssuerMetadataInterface::class); |
||
| 143 | $issuerBuilder = $this->prophesize(IssuerBuilderInterface::class); |
||
| 144 | $issuerJwksProvider = $this->prophesize(JwksProviderInterface::class); |
||
| 145 | |||
| 146 | $algorithm = new RS256(); |
||
| 147 | $algorithmManager->get('RS256')->willReturn($algorithm); |
||
| 148 | |||
| 149 | $JWSVerifier->verifyWithKey(Argument::type(JWS::class), Argument::that(function (JWK $key) use ($jwkPublic) { |
||
| 150 | return $jwkPublic->all() === $key->all(); |
||
| 151 | }), 0) |
||
| 152 | ->willReturn(true); |
||
| 153 | |||
| 154 | $client->getIssuer()->willReturn($issuer->reveal()); |
||
| 155 | $issuerMetadata->getIssuer()->willReturn('foo-issuer'); |
||
| 156 | $issuer->getMetadata()->willReturn($issuerMetadata->reveal()); |
||
| 157 | $issuer->getJwksProvider()->willReturn($issuerJwksProvider->reveal()); |
||
| 158 | $issuerJwksProvider->getJwks()->willReturn([ |
||
| 159 | 'keys' => [ |
||
| 160 | $jwkPublic->all(), |
||
| 161 | ], |
||
| 162 | ]); |
||
| 163 | |||
| 164 | $service = new AggregateParser( |
||
| 165 | $issuerBuilder->reveal(), |
||
| 166 | $algorithmManager->reveal(), |
||
| 167 | $JWSVerifier->reveal() |
||
| 168 | ); |
||
| 169 | |||
| 170 | $claims = [ |
||
| 171 | 'sub' => 'foo', |
||
| 172 | '_claim_names' => [ |
||
| 173 | 'eye_color' => 'src1', |
||
| 174 | ], |
||
| 175 | '_claim_sources' => [ |
||
| 176 | 'src1' => [ |
||
| 177 | 'JWT' => $jwt, |
||
| 178 | ], |
||
| 179 | ], |
||
| 180 | ]; |
||
| 181 | |||
| 182 | $unpacked = $service->unpack($client->reveal(), $claims); |
||
| 183 | |||
| 184 | static::assertSame('blue', $unpacked['eye_color'] ?? null); |
||
| 185 | static::assertArrayNotHasKey('_claim_names', $unpacked); |
||
| 186 | static::assertArrayNotHasKey('_claim_sources', $unpacked); |
||
| 187 | } |
||
| 189 |