Bag::clear()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Knp\FriendlyContexts\Record\Collection;
4
5
use Knp\FriendlyContexts\Record\Collection;
6
use Knp\FriendlyContexts\Reflection\ObjectReflector;
7
8
class Bag
9
{
10
    protected $reflector;
11
    protected $collections = [];
12
13
    public function __construct(ObjectReflector $reflector)
14
    {
15
        $this->reflector = $reflector;
16
    }
17
18
    public function clear()
19
    {
20
        $this->collections = [];
21
    }
22
23
    public function getCollection($entity)
24
    {
25
        foreach ($this->collections as $collection) {
26
            if ($collection->support($entity)) {
27
                return $collection;
28
            }
29
        }
30
31
        $new = new Collection($this->reflector);
32
        $new->support($entity);
33
34
        return $this->collections[] = $new;
35
    }
36
37
    public function count()
38
    {
39
        return count($this->collections);
40
    }
41
}
42