Completed
Branch feature/pre-split (4ff102)
by Anton
03:27
created

AbstractRelation::getClass()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * components
4
 *
5
 * @author    Wolfy-J
6
 */
7
namespace Spiral\ORM\Entities\Relations;
8
9
use Spiral\ORM\ORMInterface;
10
use Spiral\ORM\RecordInterface;
11
use Spiral\ORM\RelationInterface;
12
13
abstract class AbstractRelation implements RelationInterface
14
{
15
    /**
16
     * Indicates that relation commands must be executed prior to parent command.
17
     */
18
    const LEADING_RELATION = false;
19
20
    /**
21
     * Indication that relation have been loaded.
22
     *
23
     * @var bool
24
     */
25
    protected $loaded;
26
27
    /**
28
     * Parent record. Only read operations!
29
     *
30
     * @invisible
31
     * @var RecordInterface
32
     */
33
    protected $parent;
34
35
    /**
36
     * Class name relation points to.
37
     *
38
     * @var string
39
     */
40
    protected $class;
41
42
    /**
43
     * Relation schema, defined when ORM being compiled. Check relation config to find out what
44
     * schema producer been used for this relation accessor.
45
     *
46
     * @var array
47
     */
48
    protected $schema;
49
50
    /**
51
     * Related data.
52
     *
53
     * @invisible
54
     * @var array
55
     */
56
    protected $data = null;
57
58
    /**
59
     * Provides ability for lazy-loading model initialization and inner selects.
60
     *
61
     * @invisible
62
     * @var ORMInterface
63
     */
64
    protected $orm;
65
66
    /**
67
     * @param string       $class Owner model class name.
68
     * @param array        $schema
69
     * @param ORMInterface $orm
70
     */
71
    public function __construct(string $class, array $schema, ORMInterface $orm)
72
    {
73
        $this->class = $class;
74
        $this->schema = $schema;
75
        $this->orm = $orm;
76
    }
77
78
    /**
79
     * {@inheritdoc}
80
     */
81
    public function isLeading(): bool
82
    {
83
        return static::LEADING_RELATION;
84
    }
85
86
    /**
87
     * {@inheritdoc}
88
     */
89
    public function withContext(
90
        RecordInterface $parent,
91
        bool $loaded = false,
92
        array $data = null
93
    ): RelationInterface {
94
        $relation = clone $this;
95
        $relation->parent = $parent;
96
        $relation->loaded = $loaded;
97
        $relation->data = $data;
0 ignored issues
show
Documentation Bug introduced by
It seems like $data can be null. However, the property $data is declared as array. Maybe change the type of the property to array|null or add a type check?

Our type inference engine has found an assignment of a scalar value (like a string, an integer or null) to a property which is an array.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property.

To type hint that a parameter can be either an array or null, you can set a type hint of array and a default value of null. The PHP interpreter will then accept both an array or null for that parameter.

function aContainsB(array $needle = null, array  $haystack) {
    if (!$needle) {
        return false;
    }

    return array_intersect($haystack, $needle) == $haystack;
}

The function can be called with either null or an array for the parameter $needle but will only accept an array as $haystack.

Loading history...
98
99
        return $relation;
100
    }
101
102
    /**
103
     * {@inheritdoc}
104
     */
105
    public function getClass(): string
106
    {
107
        return $this->class;
108
    }
109
110
    /**
111
     * {@inheritdoc}
112
     */
113
    public function isLoaded(): bool
114
    {
115
        return $this->loaded;
116
    }
117
}