Bag   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 6
eloc 12
c 2
b 0
f 0
dl 0
loc 32
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A count() 0 3 1
A __construct() 0 3 1
A getCollection() 0 12 3
A clear() 0 3 1
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