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

AbstractEvent::get()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 3
cts 4
cp 0.75
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
crap 2.0625
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