Test Failed
Push — master ( f1767b...06a3a6 )
by Divine Niiquaye
03:30
created

ControllerEvent   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Test Coverage

Coverage 57.14%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 57
ccs 8
cts 14
cp 0.5714
rs 10
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getReflection() 0 3 1
A getController() 0 3 1
A getArguments() 0 3 1
A setController() 0 3 1
A setArguments() 0 3 1
A __construct() 0 7 1
A setArgument() 0 3 1
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
    private \ReflectionFunctionAbstract $ref;
37
    private array $arguments;
38
39
    /** @var mixed */
40 4
    private $controller;
41
42 4
    /**
43
     * @param mixed $controller
44 4
     */
45 4
    public function __construct(Application $app, $controller, \ReflectionFunctionAbstract $ref, array $arguments, Request $request)
46
    {
47
        parent::__construct($app, $request);
48
49
        $this->controller = $controller;
50
        $this->arguments = $arguments;
51 4
        $this->ref = $ref;
52
    }
53 4
54
    public function getReflection(): \ReflectionFunctionAbstract
55
    {
56
        return $this->ref;
57
    }
58
59
    /**
60
     * @return mixed
61
     */
62
    public function getController()
63
    {
64 4
        return $this->controller;
65
    }
66 4
67
    /**
68
     * @param mixed $controller
69
     */
70
    public function setController($controller): void
71
    {
72
        $this->controller = $controller;
73
    }
74
75
    public function getArguments(): array
76
    {
77
        return $this->arguments;
78
    }
79
80
    public function setArguments(array $arguments): void
81
    {
82
        $this->arguments = $arguments;
83
    }
84
85
    /**
86
     * @param mixed $value
87
     */
88
    public function setArgument(string $name, $value): void
89
    {
90
        $this->arguments[$name] = $value;
91
    }
92
}
93