| Conditions | 1 |
| Paths | 1 |
| Total Lines | 80 |
| Code Lines | 60 |
| 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 |
||
| 34 | public function testInvokeWithNoPush() |
||
| 35 | { |
||
| 36 | $links = [ |
||
| 37 | $this->createStdClass([ |
||
| 38 | 'rel' => OptionsInterface::MODE_PRELOAD, |
||
| 39 | 'href' => '/foo.css', |
||
| 40 | ]), |
||
| 41 | $this->createStdClass([ |
||
| 42 | 'rel' => OptionsInterface::MODE_PREFETCH, |
||
| 43 | 'href' => '/bar.css', |
||
| 44 | 'as' => 'style', |
||
| 45 | 'crossorigin' => 'same-origin', |
||
| 46 | 'type' => 'text/style', |
||
| 47 | 'media' => '(min-width: 100px)', |
||
| 48 | 'nopush' => 'nopush', |
||
| 49 | ]), |
||
| 50 | $this->createStdClass([ |
||
| 51 | 'rel' => OptionsInterface::MODE_DNS_PREFETCH, |
||
| 52 | 'href' => '/foo-dns-prefetch.css', |
||
| 53 | ]), |
||
| 54 | $this->createStdClass([ |
||
| 55 | 'rel' => OptionsInterface::MODE_PRECONNECT, |
||
| 56 | 'href' => '/foo-preconnect.css', |
||
| 57 | ]), |
||
| 58 | $this->createStdClass([ |
||
| 59 | 'rel' => OptionsInterface::MODE_PRERENDER, |
||
| 60 | 'href' => '/foo-prerender.css', |
||
| 61 | ]), |
||
| 62 | ]; |
||
| 63 | |||
| 64 | $headLink = $this->prophesize(HeadLink::class); |
||
| 65 | $options = $this->prophesize(OptionsInterface::class); |
||
| 66 | $event = $this->prophesize(MvcEvent::class); |
||
| 67 | $responseHeaders = $this->prophesize(Headers::class); |
||
| 68 | $headContainer = $this->prophesize(AbstractContainer::class); |
||
| 69 | $response = $this->prophesize(PhpEnvironment\Response::class); |
||
| 70 | |||
| 71 | $options->isHttp2PushEnabled()->willReturn(false); |
||
| 72 | |||
| 73 | $headContainer->getIterator()->willReturn(new \ArrayIterator($links)); |
||
| 74 | |||
| 75 | $headLink->getContainer()->willReturn($headContainer->reveal()); |
||
| 76 | $response->getHeaders()->willReturn($responseHeaders->reveal()); |
||
| 77 | $event->getResponse()->willReturn($response->reveal()); |
||
| 78 | |||
| 79 | $responseHeaders->addHeader(Argument::allOf( |
||
| 80 | Argument::type(GenericMultiHeader::class), |
||
| 81 | Argument::which('getFieldName', 'Link'), |
||
| 82 | Argument::which('getFieldValue', '</foo.css>; rel="preload"; nopush') |
||
| 83 | )) |
||
| 84 | ->shouldBeCalled(); |
||
| 85 | $responseHeaders->addHeader(Argument::allOf( |
||
| 86 | Argument::type(GenericMultiHeader::class), |
||
| 87 | Argument::which('getFieldName', 'Link'), |
||
| 88 | Argument::which('getFieldValue', '</bar.css>; rel="prefetch"; as="style"; crossorigin="same-origin"; type="text/style"; media="(min-width: 100px)"; nopush') |
||
| 89 | )) |
||
| 90 | ->shouldBeCalled(); |
||
| 91 | $responseHeaders->addHeader(Argument::allOf( |
||
| 92 | Argument::type(GenericMultiHeader::class), |
||
| 93 | Argument::which('getFieldName', 'Link'), |
||
| 94 | Argument::which('getFieldValue', '</foo-dns-prefetch.css>; rel="dns-prefetch"; nopush') |
||
| 95 | )) |
||
| 96 | ->shouldBeCalled(); |
||
| 97 | $responseHeaders->addHeader(Argument::allOf( |
||
| 98 | Argument::type(GenericMultiHeader::class), |
||
| 99 | Argument::which('getFieldName', 'Link'), |
||
| 100 | Argument::which('getFieldValue', '</foo-preconnect.css>; rel="preconnect"; nopush') |
||
| 101 | )) |
||
| 102 | ->shouldBeCalled(); |
||
| 103 | $responseHeaders->addHeader(Argument::allOf( |
||
| 104 | Argument::type(GenericMultiHeader::class), |
||
| 105 | Argument::which('getFieldName', 'Link'), |
||
| 106 | Argument::which('getFieldValue', '</foo-prerender.css>; rel="prerender"; nopush') |
||
| 107 | )) |
||
| 108 | ->shouldBeCalled(); |
||
| 109 | |||
| 110 | $injector = new LinkHandler($headLink->reveal(), $options->reveal()); |
||
| 111 | |||
| 112 | $injector($event->reveal()); |
||
| 113 | } |
||
| 114 | |||
| 247 |