Conditions | 1 |
Paths | 1 |
Total Lines | 65 |
Code Lines | 53 |
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 |
||
60 | public function testFetchTokenFromCode(): void |
||
61 | { |
||
62 | $tokenSetFactory = $this->prophesize(TokenSetFactoryInterface::class); |
||
63 | $client = $this->prophesize(ClientInterface::class); |
||
64 | $requestFactory = $this->prophesize(RequestFactoryInterface::class); |
||
65 | $idTokenVerifierBuilder = $this->prophesize(IdTokenVerifierBuilderInterface::class); |
||
66 | $tokenVerifierBuilder = $this->prophesize(TokenVerifierBuilderInterface::class); |
||
67 | |||
68 | $service = new AuthorizationService( |
||
69 | $tokenSetFactory->reveal(), |
||
70 | $client->reveal(), |
||
71 | $requestFactory->reveal(), |
||
72 | $idTokenVerifierBuilder->reveal(), |
||
73 | $tokenVerifierBuilder->reveal() |
||
74 | ); |
||
75 | |||
76 | $openIdClient = $this->prophesize(OpenIDClient::class); |
||
77 | $openIdClient->getHttpClient()->willReturn(null); |
||
78 | $metadata = $this->prophesize(ClientMetadataInterface::class); |
||
79 | $authMethodFactory = $this->prophesize(AuthMethodFactoryInterface::class); |
||
80 | $authMethod = $this->prophesize(AuthMethodInterface::class); |
||
81 | $request = $this->prophesize(RequestInterface::class); |
||
82 | $tokenRequest1 = $this->prophesize(RequestInterface::class); |
||
83 | $tokenRequest2 = $this->prophesize(RequestInterface::class); |
||
84 | $response = $this->prophesize(ResponseInterface::class); |
||
85 | $stream = $this->prophesize(StreamInterface::class); |
||
86 | $issuer = $this->prophesize(IssuerInterface::class); |
||
87 | $issuerMetadata = $this->prophesize(IssuerMetadataInterface::class); |
||
88 | |||
89 | $claims = [ |
||
90 | 'grant_type' => 'authorization_code', |
||
91 | 'code' => 'foo-code', |
||
92 | 'redirect_uri' => 'redirect-uri', |
||
93 | ]; |
||
94 | |||
95 | $requestFactory->createRequest('POST', 'token-endpoint') |
||
96 | ->willReturn($request->reveal()); |
||
97 | $request->withHeader('content-type', 'application/x-www-form-urlencoded') |
||
98 | ->willReturn($tokenRequest1->reveal()); |
||
99 | $openIdClient->getIssuer()->willReturn($issuer->reveal()); |
||
100 | $issuer->getMetadata()->willReturn($issuerMetadata->reveal()); |
||
101 | $issuerMetadata->getTokenEndpoint()->willReturn('token-endpoint'); |
||
102 | $issuerMetadata->get('token_endpoint')->willReturn('token-endpoint'); |
||
103 | $openIdClient->getMetadata()->willReturn($metadata->reveal()); |
||
104 | $openIdClient->getAuthMethodFactory()->willReturn($authMethodFactory->reveal()); |
||
105 | $metadata->getTokenEndpointAuthMethod()->willReturn('auth-method'); |
||
106 | $metadata->get('token_endpoint_auth_method')->willReturn('auth-method'); |
||
107 | $authMethodFactory->create('auth-method')->willReturn($authMethod->reveal()); |
||
108 | $authMethod->createRequest( |
||
109 | $tokenRequest1->reveal(), |
||
110 | $openIdClient->reveal(), |
||
111 | $claims |
||
112 | ) |
||
113 | ->willReturn($tokenRequest2->reveal()); |
||
114 | |||
115 | $client->sendRequest($tokenRequest2->reveal()) |
||
116 | ->willReturn($response->reveal()); |
||
117 | $response->getStatusCode()->willReturn(200); |
||
118 | $response->getBody()->willReturn($stream->reveal()); |
||
119 | $stream->__toString()->willReturn('{"foo":"bar"}'); |
||
120 | |||
121 | $tokenSet = $this->prophesize(TokenSetInterface::class); |
||
122 | $tokenSetFactory->fromArray(['foo' => 'bar'])->willReturn($tokenSet->reveal()); |
||
123 | |||
124 | static::assertSame($tokenSet->reveal(), $service->grant($openIdClient->reveal(), $claims)); |
||
125 | } |
||
127 |