Conditions | 6 |
Paths | 5 |
Total Lines | 27 |
Code Lines | 17 |
Lines | 0 |
Ratio | 0 % |
Tests | 15 |
CRAP Score | 6.0087 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
23 | 9 | public function getRobotsTxt() |
|
24 | { |
||
25 | 9 | if (null === $this->robotsTxt) { |
|
26 | 9 | $url = $this->url()->getOrigin().'/robots.txt'; |
|
27 | |||
28 | 9 | $request = $this->getResponse()->getRequest(); |
|
29 | 9 | $userAgent = $request ? $request->getUserAgent() : Harvest::DEFAULT_USER_AGENT; |
|
30 | |||
31 | 9 | $request = new CurlRequest($url); |
|
32 | $request |
||
33 | 9 | ->setDefaultSpeedOptions() |
|
34 | 9 | ->setDownloadOnly('0-500000') |
|
35 | 9 | ->setUserAgent($userAgent) |
|
36 | ; |
||
37 | 9 | $result = $request->exec(); |
|
38 | |||
39 | 9 | if (!$result instanceof \PiedWeb\Curl\Response |
|
40 | 9 | || false === stripos($result->getContentType(), 'text/plain') |
|
41 | 9 | || empty(trim($result->getContent())) |
|
42 | ) { |
||
43 | $this->robotsTxt = ''; |
||
44 | } else { |
||
45 | 9 | $this->robotsTxt = new RobotsTxt($result->getContent()); |
|
46 | } |
||
47 | } |
||
48 | |||
49 | 9 | return $this->robotsTxt; |
|
50 | } |
||
64 |