Completed
Push — master ( 1c8751...9578ed )
by Dev
10:51 queued 09:36
created

CrawlerRestart   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
eloc 13
dl 0
loc 30
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getHarvest() 0 16 3
A loadFromPreviousCrawl() 0 3 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 (true === $this->fromCache) {
25 3
            $filePath = $this->recorder->getCacheFilePath($url);
26 3
            if (file_exists($filePath)) {
27 2
                $response = new ResponseFromCache(
28 2
                    $filePath,
0 ignored issues
show
Bug introduced by
It seems like $filePath can also be of type null; however, parameter $filePathOrContent of PiedWeb\Curl\ResponseFromCache::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

28
                    /** @scrutinizer ignore-type */ $filePath,
Loading history...
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