Completed
Branch feature/pre-split (7f7f80)
by Anton
05:56
created

Record::delete()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
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
}