Passed
Push — 1.0.x ( 8353d5...3a2c37 )
by Julien
21:28
created

SoftDeleteConditions   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 4
eloc 15
c 3
b 0
f 0
dl 0
loc 33
ccs 0
cts 15
cp 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getSoftDeleteConditions() 0 3 1
A initializeSoftDeleteConditions() 0 5 1
A setSoftDeleteConditions() 0 3 1
A defaultSoftDeleteCondition() 0 9 1
1
<?php
2
3
/**
4
 * This file is part of the Zemit Framework.
5
 *
6
 * (c) Zemit Team <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE.txt
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Zemit\Mvc\Controller\Traits\Query\Conditions;
13
14
use Phalcon\Db\Column;
15
use Phalcon\Support\Collection;
16
use Zemit\Mvc\Controller\Traits\Abstracts\AbstractModel;
17
use Zemit\Mvc\Controller\Traits\Abstracts\AbstractQuery;
18
19
trait SoftDeleteConditions
20
{
21
    use AbstractModel;
22
    use AbstractQuery;
23
    
24
    protected ?Collection $softDeleteConditions;
25
    
26
    public function initializeSoftDeleteConditions(): void
27
    {
28
        $this->setSoftDeleteConditions(new Collection([
29
            'default' => $this->defaultSoftDeleteCondition(),
30
        ], false));
31
    }
32
    
33
    public function setSoftDeleteConditions(?Collection $softDeleteConditions): void
34
    {
35
        $this->softDeleteConditions = $softDeleteConditions;
36
    }
37
    
38
    public function getSoftDeleteConditions(): ?Collection
39
    {
40
        return $this->softDeleteConditions;
41
    }
42
    
43
    public function defaultSoftDeleteCondition(): array|string|null
44
    {
45
        $field = $this->appendModelName('deleted');
46
        $bindKey = $this->generateBindKey('deleted');
47
        
48
        return [
49
            "{$field} = :{$bindKey}:",
50
            [$bindKey => 0],
51
            [$bindKey => Column::BIND_PARAM_INT],
52
        ];
53
    }
54
}
55