Passed
Push — master ( ea0818...92b4a6 )
by Adrian
01:28
created

Delete::execute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 7
c 2
b 0
f 0
dl 0
loc 13
rs 10
cc 2
nc 2
nop 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Sirius\Orm\Action;
5
6
use Sirius\Orm\Entity\StateEnum;
7
8
class Delete extends BaseAction
9
{
10
    protected function execute()
11
    {
12
        $conditions = $this->getConditions();
13
14
        if (empty($conditions)) {
15
            return;
16
        }
17
18
        $delete = new \Sirius\Sql\Delete($this->mapper->getWriteConnection());
19
        $delete->from($this->mapper->getTable());
20
        $delete->whereAll($conditions, false);
21
22
        $delete->perform();
23
    }
24
25
    public function onSuccess()
26
    {
27
        if ($this->entity->getPersistenceState() !== StateEnum::DELETED) {
28
            $this->entity->setPk(null);
29
            $this->entity->setPersistenceState(StateEnum::DELETED);
30
        }
31
    }
32
}
33