Passed
Branch dev_2x (3e8772)
by Adrian
01:42
created

OneToOne   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 7
eloc 11
c 0
b 0
f 0
dl 0
loc 37
rs 10
1
<?php
2
declare(strict_types=1);
3
4
namespace Sirius\Orm\Blueprint\Relation;
5
6
use Sirius\Orm\Blueprint\Mapper;
7
use Sirius\Orm\Blueprint\Relation;
8
use Sirius\Orm\Helpers\Inflector;
9
use Sirius\Orm\Relation\RelationConfig;
10
11
class OneToOne extends Relation
12
{
13
    protected $type = RelationConfig::TYPE_ONE_TO_ONE;
14
15
    protected $cascade;
16
17
    /**
18
     * @return bool
19
     */
20
    public function getCascade()
21
    {
22
        return $this->cascade;
23
    }
24
25
    /**
26
     * @param bool $cascade
27
     *
28
     * @return Relation
29
     */
30
    public function setCascade(bool $cascade)
31
    {
32
        $this->cascade = $cascade;
33
34
        return $this;
35
    }
36
37
    public function setMapper(Mapper $mapper): Relation
38
    {
39
        if ($mapper && ! $this->foreignKey) {
40
            $this->foreignKey = Inflector::singularize($mapper->getName()) . '_id';
41
        }
42
43
        if ($mapper && ! $this->nativeKey) {
44
            $this->nativeKey = $mapper->getPrimaryKey();
45
        }
46
47
        return parent::setMapper($mapper);
48
    }
49
}
50