Action   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 71
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A middleware() 0 11 2
A getMiddleware() 0 4 1
A callAction() 0 4 1
A __call() 0 8 1
1
<?php
2
3
namespace BrightComponents\Actions;
4
5
use BadMethodCallException;
6
7
class Action
8
{
9
    /**
10
     * The middleware registered on the action.
11
     *
12
     * @var array
13
     */
14
    protected $middleware = [];
15
16
    /**
17
     * Register middleware on the action.
18
     *
19
     * @param  array|string|\Closure  $middleware
20
     * @param  array   $options
21
     *
22
     * @return \BrightComponents\Actions\ActionMiddlewareOptions
23
     */
24
    public function middleware($middleware, array $options = [])
25
    {
26
        foreach ((array) $middleware as $m) {
27
            $this->middleware[] = [
28
                'middleware' => $m,
29
                'options' => &$options,
30
            ];
31
        }
32
33
        return new ActionMiddlewareOptions($options);
34
    }
35
36
    /**
37
     * Get the middleware assigned to the action.
38
     *
39
     * @return array
40
     */
41
    public function getMiddleware()
42
    {
43
        return $this->middleware;
44
    }
45
46
    /**
47
     * Execute an action on the action.
48
     *
49
     * @param  string  $method
50
     * @param  array   $parameters
51
     *
52
     * @return \Symfony\Component\HttpFoundation\Response
53
     */
54
    public function callAction($method, $parameters)
55
    {
56
        return call_user_func_array([$this, $method], $parameters);
57
    }
58
59
    /**
60
     * Handle calls to missing methods on the action.
61
     *
62
     * @param  string  $method
63
     * @param  array   $parameters
64
     *
65
     * @throws \BadMethodCallException
66
     *
67
     * @return mixed
68
     */
69
    public function __call($method, $parameters)
70
    {
71
        throw new BadMethodCallException(sprintf(
72
            'Method %s::%s does not exist.',
73
            static::class,
74
            $method
75
        ));
76
    }
77
}
78