Completed
Pull Request — master (#93)
by Alessandro
02:47
created

AbstractEvent::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Paraunit\Lifecycle;
5
6
use Symfony\Component\EventDispatcher\Event;
7
8
/**
9
 * Class AbstractEvent
10
 * @package Paraunit\Lifecycle
11
 */
12
abstract class AbstractEvent extends Event
13
{
14
    /** @var array */
15
    private $context;
16
17
    /**
18
     * AbstractEvent constructor.
19
     * @param array $context
20
     */
21 54
    public function __construct(array $context = [])
22
    {
23 54
        $this->context = $context;
24
    }
25
26
    /**
27
     * @param $contextParameterName
28
     *
29
     * @return bool
30
     */
31 25
    public function has(string $contextParameterName): bool
32
    {
33 25
        return isset($this->context[$contextParameterName]);
34
    }
35
36
    /**
37
     * @param string $contextParameterName
38
     * @return mixed
39
     * @throws \LogicException If parameter is not found
40
     */
41 25
    public function get(string $contextParameterName)
42
    {
43 25
        if (! $this->has($contextParameterName)) {
44
            throw new \LogicException('Cannot find parameter: ' . $contextParameterName);
45
        }
46
47 25
        return $this->context[$contextParameterName];
48
    }
49
}
50