Completed
Push — master ( 801ae3...f2d109 )
by Ítalo
04:18
created

AbstractConstCollectionArray::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 6
ccs 0
cts 0
cp 0
rs 9.4285
cc 2
eloc 3
nc 2
nop 1
crap 6
1
<?php
2
3
// Copyright (c) Lellys Informática. All rights reserved. See License.txt in the project root for license information.
4
namespace Collections;
5
6
use Collections\Immutable\ImmArrayList;
7
use Collections\Immutable\ImmDictionary;
8
use Collections\Immutable\ImmSet;
9
10
/**
11
 * Provides the abstract base class for a strongly typed collection.
12
 */
13
abstract class AbstractConstCollectionArray extends AbstractCollection implements
14
    CollectionInterface,
15
    CollectionConvertableInterface,
16
    \Serializable,
17
    \JsonSerializable
18
{
19
    use SortTrait;
20
21
    public function __construct($array = null)
22
    {
23
        if ($array !== null) {
24
            $this->addAll($array);
25
        }
26
    }
27 61
28
    /**
29 61
     * @var array
30 15
     */
31
    protected $container = [];
32
33
    /**
34 15
     * {@inheritdoc}
35 15
     */
36 6
    public function isEmpty()
37 6
    {
38 15
        return $this->count() === 0;
39 15
    }
40
41 15
    /**
42
     * {@inheritdoc}
43 61
     */
44
    public function count()
45
    {
46
        return count($this->container);
47
    }
48 1
49
    /**
50 1
     * {@inheritdoc}
51
     */
52
    public function clear()
53
    {
54
        $this->container = [];
55
56 7
        return $this;
57
    }
58 7
59
    /**
60
     * {@inheritdoc}
61
     */
62
    public function serialize()
63
    {
64
        return serialize($this->container);
65
    }
66
67
    /**
68
     * {@inheritdoc}
69
     */
70
    public function unserialize($serialized)
71
    {
72
        $this->container = unserialize($serialized);
73
74 2
        return $this->container;
75
    }
76 2
77
    /**
78
     * {@inheritdoc}
79
     */
80
    public function jsonSerialize()
81
    {
82 1
        return $this->container;
83
    }
84 1
85
    /**
86 1
     * {@inheritdoc}
87
     */
88
    public function toVector()
89
    {
90
        return new ArrayList($this);
91
    }
92 3
93
    /**
94 3
     * {@inheritdoc}
95 2
     */
96
    public function toImmVector()
97
    {
98 1
        return new ImmArrayList($this);
99
    }
100
101
    /**
102
     * {@inheritdoc}
103
     */
104
    public function toSet()
105
    {
106
        return new Set($this);
107
    }
108
109
    /**
110
     * {@inheritdoc}
111
     */
112
    public function toImmSet()
113 1
    {
114
        return new ImmSet($this);
115 1
    }
116
117
    /**
118
     * {@inheritdoc}
119
     */
120
    public function toMap()
121
    {
122
        return new Dictionary($this);
123
    }
124
125
    /**
126
     * {@inheritdoc}
127
     */
128
    public function toImmMap()
129
    {
130
        return new ImmDictionary($this);
131
    }
132
}
133