Completed
Pull Request — master (#64)
by Romain
04:39
created

PolicyEnforcement::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
crap 1
1
<?php
2
3
namespace Kerox\Messenger\Model\Callback;
4
5
class PolicyEnforcement
6
{
7
    /**
8
     * @var string
9
     */
10
    protected $action;
11
12
    /**
13
     * @var null|string
14
     */
15
    protected $reason;
16
17
    /**
18
     * PolicyEnforcement constructor.
19
     *
20
     * @param string      $action
21
     * @param null|string $reason
22
     */
23 2
    public function __construct(string $action, $reason)
24
    {
25 2
        $this->action = $action;
26 2
        $this->reason = $reason;
27 2
    }
28
29
    /**
30
     * @return string
31
     */
32 1
    public function getAction(): string
33
    {
34 1
        return $this->action;
35
    }
36
37
    /**
38
     * @return null|string
39
     */
40 1
    public function getReason()
41
    {
42 1
        return $this->reason;
43
    }
44
45
    /**
46
     * @param array $payload
47
     *
48
     * @return \Kerox\Messenger\Model\Callback\PolicyEnforcement
49
     */
50 1
    public static function create(array $payload): PolicyEnforcement
51
    {
52 1
        $reason = $payload['reason'] ?? null;
53
54 1
        return new static($payload['action'], $reason);
55
    }
56
}
57