Completed
Push — 2.0 ( 359ae1...221cc7 )
by Rafał
51:27 queued 18:07
created

ZipArchiver::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Superdesk Publisher Archiver Component.
7
 *
8
 * Copyright 2019 Sourcefabric z.ú. and contributors.
9
 *
10
 * For the full copyright and license information, please see the
11
 * AUTHORS and LICENSE files distributed with this source code.
12
 *
13
 * @copyright 2019 Sourcefabric z.ú
14
 * @license http://www.superdesk.org/license
15
 */
16
17
namespace SWP\Component\Archiver\Archiver;
18
19
use ZipArchive;
20
21
class ZipArchiver implements ArchiverInterface
22
{
23
    private $zip;
24
25
    public function __construct()
26
    {
27
        $this->zip = new ZipArchive();
28
    }
29
30
    public function unarchive(string $source, string $target): bool
31
    {
32
        if (false === $this->zip->open($source)) {
33
            return false;
34
        }
35
36
        if (false === $this->zip->extractTo(dirname($target))) {
37
            $this->zip->close();
38
39
            return false;
40
        }
41
42
        return $this->zip->close();
43
    }
44
}
45