Completed
Branch feature/pre-split (7f7f80)
by Anton
04:48
created

Record   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 36
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
B save() 0 25 4
A delete() 0 7 1
1
<?php
2
/**
3
 * components
4
 *
5
 * @author    Wolfy-J
6
 */
7
namespace Spiral\ORM;
8
9
use Spiral\Models\ActiveEntityInterface;
10
use Spiral\ORM\Commands\InsertCommand;
11
use Spiral\ORM\Commands\UpdateCommand;
12
13
/**
14
 * Adds ActiveRecord abilities to RecordEntity.
15
 */
16
abstract class Record extends RecordEntity implements ActiveEntityInterface
17
{
18
    public function save(TransactionInterface $transaction = null, bool $queueRelations = true): int
19
    {
20
        //Initial reacord command
21
        $command = $this->queueSave(false);
22
23
        if ($command instanceof InsertCommand) {
24
            $state = self::CREATED;
25
        } elseif ($command instanceof UpdateCommand) {
26
            $state = self::UPDATED;
27
        } else {
28
            $state = self::UNCHANGED;
29
        }
30
31
        if ($queueRelations) {
32
            //Mounting relation related updates
33
            $command = $this->relations->queueRelations($command);
34
        }
35
36
        //todo: saturate command
37
38
        //Registering command
39
        $transaction->addCommand($command);
0 ignored issues
show
Bug introduced by
It seems like $transaction is not always an object, but can also be of type null. Maybe add an additional type check?

If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe:

function someFunction(A $objectMaybe = null)
{
    if ($objectMaybe instanceof A) {
        $objectMaybe->doSomething();
    }
}
Loading history...
40
41
        return $state;
42
    }
43
44
    public function delete(TransactionInterface $transaction = null)
45
    {
46
        //todo: saturate command
47
48
        //saturate transaction
49
        $transaction->addCommand($this->queueDelete());
0 ignored issues
show
Bug introduced by
It seems like $transaction is not always an object, but can also be of type null. Maybe add an additional type check?

If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe:

function someFunction(A $objectMaybe = null)
{
    if ($objectMaybe instanceof A) {
        $objectMaybe->doSomething();
    }
}
Loading history...
50
    }
51
}