| Conditions | 1 |
| Paths | 1 |
| Total Lines | 78 |
| Code Lines | 59 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 14 | ||
| Bugs | 2 | Features | 2 |
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 |
||
| 97 | protected function setUp() |
||
| 98 | { |
||
| 99 | $this->spider = new Spider('http://php-spider.org/A'); |
||
| 100 | |||
| 101 | $this->requestHandler = $this->getMock('VDB\Spider\RequestHandler\RequestHandlerInterface'); |
||
| 102 | |||
| 103 | $this->hrefA = 'http://php-spider.org/A'; |
||
| 104 | $this->hrefB = 'http://php-spider.org/B'; |
||
| 105 | $this->hrefC = 'http://php-spider.org/C'; |
||
| 106 | $this->hrefD = 'http://php-spider.org/D'; |
||
| 107 | $this->hrefE = 'http://php-spider.org/E'; |
||
| 108 | $this->hrefF = 'http://php-spider.org/F'; |
||
| 109 | $this->hrefG = 'http://php-spider.org/G'; |
||
| 110 | |||
| 111 | $this->linkA = new DiscoveredUri(new Uri($this->hrefA)); |
||
| 112 | $this->linkB = new DiscoveredUri(new Uri($this->hrefB)); |
||
| 113 | $this->linkC = new DiscoveredUri(new Uri($this->hrefC)); |
||
| 114 | $this->linkD = new DiscoveredUri(new Uri($this->hrefD)); |
||
| 115 | $this->linkE = new DiscoveredUri(new Uri($this->hrefE)); |
||
| 116 | $this->linkF = new DiscoveredUri(new Uri($this->hrefF)); |
||
| 117 | $this->linkG = new DiscoveredUri(new Uri($this->hrefG)); |
||
| 118 | |||
| 119 | $this->linkA->setDepthFound(0); |
||
| 120 | $this->linkB->setDepthFound(1); |
||
| 121 | $this->linkC->setDepthFound(1); |
||
| 122 | $this->linkD->setDepthFound(2); |
||
| 123 | $this->linkE->setDepthFound(1); |
||
| 124 | $this->linkF->setDepthFound(2); |
||
| 125 | $this->linkG->setDepthFound(2); |
||
| 126 | |||
| 127 | $htmlA = file_get_contents(__DIR__ . '/Fixtures/SpiderTestHTMLResourceA.html'); |
||
| 128 | $this->responseA = new Response(200, null, $htmlA); |
||
| 129 | |||
| 130 | $htmlB = file_get_contents(__DIR__ . '/Fixtures/SpiderTestHTMLResourceB.html'); |
||
| 131 | $this->responseB = new Response(200, null, $htmlB); |
||
| 132 | |||
| 133 | $htmlC = file_get_contents(__DIR__ . '/Fixtures/SpiderTestHTMLResourceC.html'); |
||
| 134 | $this->responseC = new Response(200, null, $htmlC); |
||
| 135 | |||
| 136 | $htmlD = file_get_contents(__DIR__ . '/Fixtures/SpiderTestHTMLResourceD.html'); |
||
| 137 | $this->responseD = new Response(200, null, $htmlD); |
||
| 138 | |||
| 139 | $htmlE = file_get_contents(__DIR__ . '/Fixtures/SpiderTestHTMLResourceE.html'); |
||
| 140 | $this->responseE = new Response(200, null, $htmlE); |
||
| 141 | |||
| 142 | $htmlF = file_get_contents(__DIR__ . '/Fixtures/SpiderTestHTMLResourceF.html'); |
||
| 143 | $this->responseF = new Response(200, null, $htmlF); |
||
| 144 | |||
| 145 | $htmlG = file_get_contents(__DIR__ . '/Fixtures/SpiderTestHTMLResourceG.html'); |
||
| 146 | $this->responseG = new Response(200, null, $htmlG); |
||
| 147 | |||
| 148 | $this->linkToResponseMap[$this->linkA->toString()] = $this->responseA; |
||
| 149 | $this->linkToResponseMap[$this->linkB->toString()] = $this->responseB; |
||
| 150 | $this->linkToResponseMap[$this->linkC->toString()] = $this->responseC; |
||
| 151 | $this->linkToResponseMap[$this->linkD->toString()] = $this->responseD; |
||
| 152 | $this->linkToResponseMap[$this->linkE->toString()] = $this->responseE; |
||
| 153 | $this->linkToResponseMap[$this->linkF->toString()] = $this->responseF; |
||
| 154 | $this->linkToResponseMap[$this->linkG->toString()] = $this->responseG; |
||
| 155 | |||
| 156 | $this->requestHandler |
||
| 157 | ->expects($this->any()) |
||
| 158 | ->method('request') |
||
| 159 | ->will($this->returnCallback(array($this, 'doTestRequest'))); |
||
| 160 | |||
| 161 | $this->spider->getDownloader()->setRequestHandler($this->requestHandler); |
||
| 162 | |||
| 163 | $this->spider->getDiscovererSet()->set(new XPathExpressionDiscoverer('//a')); |
||
| 164 | |||
| 165 | $this->statsHandler = new StatsHandler(); |
||
| 166 | $this->spider->getDispatcher()->addSubscriber($this->statsHandler); |
||
| 167 | $this->spider->getQueueManager()->getDispatcher()->addSubscriber($this->statsHandler); |
||
| 168 | $this->spider->getDownloader()->getDispatcher()->addSubscriber($this->statsHandler); |
||
| 169 | |||
| 170 | $this->logHandler = new LogHandler(); |
||
| 171 | $this->spider->getDispatcher()->addSubscriber($this->logHandler); |
||
| 172 | $this->spider->getQueueManager()->getDispatcher()->addSubscriber($this->logHandler); |
||
| 173 | $this->spider->getDownloader()->getDispatcher()->addSubscriber($this->logHandler); |
||
| 174 | } |
||
| 175 | |||
| 345 |