Completed
Push — master ( 8112b0...bcd086 )
by Faiz
02:39
created

Downloader   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

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

3 Methods

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