Completed
Push — master ( ff35ff...cb4013 )
by ARCANEDEV
05:05
created

SoftDeleteTrait::hardDeleting()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 2
eloc 2
nc 2
nop 0
crap 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
     |  Functions
24
     | ------------------------------------------------------------------------------------------------
25
     */
26
    /**
27
     * Check if the model uses soft delete.
28
     *
29
     * @return bool
30
     */
31 280
    public static function usesSoftDelete()
32
    {
33 280
        static $softDelete;
34
35 280
        if (is_null($softDelete)) {
36 8
            $instance = new static;
37
38 8
            return $softDelete = method_exists($instance, 'withTrashed');
39
        }
40
41 280
        return $softDelete;
42
    }
43
44
    /**
45
     * Get whether user is intended to delete the model from database entirely.
46
     *
47
     * @return bool
48
     */
49 20
    protected function hardDeleting()
50
    {
51 20
        return ! $this->usesSoftDelete() || $this->forceDeleting;
52
    }
53
}
54