Completed
Branch feature/pre-split (4cb052)
by Anton
03:34
created

Record::primaryKey()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
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;
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
        //saturate transaction
21
        $transaction->addCommand($command = $this->queueSave($queueRelations));
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...
22
23
        if ($command instanceof InsertCommand) {
24
            return self::CREATED;
25
        } elseif ($command instanceof UpdateCommand) {
26
            return self::UPDATED;
27
        }
28
29
        return self::UNCHANGED;
30
    }
31
32
    public function delete(TransactionInterface $transaction = null)
33
    {
34
        //saturate transaction
35
36
        $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...
37
    }
38
}