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

Record   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 23
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A save() 0 13 3
A delete() 0 6 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
        //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
}