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

ImmutableZipContainer::__clone()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 2
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 4
ccs 0
cts 0
cp 0
crap 6
rs 10
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