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

CrawlerRestart::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
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