ReadonlyCollection::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
nc 1
cc 1
eloc 2
nop 1
crap 1
1
<?php
2
3
namespace Nayjest\Collection\Decorator;
4
5
use Nayjest\Collection\Collection;
6
use Nayjest\Collection\CollectionReadInterface;
7
use Nayjest\Collection\CollectionReadTrait;
8
9
/**
10
 * Collection wrapper that allows only operations for data reading.
11
 */
12
class ReadonlyCollection implements CollectionReadInterface
13
{
14
    use CollectionReadTrait;
15
16
    private $collection;
17
    private $data;
18
19
    /**
20
     * Constructor.
21
     *
22
     * @param CollectionReadInterface $collection wrapped collection
23
     */
24 9
    public function __construct(CollectionReadInterface $collection)
25
    {
26 9
        $this->collection = $collection;
27 9
    }
28
29 1
    protected function createCollection(array $items)
30
    {
31 1
        return new static(new Collection($items));
32
    }
33
34 9
    protected function &items()
35
    {
36 9
        $this->data = $this->collection->toArray();
37
38 9
        return $this->data;
39
    }
40
}
41