Record::has()   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 1
1
<?php
2
3
namespace Knp\FriendlyContexts\Record;
4
5
use Knp\FriendlyContexts\Reflection\ObjectReflector;
6
7
class Record
8
{
9
10
    protected $reflector;
11
    protected $collection;
12
    protected $entity;
13
    protected $values;
14
15
    public function __construct(ObjectReflector $reflector, Collection $collection)
16
    {
17
        $this->reflector = $reflector;
18
        $this->collection = $collection;
19
    }
20
21
    public function attach($entity, $values = [])
22
    {
23
        if (!$this->collection->support($entity)) {
24
            throw new \InvalidArgumentException('Given entity is not supported by the collection');
25
        }
26
27
        $this->entity = $entity;
28
        $this->values = $values;
29
    }
30
31
    public function getEntity()
32
    {
33
        return $this->entity;
34
    }
35
36
    public function all()
37
    {
38
        return $this->values;
39
    }
40
41
    public function has($key)
42
    {
43
        return array_key_exists($key, $this->values);
44
    }
45
46
    public function get($key)
47
    {
48
        if ($this->has($key)) {
49
            return $this->values[$key];
50
        }
51
    }
52
53
    public function equals($key, $value)
54
    {
55
        if ($this->has($key)) {
56
            return $this->get($key) === $value;
57
        }
58
59
        return false;
60
    }
61
}
62