SoftDeleteTrait   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 43
c 0
b 0
f 0
wmc 4
lcom 1
cbo 0
ccs 8
cts 8
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A usesSoftDelete() 0 12 2
A hardDeleting() 0 4 2
1
<?php namespace Arcanedev\LaravelNestedSet\Traits;
2
3
/**
4
 * Class     SoftDeleteTrait
5
 *
6
 * @package  Arcanedev\LaravelNestedSet\Traits
7
 * @author   ARCANEDEV <[email protected]>
8
 *
9
 * @property  bool   $forceDeleting
10
 */
11
trait SoftDeleteTrait
12
{
13
    /* -----------------------------------------------------------------
14
     |  Properties
15
     | -----------------------------------------------------------------
16
     */
17
    /**
18
     * @var \Carbon\Carbon
19
     */
20
    public static $deletedAt;
21
22
    /* -----------------------------------------------------------------
23
     |  Main Methods
24
     | -----------------------------------------------------------------
25
     */
26
    /**
27
     * Check if the model uses soft delete.
28
     *
29
     * @return bool
30
     */
31 216
    public static function usesSoftDelete()
32
    {
33 216
        static $softDelete;
34
35 216
        if (is_null($softDelete)) {
36 6
            $instance = new static;
37
38 6
            return $softDelete = method_exists($instance, 'bootSoftDeletes');
39
        }
40
41 216
        return $softDelete;
42
    }
43
44
    /**
45
     * Get whether user is intended to delete the model from database entirely.
46
     *
47
     * @return bool
48
     */
49 15
    protected function hardDeleting()
50
    {
51 15
        return ! $this->usesSoftDelete() || $this->forceDeleting;
52
    }
53
}
54