HttpClient   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 1
dl 0
loc 33
ccs 0
cts 18
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A downloadFile() 0 14 4
A prepareDirectory() 0 7 2
1
<?php
2
3
namespace Cpliakas\ManifestPublisher\Traits;
4
5
use Symfony\Component\Filesystem\Filesystem;
6
7
trait HttpClient
8
{
9
    /**
10
     * @param string  $url
11
     * @param string  $filename
12
     * @param boolean $overwrite
13
     */
14
    public function downloadFile($url, $filename, $overwrite = false)
15
    {
16
        if (file_exists($filename) && !$overwrite) {
17
           return;
18
        }
19
20
        $this->prepareDirectory(dirname($filename));
21
22
        if (!$filedata = @file_get_contents($url)) {
23
            throw new \RuntimeException(sprintf('Unable to download archive "%s"', $url));
24
        }
25
26
        file_put_contents($filename, $filedata);
27
    }
28
29
    /**
30
     * @param string $directory
31
     */
32
    public function prepareDirectory($directory)
33
    {
34
        $fs = new Filesystem();
35
        if (!$fs->exists($directory)) {
36
            $fs->mkdir($directory);
37
        }
38
    }
39
}
40