Test Failed
Push — master ( ce60e5...378563 )
by Julien
12:41 queued 07:49
created

ProgressTrait::start()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
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\Model\Behavior;
13
14
/**
15
 * Allow to enable or disable trait
16
 * on the current model instance ($progress)
17
 * or globally for every model instance ($staticProgress)
18
 */
19
trait ProgressTrait
20
{
21
    public bool $progress = false;
22
    public static bool $staticProgress = false;
23
    
24
    /**
25
     * Return true if the behavior is progress
26
     * on the current model instance
27
     */
28 1
    public function getProgress(): bool
29
    {
30 1
        return $this->progress;
31
    }
32
    
33
    /**
34
     * Set true to enable the behavior
35
     * on the current model instance
36
     */
37
    public function setProgress(bool $progress): void
38
    {
39
        $this->progress = $progress;
40
    }
41
    
42
    /**
43
     * Return true if the behavior is progress
44
     * globally for every model instance
45
     */
46 1
    public static function getStaticProgress(): bool
47
    {
48 1
        return self::$staticProgress;
49
    }
50
    
51
    /**
52
     * Set true to enable the behavior
53
     * globally for every model instance
54
     */
55
    public static function setStaticProgress(bool $staticProgress): void
56
    {
57
        self::$staticProgress = $staticProgress;
58
    }
59
    
60
    /**
61
     * Enable the behavior
62
     * on the current model instance
63
     */
64
    public function start(): void
65
    {
66
        $this->setProgress(true);
67
    }
68
    
69
    /**
70
     * Disable the behavior
71
     * on the current model instance
72
     */
73
    public function stop(): void
74
    {
75
        $this->setProgress(false);
76
    }
77
    
78
    /**
79
     * Enable the behavior
80
     * globally for every model instance
81
     */
82
    public static function staticStart(): void
83
    {
84
        self::setStaticProgress(true);
85
    }
86
    
87
    /**
88
     * Disable the behavior
89
     * globally for every model instance
90
     */
91
    public static function staticStop(): void
92
    {
93
        self::setStaticProgress(false);
94
    }
95
    
96
    /**
97
     * Return true if the behavior is in progress
98
     * on the current model instance and globally
99
     */
100 1
    public function inProgress(): bool
101
    {
102 1
        return $this->getProgress() || self::getStaticProgress();
103
    }
104
    
105
    /**
106
     * Return true if the behavior is started
107
     * on the current model instance and globally
108
     */
109
    public function isStarted(): bool
110
    {
111
        return $this->inProgress();
112
    }
113
    
114
    /**
115
     * Return true if the behavior is stopped
116
     * on the current model instance and globally
117
     */
118
    public function isStopped(): bool
119
    {
120
        return !$this->inProgress();
121
    }
122
}
123