Event::getName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

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 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace Nip\Records\EventManager\Events;
4
5
use Nip\Records\AbstractModels\Record;
6
use Nip\Records\AbstractModels\RecordManager;
7
use Nip\Records\EventManager\EventManager;
8
9
/**
10
 * Class Event
11
 * @package Nip\Records\EventManager\Events
12
 */
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
67
    {
68 3
        return $this->stage;
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
93
    {
94 1
        return $this->record;
95
    }
96
}
97