Total Complexity | 8 |
Total Lines | 82 |
Duplicated Lines | 0 % |
Coverage | 94.74% |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
13 | class Event |
||
14 | { |
||
15 | /** |
||
16 | * @var string |
||
17 | */ |
||
18 | protected $stage; |
||
19 | |||
20 | /** |
||
21 | * @var RecordManager |
||
22 | */ |
||
23 | protected $manager; |
||
24 | |||
25 | /** |
||
26 | * @var Record |
||
27 | */ |
||
28 | protected $record; |
||
29 | |||
30 | /** |
||
31 | * Event constructor. |
||
32 | * @param string $stage |
||
33 | * @param RecordManager $manager |
||
34 | * @param Record $record |
||
35 | */ |
||
36 | 3 | public function __construct(string $stage, RecordManager $manager, Record $record = null) |
|
37 | { |
||
38 | 3 | $this->stage = $stage; |
|
39 | 3 | $this->manager = $manager; |
|
40 | 3 | if ($record instanceof Record) { |
|
41 | $this->withRecord($record); |
||
42 | } |
||
43 | 3 | } |
|
44 | |||
45 | /** |
||
46 | * @param string $name |
||
47 | * @param RecordManager $manager |
||
48 | * @return Event |
||
49 | */ |
||
50 | 3 | public static function create(string $name, RecordManager $manager) |
|
51 | { |
||
52 | 3 | return (new self($name, $manager)); |
|
53 | } |
||
54 | |||
55 | /** |
||
56 | * @return string |
||
57 | */ |
||
58 | 3 | public function getName() |
|
59 | { |
||
60 | 3 | return EventManager::eventName($this->getStage(), $this->getManager()); |
|
61 | } |
||
62 | |||
63 | /** |
||
64 | * @return string |
||
65 | */ |
||
66 | 3 | public function getStage(): string |
|
69 | } |
||
70 | |||
71 | /** |
||
72 | * @return RecordManager |
||
73 | */ |
||
74 | 3 | public function getManager(): RecordManager |
|
75 | { |
||
76 | 3 | return $this->manager; |
|
77 | } |
||
78 | |||
79 | /** |
||
80 | * @param Record $record |
||
81 | * @return Event |
||
82 | */ |
||
83 | 1 | public function withRecord(Record $record) |
|
84 | { |
||
85 | 1 | $this->record = $record; |
|
86 | 1 | return $this; |
|
87 | } |
||
88 | |||
89 | /** |
||
90 | * @return Record |
||
91 | */ |
||
92 | 1 | public function getRecord(): Record |
|
95 | } |
||
96 | } |
||
97 |