Passed
Push — 0.7.0 ( a860c5...e442b6 )
by Alexander
03:31 queued 12s
created

Controller::callAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 3
rs 10
1
<?php 
2
3
/**
4
 * Lenevor Framework
5
 *
6
 * LICENSE
7
 *
8
 * This source file is subject to the new BSD license that is bundled
9
 * with this package in the file license.md.
10
 * It is also available through the world-wide-web at this URL:
11
 * https://lenevor.com/license
12
 * If you did not receive a copy of the license and are unable to
13
 * obtain it through the world-wide-web, please send an email
14
 * to [email protected] so we can send you a copy immediately.
15
 *
16
 * @package     Lenevor
17
 * @subpackage  Base
18
 * @link        https://lenevor.com
19
 * @copyright   Copyright (c) 2019 - 2021 Alexander Campo <[email protected]>
20
 * @license     https://opensource.org/licenses/BSD-3-Clause New BSD license or see https://lenevor.com/license or see /license.md
21
 */
22
23
namespace Syscodes\Controller;
24
25
use BadMethodCallException;
26
27
/**
28
 * This class allows you to manage the middlewares, actions and parameters 
29
 * in each controller created by the user.
30
 * 
31
 * @author Alexander Campo <[email protected]>
32
 */
33
abstract class Controller
34
{
35
    /**
36
     * The middleware registered on the controller.
37
     * 
38
     * @var array $middleware
39
     */
40
    protected $middleware = [];
41
42
    /**
43
     * Register middleware on the controller.
44
     * 
45
     * @param  \Closure|array|string  $middleware
46
     * @param  array  $options
47
     * 
48
     * @return \Syscodes\Controller\ControllerMiddlewareOptions
49
     */
50
    public function middleware($middleare, array $options = [])
51
    {
52
        foreach ((array) $middleware as $m) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $middleware does not exist. Did you maybe mean $middleare?
Loading history...
53
            $this->middleware[$m] = [
54
                'options' => &$options
55
            ];
56
        }
57
58
        return new ControllerMiddlewareOptions($options);
0 ignored issues
show
Bug introduced by
The type Syscodes\Controller\ControllerMiddlewareOptions was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
59
    }
60
61
    /**
62
     * Get the middleware assigned to the controller.
63
     * 
64
     * @return array
65
     */
66
    public function getMiddleware()
67
    {
68
        return $this->middleware;
69
    }
70
71
    /**
72
     * Execute an action on the controller.
73
     * 
74
     * @param  string  $method
75
     * @param  array  $parameters
76
     * 
77
     * @return void
78
     */
79
    public function callAction($method, $parameters)
80
    {
81
        return call_user_func_array([$this, $method], $parameters);
82
    }
83
84
    /**
85
     * Dynamically handle calls to methods on the controller.
86
     * 
87
     * @param  string  $method
88
     * @param  array  $parameters
89
     * 
90
     * @return mixed
91
     * 
92
     * @throws \BadMethodCallException
93
     */
94
    public function __call($method, $parameters)
95
    {
96
        throw new BadMethodCallException(sprintf(
97
            'Method %s::%s does not exist', static::class, $method
98
        ));
99
    }
100
}