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

ZipArchiver   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 24
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A unarchive() 0 14 3
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