Record::all()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
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()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
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)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
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