Completed
Push — master ( a2b567...2ce769 )
by Dev
02:37 queued 57s
created

Recorder   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 95%

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 41
ccs 19
cts 20
cp 0.95
rs 10
c 0
b 0
f 0
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A recordOutboundLink() 0 6 1
A record() 0 19 3
A recordInboundLink() 0 3 1
1
<?php
2
3
namespace PiedWeb\SeoPocketCrawler;
4
5
class Recorder
6
{
7
    protected $folder;
8
9 3
    public function __construct($folder)
10
    {
11 3
        $this->folder = $folder;
12 3
    }
13
14 3
    public function record(array $urls)
15
    {
16 3
        $fp = fopen($this->folder.'/index.csv', 'w');
17
18 3
        if ($fp) {
0 ignored issues
show
introduced by
$fp is of type false|resource, thus it always evaluated to false.
Loading history...
19 3
            $header = array_keys(get_object_vars(array_values($urls)[0]));
20 3
            fputcsv($fp, $header);
21
22 3
            foreach ($urls as $url) {
23 3
                fputcsv($fp, get_object_vars($url));
24
            }
25
26 3
            fclose($fp);
27
28
29 3
            return true;
30
        }
31
32
        return false;
33
    }
34
35 2
    public function recordInboundLink(Url $from, Url $to)
36
    {
37 2
        file_put_contents($this->folder.'/links/To_'.$to->sha1.'.txt', $from->uri, FILE_APPEND);
38 2
    }
39
40 2
    public function recordOutboundLink(Url $from, array $links)
41
    {
42
        $links = array_map(function ($link) {
43 2
            return $link->getUrl();
44 2
        }, $links);
45 2
        file_put_contents($this->folder.'/links/From_'.$from->sha1.'.txt', implode(PHP_EOL, $links));
46 2
    }
47
}
48