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

AbstractEvent   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 87.5%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 38
ccs 7
cts 8
cp 0.875
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A has() 0 4 1
A get() 0 8 2
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