HasSomeTrait   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
dl 0
loc 32
ccs 14
cts 14
cp 1
rs 10
c 1
b 0
f 0
wmc 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A deleteChild() 0 16 5
A applyChanges() 0 4 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cycle\ORM\Relation\Traits;
6
7
use Cycle\ORM\Transaction\Pool;
8
use Cycle\ORM\Transaction\Tuple;
9
10
/**
11
 * @internal
12
 */
13
trait HasSomeTrait
14
{
15
    /**
16
     * Delete original related entity of no other objects reference to it.
17
     */
18 472
    protected function deleteChild(Pool $pool, Tuple $tuple, object $child): Tuple
19
    {
20 472
        if ($this->isNullable()) {
0 ignored issues
show
Bug introduced by
It seems like isNullable() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

20
        if ($this->/** @scrutinizer ignore-call */ isNullable()) {
Loading history...
21 48
            $rTuple = $pool->attachStore($child, false);
22 48
            $relName = $this->getTargetRelationName();
0 ignored issues
show
Bug introduced by
It seems like getTargetRelationName() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

22
            /** @scrutinizer ignore-call */ 
23
            $relName = $this->getTargetRelationName();
Loading history...
23
            // Related state
24 48
            $state = $rTuple->state;
25 48
            if (!$state->hasRelation($relName) || $state->getRelation($relName) === $tuple->entity) {
26 48
                foreach ($this->outerKeys as $outerKey) {
27 48
                    $state->register($outerKey, null);
28
                }
29 48
                $state->setRelation($relName, null);
30
            }
31 48
            return $rTuple;
32
        }
33 424
        return $pool->attachDelete($child, $this->isCascade());
0 ignored issues
show
Bug introduced by
It seems like isCascade() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

33
        return $pool->attachDelete($child, $this->/** @scrutinizer ignore-call */ isCascade());
Loading history...
34
    }
35
36
    /**
37
     * Apply inner key values to related entity
38
     *
39 994
     * @param Tuple $tuple Related tuple
40
     */
41 994
    protected function applyChanges(Tuple $parentTuple, Tuple $tuple): void
42 994
    {
43
        foreach ($this->innerKeys as $i => $innerKey) {
44
            $tuple->state->register($this->outerKeys[$i], $parentTuple->state->getValue($innerKey));
45
        }
46
    }
47
}
48