Completed
Push — master ( b59592...c78116 )
by Faiz
01:47
created

Downloader::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace FaizShukri\Quran\Supports;
4
5
use GuzzleHttp\Client;
6
7
class Downloader
8
{
9
    private $config;
10
11 57
    public function __construct(Config $config)
12
    {
13 57
        $this->config = $config;
14 57
    }
15
16 57
    public function sync($type = 'xml')
17
    {
18
        // Download quran data
19 57
        foreach ($this->config->get('translations') as $tr) {
20 57
            $file = $this->config->get('storage_path') . '/' . $tr . '.' . $type;
21
22 57
            if (!file_exists($file)) {
23 3
                $url = 'http://tanzil.net/trans/?transID=' . $tr . '&type=' . $type;
24 3
                $this->download($url, $file);
25 3
            }
26 57
        }
27 57
    }
28
29 3
    public function download($url, $destination)
30
    {
31 3
        $client = new Client();
32 3
        $res = $client->get($url);
33 3
        file_put_contents($destination, $res->getBody());
34 3
    }
35
}
36