Passed
Pull Request — master (#190)
by Arman
02:54
created

Archive   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 47
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getAdapter() 0 3 1
A __construct() 0 3 1
A __call() 0 7 2
1
<?php
2
3
/**
4
 * Quantum PHP Framework
5
 *
6
 * An open source software development framework for PHP
7
 *
8
 * @package Quantum
9
 * @author Arman Ag. <[email protected]>
10
 * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org)
11
 * @link http://quantum.softberg.org/
12
 * @since 2.9.5
13
 */
14
15
namespace Quantum\Libraries\Archive;
16
17
use Quantum\Libraries\Archive\Exceptions\ArchiveException;
18
use Quantum\Libraries\Archive\Contracts\ArchiveInterface;
19
use Quantum\Exceptions\BaseException;
20
21
/**
22
 * Class Archive
23
 * @package Quantum\Libraries\Archive
24
 * @method void setName(string $archiveName)
25
 * @method bool offsetExists(string $filename)
26
 * @method bool addEmptyDir(string $directory)
27
 * @method bool addFile(string $filePath, string $entryName)
28
 * @method bool addFromString(string $entryName, string $content)
29
 * @method bool addMultipleFiles(array $fileNames)
30
 * @method int count()
31
 * @method bool extractTo(string $pathToExtract, $files = null)
32
 * @method bool deleteFile(string $filename)
33
 * @method bool deleteMultipleFiles(array $fileNames)
34
 */
35
class Archive
36
{
37
38
    /**
39
     * Phar
40
     */
41
    const PHAR = 'phar';
42
43
    /**
44
     * Zip
45
     */
46
    const ZIP = 'zip';
47
48
    /**
49
     * @var ArchiveInterface
50
     */
51
    private $adapter;
52
53
    /**
54
     * @param ArchiveInterface $adapter
55
     */
56
    public function __construct(ArchiveInterface $adapter)
57
    {
58
        $this->adapter = $adapter;
59
    }
60
61
    /**
62
     * @return ArchiveInterface
63
     */
64
    public function getAdapter(): ArchiveInterface
65
    {
66
        return $this->adapter;
67
    }
68
69
    /**
70
     * @param string $method
71
     * @param array|null $arguments
72
     * @return mixed
73
     * @throws BaseException
74
     */
75
    public function __call(string $method, ?array $arguments)
76
    {
77
        if (!method_exists($this->adapter, $method)) {
78
            throw ArchiveException::methodNotSupported($method, get_class($this->adapter));
79
        }
80
81
        return $this->adapter->$method(...$arguments);
82
    }
83
}