Completed
Push — master ( 666f26...e51d97 )
by Florian
02:35
created

Downloader::findDownload()   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

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 3
crap 1
1
<?php
2
3
namespace Laposte\DatanovaBundle\Service;
4
5
use Laposte\DatanovaBundle\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