Passed
Push — master ( f2e1d1...eea237 )
by Divine Niiquaye
03:30
created

ControllerEvent::getReflection()   A

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 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of DivineNii opensource projects.
7
 *
8
 * PHP version 7.4 and above required
9
 *
10
 * @author    Divine Niiquaye Ibok <[email protected]>
11
 * @copyright 2019 DivineNii (https://divinenii.com/)
12
 * @license   https://opensource.org/licenses/BSD-3-Clause License
13
 *
14
 * For the full copyright and license information, please view the LICENSE
15
 * file that was distributed with this source code.
16
 */
17
18
namespace Rade\Event;
19
20
use Psr\Http\Message\ServerRequestInterface as Request;
21
use Rade\Application;
22
23
/**
24
 * Allows filtering of controller arguments.
25
 *
26
 * You can call getController() to retrieve the controller and getArguments
27
 * to retrieve the current arguments. With setArguments() you can replace
28
 * arguments that are used to call the controller.
29
 *
30
 * Arguments set in the event must be compatible with the signature of the controller.
31
 *
32
 * @author Divine Niiquaye Ibok <[email protected]>
33
 */
34
final class ControllerEvent extends KernelEvent
35
{
36
    /** @var array<int|string,mixed> */
37
    private array $arguments;
38
39
    /** @var mixed */
40
    private $controller;
41
42
    /**
43
     * @param mixed $controller
44
     */
45 4
    public function __construct(Application $app, Request $request, $controller, array $arguments)
46
    {
47 4
        parent::__construct($app, $request);
48
49 4
        $this->controller = $controller;
50 4
        $this->arguments = $arguments;
51
    }
52
53
    /**
54
     * @return mixed
55
     */
56 4
    public function getController()
57
    {
58 4
        return $this->controller;
59
    }
60
61
    /**
62
     * @param mixed $controller
63
     */
64
    public function setController($controller): void
65
    {
66
        $this->controller = $controller;
67
    }
68
69 4
    public function getArguments(): array
70
    {
71 4
        return $this->arguments;
72
    }
73
74
    public function setArguments(array $arguments): void
75
    {
76
        $this->arguments = $arguments;
77
    }
78
79
    /**
80
     * @param mixed $value
81
     */
82
    public function setArgument(string $name, $value): void
83
    {
84
        $this->arguments[$name] = $value;
85
    }
86
}
87