Completed
Pull Request — master (#132)
by
unknown
01:33
created

Archive   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 116
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 1
dl 0
loc 116
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A count() 0 4 1
A getIterator() 0 4 1
A getMembers() 0 4 1
A addMembers() 0 6 1
A removeMembers() 0 6 1
A extract() 0 6 1
A extractMembers() 0 6 1
1
<?php
2
3
/*
4
 * This file is part of Zippy.
5
 *
6
 * (c) Alchemy <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Alchemy\Zippy\Archive;
13
14
use Alchemy\Zippy\Adapter\AdapterInterface;
15
use Alchemy\Zippy\Resource\ResourceManager;
16
use Alchemy\Zippy\Adapter\Resource\ResourceInterface;
17
18
/**
19
 * Represents an archive
20
 */
21
class Archive implements ArchiveInterface
22
{
23
    /**
24
     * The path to the archive
25
     *
26
     * @var string
27
     */
28
    protected $path;
29
30
    /**
31
     * The archive adapter
32
     *
33
     * @var AdapterInterface
34
     */
35
    protected $adapter;
36
37
    /**
38
     * An array of archive members
39
     *
40
     * @var MemberInterface[]
41
     */
42
    protected $members = array();
43
44
    /**
45
     * @var ResourceInterface
46
     */
47
    protected $resource;
48
49
    /**
50
     *
51
     * @var ResourceManager
52
     */
53
    protected $manager;
54
55
    /**
56
     * Constructor
57
     *
58
     * @param ResourceInterface $resource Path to the archive
59
     * @param AdapterInterface  $adapter  An archive adapter
60
     * @param ResourceManager   $manager  The resource manager
61
     */
62
    public function __construct(ResourceInterface $resource, AdapterInterface $adapter, ResourceManager $manager)
63
    {
64
        $this->resource = $resource;
65
        $this->adapter = $adapter;
66
        $this->manager = $manager;
67
    }
68
69
    /**
70
     * @inheritdoc
71
     */
72
    public function count()
73
    {
74
        return count($this->getMembers());
75
    }
76
77
    /**
78
     * Returns an Iterator for the current archive
79
     *
80
     * This method implements the IteratorAggregate interface.
81
     *
82
     * @return \ArrayIterator|MemberInterface[] An iterator
83
     */
84
    public function getIterator()
85
    {
86
        return new \ArrayIterator($this->getMembers());
87
    }
88
89
    /**
90
     * @inheritdoc
91
     */
92
    public function getMembers()
93
    {
94
        return $this->members = $this->adapter->listMembers($this->resource);
95
    }
96
97
    /**
98
     * @inheritdoc
99
     */
100
    public function addMembers($sources, $recursive = true)
101
    {
102
        $this->adapter->add($this->resource, $sources, $recursive);
103
104
        return $this;
105
    }
106
107
    /**
108
     * @inheritdoc
109
     */
110
    public function removeMembers($sources)
111
    {
112
        $this->adapter->remove($this->resource, $sources);
113
114
        return $this;
115
    }
116
117
    /**
118
     * @inheritdoc
119
     */
120
    public function extract($toDirectory)
121
    {
122
        $this->adapter->extract($this->resource, $toDirectory);
123
124
        return $this;
125
    }
126
127
    /**
128
     * @inheritdoc
129
     */
130
    public function extractMembers($members, $toDirectory = null)
131
    {
132
        $this->adapter->extractMembers($this->resource, $members, $toDirectory);
0 ignored issues
show
Bug introduced by
It seems like $members defined by parameter $members on line 130 can also be of type array<integer,object<Alc...chive\MemberInterface>>; however, Alchemy\Zippy\Adapter\Ad...rface::extractMembers() does only seem to accept string|array<integer,string>, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
133
134
        return $this;
135
    }
136
}
137