Conditions | 1 |
Paths | 1 |
Total Lines | 66 |
Code Lines | 42 |
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 |
||
22 | public function testFetch(): void |
||
23 | { |
||
24 | $client = $this->prophesize(ClientInterface::class); |
||
25 | $requestFactory = $this->prophesize(RequestFactoryInterface::class); |
||
26 | $uriFactory = $this->prophesize(UriFactoryInterface::class); |
||
27 | $discoveryProvider = $this->prophesize(DiscoveryProviderInterface::class); |
||
28 | |||
29 | $resource = '[email protected]'; |
||
30 | $provider = new WebFingerProvider( |
||
31 | $client->reveal(), |
||
32 | $requestFactory->reveal(), |
||
33 | $uriFactory->reveal(), |
||
34 | $discoveryProvider->reveal() |
||
35 | ); |
||
36 | |||
37 | $webFingerUrl = $this->prophesize(UriInterface::class); |
||
38 | $webFingerUrl1 = $this->prophesize(UriInterface::class); |
||
39 | |||
40 | $uriFactory->createUri('https://example.com/.well-known/webfinger') |
||
41 | ->willReturn($webFingerUrl1->reveal()); |
||
42 | $webFingerUrl1->withQuery(http_build_query([ |
||
43 | 'resource' => 'acct:[email protected]', |
||
44 | 'rel' => 'http://openid.net/specs/connect/1.0/issuer', |
||
45 | ])) |
||
46 | ->willReturn($webFingerUrl->reveal()); |
||
47 | $webFingerUrl->__toString()->willReturn('https://example.com/.well-known/webfinger'); |
||
48 | |||
49 | $request = $this->prophesize(RequestInterface::class); |
||
50 | $request1 = $this->prophesize(RequestInterface::class); |
||
51 | $response = $this->prophesize(ResponseInterface::class); |
||
52 | $stream = $this->prophesize(StreamInterface::class); |
||
53 | |||
54 | $requestFactory->createRequest('GET', $webFingerUrl) |
||
55 | ->willReturn($request1->reveal()); |
||
56 | $request1->withHeader('accept', 'application/json') |
||
57 | ->willReturn($request->reveal()); |
||
58 | |||
59 | $client->sendRequest($request->reveal()) |
||
60 | ->willReturn($response->reveal()); |
||
61 | |||
62 | $response->getStatusCode()->willReturn(200); |
||
63 | $response->getBody()->willReturn($stream->reveal()); |
||
64 | |||
65 | $responsePayload = [ |
||
66 | 'links' => [ |
||
67 | [ |
||
68 | 'rel' => 'wrong-foo', |
||
69 | 'href' => 'wrong-url', |
||
70 | ], |
||
71 | [ |
||
72 | 'rel' => 'http://openid.net/specs/connect/1.0/issuer', |
||
73 | ], |
||
74 | [ |
||
75 | 'rel' => 'http://openid.net/specs/connect/1.0/issuer', |
||
76 | 'href' => 'https://openid-uri', |
||
77 | ], |
||
78 | ], |
||
79 | ]; |
||
80 | |||
81 | $stream->__toString()->willReturn(json_encode($responsePayload)); |
||
82 | |||
83 | $discoveryProvider->discovery('https://openid-uri')->willReturn([ |
||
84 | 'issuer' => 'https://openid-uri', |
||
85 | ]); |
||
86 | |||
87 | static::assertSame(['issuer' => 'https://openid-uri'], $provider->fetch($resource)); |
||
88 | } |
||
90 |