SoftDelete   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 30
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A onDelete() 0 3 1
A onNewQuery() 0 7 1
A __construct() 0 3 1
A getName() 0 3 1
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