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

Downloader   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 5
c 3
b 0
f 0
lcom 1
cbo 2
dl 0
loc 57
ccs 20
cts 20
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A download() 0 19 3
A findDownload() 0 4 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