Completed
Push — master ( e8ecc6...4bc2d8 )
by Faiz
02:14
created

Downloader   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 61.11%

Importance

Changes 3
Bugs 2 Features 1
Metric Value
wmc 5
c 3
b 2
f 1
lcom 1
cbo 3
dl 0
loc 31
ccs 11
cts 18
cp 0.6111
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A sync() 0 14 3
A download() 0 6 1
1
<?php
2
3
namespace FaizShukri\Quran\Supports;
4
5
use GuzzleHttp\Client;
6
7
class Downloader
8
{
9
    private $config;
10
11 78
    public function __construct(Config $config)
12
    {
13 78
        $this->config = $config;
14 78
    }
15
16 78
    public function sync($type = 'xml')
17
    {
18 78
        $translations = (array) $this->config->get('translations');
19
20
        // Download quran data
21 78
        foreach ($translations as $tr) {
22 78
            $file = $this->config->get('storage_path').'/'.$tr.'.'.$type;
23
24 78
            if (!file_exists($file)) {
25
                $url = 'http://tanzil.net/trans/?transID='.$tr.'&type='.$type;
26 26
                $this->download($url, $file);
27
            }
28 52
        }
29 78
    }
30
31
    public function download($url, $destination)
32
    {
33
        $client = new Client();
34
        $res = $client->get($url);
35
        file_put_contents($destination, $res->getBody());
36
    }
37
}
38