Completed
Push — master ( 40a7a3...6234fd )
by Dev
02:19
created

CrawlerRestart::resetLinks()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
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 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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
16 3
        $this->resetLinks();
17 3
    }
18
19 3
    protected function resetLinks()
20
    {
21 3
        exec('rm -rf '.$this->getDataFolder().Recorder::LINKS_DIR);
22 3
        mkdir($this->getDataFolder().Recorder::LINKS_DIR);
23 3
    }
24
25 3
    protected function loadFromPreviousCrawl(string $startUrl)
26
    {
27 3
        $this->urls[$startUrl] = null;
28 3
    }
29
30 3
    protected function getHarvest(Url $url)
31
    {
32 3
        if (true === $this->fromCache) {
33 3
            $filePath = $this->recorder->getCacheFilePath($url);
34 3
            if (null !== $filePath && file_exists($filePath)) {
35 2
                $response = new ResponseFromCache(
36 2
                    $filePath,
37 2
                    $this->base.$url->uri,
38 2
                    json_decode(file_get_contents($filePath.'---info'), true)
39
                );
40
41 2
                return new Harvest($response);
42
            }
43
        }
44
45 3
        return parent::getHarvest($url);
46
    }
47
}
48