Completed
Push — master ( 074443...b3b676 )
by Alexey
08:58 queued 11s
created

ImmutableZipContainer   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 11
c 1
b 0
f 1
dl 0
loc 62
ccs 10
cts 10
cp 1
rs 10
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A count() 0 3 1
A getEntries() 0 3 1
A getArchiveComment() 0 3 1
A __construct() 0 4 1
A __clone() 0 4 2
1
<?php
2
3
namespace PhpZip\Model;
4
5
/**
6
 * Class ImmutableZipContainer.
7
 */
8
class ImmutableZipContainer implements \Countable
9
{
10
    /** @var ZipEntry[] */
11
    protected $entries;
12
13
    /** @var string|null Archive comment */
14
    protected $archiveComment;
15
16
    /**
17
     * ZipContainer constructor.
18
     *
19
     * @param ZipEntry[]  $entries
20
     * @param string|null $archiveComment
21
     */
22 175
    public function __construct(array $entries, $archiveComment)
23
    {
24 175
        $this->entries = $entries;
25 175
        $this->archiveComment = $archiveComment;
26 175
    }
27
28
    /**
29
     * @return ZipEntry[]
30
     */
31 99
    public function &getEntries()
32
    {
33 99
        return $this->entries;
34
    }
35
36
    /**
37
     * @return string|null
38
     */
39 88
    public function getArchiveComment()
40
    {
41 88
        return $this->archiveComment;
42
    }
43
44
    /**
45
     * Count elements of an object.
46
     *
47
     * @see https://php.net/manual/en/countable.count.php
48
     *
49
     * @return int The custom count as an integer.
50
     *             The return value is cast to an integer.
51
     */
52 82
    public function count()
53
    {
54 82
        return \count($this->entries);
55
    }
56
57
    /**
58
     * When an object is cloned, PHP 5 will perform a shallow copy of all of the object's properties.
59
     * Any properties that are references to other variables, will remain references.
60
     * Once the cloning is complete, if a __clone() method is defined,
61
     * then the newly created object's __clone() method will be called, to allow any necessary properties that need to
62
     * be changed. NOT CALLABLE DIRECTLY.
63
     *
64
     * @see https://php.net/manual/en/language.oop5.cloning.php
65
     */
66
    public function __clone()
67
    {
68
        foreach ($this->entries as $key => $value) {
69
            $this->entries[$key] = clone $value;
70
        }
71
    }
72
}
73