Passed
Push — master ( 6042d7...377078 )
by Mihail
04:38
created

FormUpdateDownload::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 6
rs 9.4285
1
<?php
2
3
namespace Apps\Model\Admin\Main;
4
5
6
use Ffcms\Core\App;
7
use Ffcms\Core\Arch\Model;
8
use Ffcms\Core\Helper\FileSystem\File;
9
10
/**
11
 * Class FormUpdateDownload. Download update from remote url and extract it in root directory
12
 * @package Apps\Model\Admin\Main
13
 */
14
class FormUpdateDownload extends Model
15
{
16
    private $url;
17
    private $name;
18
19
    /**
20
     * FormUpdateDownload constructor. Pass download url & tag name inside
21
     * @param bool $url
22
     * @param $name
23
     */
24
    public function __construct($url, $name)
25
    {
26
        $this->url = $url;
27
        $this->name = $name;
28
        parent::__construct();
29
    }
30
31
    /**
32
     * Download archive and extract to root directory
33
     * @return bool
34
     */
35
    public function make()
36
    {
37
        $archive = $this->name . '.zip';
38
        // download archive
39
        File::saveFromUrl($this->url, '/' . $archive);
0 ignored issues
show
Bug introduced by
The method saveFromUrl() does not seem to exist on object<Ffcms\Core\Helper\FileSystem\File>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
40
        // extract archive
41
        $zip = new \ZipArchive();
42
        if ($zip->open(root . '/' . $archive) === true) {
43
            $zip->extractTo(root);
44
            $zip->close();
45
            // cleanup cache
46
            App::$Cache->clean();
47
            return true;
48
        }
49
50
        return false;
51
    }
52
}