Conditions | 1 |
Paths | 1 |
Total Lines | 54 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
35 | public function basicCalls() |
||
36 | { |
||
37 | $client = $this->prophesize(Client::class); |
||
38 | $tokenType = $this->prophesize(TokenType::class); |
||
39 | $responseType = $this->prophesize(ResponseType::class); |
||
40 | $responseMode = $this->prophesize(ResponseMode::class); |
||
41 | $userAccount = $this->prophesize(UserAccount::class); |
||
42 | $resourceServer = $this->prophesize(ResourceServer::class); |
||
43 | $params = [ |
||
44 | 'prompt' => 'consent login select_account', |
||
45 | 'ui_locales' => 'fr en', |
||
46 | 'scope' => 'scope1 scope2', |
||
47 | ]; |
||
48 | $authorizationRequest = new AuthorizationRequest($client->reveal(), $params); |
||
49 | |||
50 | $authorizationRequest->setTokenType($tokenType->reveal()); |
||
51 | $authorizationRequest->setResponseType($responseType->reveal()); |
||
52 | $authorizationRequest->setResponseMode($responseMode->reveal()); |
||
53 | $authorizationRequest->setRedirectUri('https://localhost'); |
||
54 | $authorizationRequest->setUserAccount($userAccount->reveal()); |
||
55 | $authorizationRequest->setResponseParameter('foo', 'bar'); |
||
56 | $authorizationRequest->setResponseHeader('X-FOO', 'bar'); |
||
57 | $authorizationRequest->setResourceServer($resourceServer->reveal()); |
||
58 | $authorizationRequest->setConsentScreenOption('foo', 'bar'); |
||
59 | |||
60 | static::assertEquals($params, $authorizationRequest->getQueryParams()); |
||
61 | static::assertFalse($authorizationRequest->hasQueryParam('client_id')); |
||
62 | static::assertTrue($authorizationRequest->hasQueryParam('prompt')); |
||
63 | static::assertEquals('consent login select_account', $authorizationRequest->getQueryParam('prompt')); |
||
64 | static::assertInstanceOf(Client::class, $authorizationRequest->getClient()); |
||
65 | static::assertInstanceOf(TokenType::class, $authorizationRequest->getTokenType()); |
||
66 | static::assertInstanceOf(ResponseType::class, $authorizationRequest->getResponseType()); |
||
67 | static::assertInstanceOf(ResponseMode::class, $authorizationRequest->getResponseMode()); |
||
68 | static::assertEquals('https://localhost', $authorizationRequest->getRedirectUri()); |
||
69 | static::assertInstanceOf(UserAccount::class, $authorizationRequest->getUserAccount()); |
||
70 | static::assertEquals(['foo' => 'bar'], $authorizationRequest->getResponseParameters()); |
||
71 | static::assertFalse($authorizationRequest->hasResponseParameter('bar')); |
||
72 | static::assertTrue($authorizationRequest->hasResponseParameter('foo')); |
||
73 | static::assertEquals('bar', $authorizationRequest->getResponseParameter('foo')); |
||
74 | static::assertEquals(['X-FOO' => 'bar'], $authorizationRequest->getResponseHeaders()); |
||
75 | static::assertFalse($authorizationRequest->hasPrompt('none')); |
||
76 | static::assertTrue($authorizationRequest->hasPrompt('login')); |
||
77 | static::assertEquals(['consent', 'login', 'select_account'], $authorizationRequest->getPrompt()); |
||
78 | static::assertTrue($authorizationRequest->hasUiLocales()); |
||
79 | static::assertEquals(['fr', 'en'], $authorizationRequest->getUiLocales()); |
||
80 | $authorizationRequest->allow(); |
||
81 | static::assertTrue($authorizationRequest->isAuthorized()); |
||
82 | $authorizationRequest->deny(); |
||
83 | static::assertFalse($authorizationRequest->isAuthorized()); |
||
84 | static::assertInstanceOf(ResourceServer::class, $authorizationRequest->getResourceServer()); |
||
85 | static::assertTrue($authorizationRequest->hasScope()); |
||
86 | static::assertEquals('scope1 scope2', $authorizationRequest->getScope()); |
||
87 | static::assertInstanceOf(DataBag::class, $authorizationRequest->getMetadata()); |
||
88 | } |
||
89 | } |
||
90 |