Downloader::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
crap 1
1
<?php
2
3
namespace Fmaj\LaposteDatanovaBundle\Service;
4
5
use Fmaj\LaposteDatanovaBundle\Client\ClientInterface;
6
7
class Downloader
8
{
9
    /** @var ClientInterface $client */
10
    private $client;
11
12
    /** @var  Finder $finder */
13
    private $finder;
14
15
    /**
16
     * @param ClientInterface $client
17
     * @param Finder $finder
18
     */
19 2
    public function __construct(ClientInterface $client, Finder $finder)
20
    {
21 2
        $this->client = $client;
22 2
        $this->finder = $finder;
23 2
    }
24
25
    /**
26
     * @param string $dataset
27
     * @param string $format
28
     * @param string $filter
29
     * @param bool $updateExisting
30
     *
31
     * @return false|string downloaded file content
32
     */
33 1
    public function download($dataset, $format, $filter = null, $updateExisting = false)
34
    {
35 1
        $result = false;
36
        $parameters = array(
37 1
            'dataset' => $dataset,
38
            'format' => $format
39 1
        );
40 1
        if (isset($filter)) {
41 1
            $parameters['q'] = $filter;
42 1
        }
43 1
        $this->client->setTimeout(0);
44 1
        $content = $this->client->get('download', $parameters);
45 1
        $save = $this->finder->save($dataset, $content, $format, $filter, $updateExisting);
46 1
        if (false !== $save) {
47 1
            $result = $this->finder->getContent($save);
48 1
        }
49
50 1
        return $result;
51
    }
52
53
    /**
54
     * @param string $dataset
55
     * @param string $format
56
     * @param string $filter
57
     * @return false|string
58
     */
59 1
    public function findDownload($dataset, $format, $filter = null)
60
    {
61 1
        return $this->finder->findDataset($dataset, $format, $filter);
62
    }
63
}
64