Completed
Push — master ( 7ba6fb...31ed5b )
by Dev
39:27 queued 38:12
created

Recorder::recordOutboundLink()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1.037

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
ccs 2
cts 3
cp 0.6667
crap 1.037
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace PiedWeb\SeoPocketCrawler;
4
5
class Recorder
6
{
7 2
    public function __construct($folder)
8
    {
9 2
        $this->folder = $folder;
0 ignored issues
show
Bug Best Practice introduced by
The property folder does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
10 2
    }
11
12 2
    public function record(array $urls)
13
    {
14 2
        $fp = fopen($this->folder.'/index.csv', 'w');
15
16 2
        $header = array_keys(get_object_vars(array_values($urls)[0]));
17 2
        fputcsv($fp, $header);
0 ignored issues
show
Bug introduced by
It seems like $fp can also be of type false; however, parameter $handle of fputcsv() does only seem to accept resource, 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

17
        fputcsv(/** @scrutinizer ignore-type */ $fp, $header);
Loading history...
18
19 2
        foreach ($urls as $url) {
20 2
            fputcsv($fp, get_object_vars($url));
21
        }
22
23 2
        fclose($fp);
0 ignored issues
show
Bug introduced by
It seems like $fp can also be of type false; however, parameter $handle of fclose() does only seem to accept resource, 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

23
        fclose(/** @scrutinizer ignore-type */ $fp);
Loading history...
24 2
    }
25
26 2
    public function recordInboundLink(Url $from, Url $to)
27
    {
28 2
        file_put_contents($this->folder.'/links/To_'.$to->sha1.'.txt', $from->uri, FILE_APPEND);
29 2
    }
30
31 2
    public function recordOutboundLink(Url $from, array $links)
32
    {
33
        $links = array_map(function ($link) { return $link->getUrl(); }, $links);
34 2
        file_put_contents($this->folder.'/links/From_'.$from->sha1.'.txt', implode(PHP_EOL, $links));
35 2
    }
36
}
37