Passed
Push — master ( c93c78...d9ab06 )
by Anton
04:33 queued 02:57
created

Relation   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 13
c 1
b 0
f 0
dl 0
loc 56
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getType() 0 3 1
A __construct() 0 8 3
A getTarget() 0 3 1
A getOptions() 0 6 1
1
<?php
2
/**
3
 * Spiral Framework.
4
 *
5
 * @license   MIT
6
 * @author    Anton Titov (Wolfy-J)
7
 */
8
declare(strict_types=1);
9
10
namespace Cycle\Annotated\Annotation\Relation;
11
12
use Doctrine\Common\Annotations\Annotation\Enum;
13
use Doctrine\Common\Annotations\Annotation\Required;
14
15
abstract class Relation implements RelationInterface
16
{
17
    // relation type
18
    protected const TYPE = '';
19
20
    /**
21
     * @Required()
22
     * @var string
23
     */
24
    protected $target;
25
26
    /**
27
     * @Enum({"eager", "lazy", "promise"}
28
     * @var string
29
     */
30
    protected $load;
31
32
    /**
33
     * @param array $values
34
     */
35
    public function __construct(array $values)
36
    {
37
        foreach ($values as $key => $value) {
38
            if ($key == "fetch") {
39
                $key = "load";
40
            }
41
42
            $this->$key = $value;
43
        }
44
    }
45
46
    /**
47
     * @return string
48
     */
49
    public function getType(): string
50
    {
51
        return static::TYPE;
52
    }
53
54
    /**
55
     * @return string|null
56
     */
57
    public function getTarget(): ?string
58
    {
59
        return $this->target;
60
    }
61
62
    /**
63
     * @return array
64
     */
65
    public function getOptions(): array
66
    {
67
        $options = get_object_vars($this);
68
        unset($options['target'], $options['inverse']);
69
70
        return $options;
71
    }
72
}