Event   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Test Coverage

Coverage 94.74%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 15
c 1
b 0
f 1
dl 0
loc 82
ccs 18
cts 19
cp 0.9474
rs 10
wmc 8

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getStage() 0 3 1
A getRecord() 0 3 1
A getName() 0 3 1
A withRecord() 0 4 1
A __construct() 0 6 2
A getManager() 0 3 1
A create() 0 3 1
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