CancellableTrait   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 6
c 1
b 0
f 0
dl 0
loc 34
ccs 8
cts 8
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A isCancelled() 0 3 1
A cancel() 0 3 1
A isPropagationStopped() 0 3 1
A getCancellationReason() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Jasny\Auth\Event;
6
7
/**
8
 * Trait for cancellable event
9
 */
10
trait CancellableTrait
11
{
12
    protected ?string $cancelled = null;
13
14
    /**
15
     * Cancel login.
16
     */
17 1
    public function cancel(string $reason): void
18
    {
19 1
        $this->cancelled = $reason;
20
    }
21
22
    /**
23
     * Is login cancelled?
24
     */
25 1
    public function isCancelled(): bool
26
    {
27 1
        return $this->cancelled !== null;
28
    }
29
30
    /**
31
     * Get reason why login was cancelled.
32
     */
33 1
    public function getCancellationReason(): string
34
    {
35 1
        return (string)$this->cancelled;
36
    }
37
38
    /**
39
     * @inheritDoc
40
     */
41 1
    final public function isPropagationStopped(): bool
42
    {
43 1
        return $this->isCancelled();
44
    }
45
}
46