Completed
Push — master ( 1be76b...833b1a )
by Dev
02:38
created

CrawlerRestart::getHarvest()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 3

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 16
ccs 10
cts 10
cp 1
rs 9.9666
c 0
b 0
f 0
cc 3
nc 3
nop 1
crap 3
1
<?php
2
3
namespace PiedWeb\SeoPocketCrawler;
4
5
use PiedWeb\UrlHarvester\Harvest;
6
use PiedWeb\Curl\ResponseFromCache;
7
8
class CrawlerRestart extends CrawlerContinue
9
{
10 3
    public function __construct(string $id, bool $fromCache = false)
11
    {
12 3
        $this->fromCache = $fromCache;
13
14 3
        parent::__construct($id);
15 3
    }
16
17 3
    protected function loadFromPreviousCrawl(string $startUrl)
18
    {
19 3
        $this->urls[$startUrl] = null;
20 3
    }
21
22 3
    protected function getHarvest(Url $url)
23
    {
24 3
        if ( $this->fromCache === true) {
25 3
            $filePath = $this->recorder->getCacheFilePath($url);
26 3
            if (file_exists($filePath)) {
27 2
                $response = new ResponseFromCache(
28 2
                    $filePath,
29 2
                    $this->base.$url->uri,
30 2
                    json_decode(file_get_contents($filePath.'---info'), true)
31
                );
32
33 2
                return new Harvest($response);
34
            }
35
        }
36
37 3
        return parent::getHarvest($url);
38
    }
39
}
40