SoftDelete::onNewQuery()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
c 0
b 0
f 0
nc 1
nop 2
dl 0
loc 7
rs 10
1
<?php
2
declare(strict_types=1);
3
4
namespace Sirius\Orm\Behaviour;
5
6
use Sirius\Orm\Action\ActionInterface;
7
use Sirius\Orm\Action\BaseAction;
8
use Sirius\Orm\Action\Delete;
9
use Sirius\Orm\Mapper;
10
use Sirius\Orm\Query;
11
12
class SoftDelete implements BehaviourInterface
13
{
14
15
    /**
16
     * @var string
17
     */
18
    protected $column;
19
20
    public function __construct($column = 'deleted_at')
21
    {
22
        $this->column = $column;
23
    }
24
25
    public function getName()
26
    {
27
        return 'soft_delete';
28
    }
29
30
    public function onDelete(Mapper $mapper, Delete $delete)
31
    {
32
        return new \Sirius\Orm\Action\SoftDelete($mapper, $delete->getEntity(), ['deleted_at_column' => $this->column]);
33
    }
34
35
    public function onNewQuery(/** @scrutinizer ignore-unused */Mapper $mapper, Query $query)
36
    {
37
        $query->setGuards([
38
            $this->column => null
39
        ]);
40
41
        return $query;
42
    }
43
}
44