1 | <?php |
||
2 | |||
3 | /** |
||
4 | * This file is part of Blitz PHP framework. |
||
5 | * |
||
6 | * (c) 2022 Dimitri Sitchet Tomkeu <[email protected]> |
||
7 | * |
||
8 | * For the full copyright and license information, please view |
||
9 | * the LICENSE file that was distributed with this source code. |
||
10 | */ |
||
11 | |||
12 | namespace BlitzPHP\Middlewares; |
||
13 | |||
14 | use BlitzPHP\Utilities\String\Text; |
||
15 | |||
16 | abstract class BaseMiddleware |
||
17 | { |
||
18 | /** |
||
19 | * Liste des arguments envoyes au middleware |
||
20 | */ |
||
21 | protected array $arguments = []; |
||
22 | |||
23 | /** |
||
24 | * Liste des arguments que peut avoir le middleware |
||
25 | */ |
||
26 | protected array $fillable = []; |
||
27 | |||
28 | /** |
||
29 | * Chemin url de la requette actuelle |
||
30 | */ |
||
31 | protected string $path; |
||
32 | |||
33 | public function init(string $path): static |
||
34 | { |
||
35 | $this->path = $path; |
||
36 | |||
37 | foreach ($this->arguments as $argument => $value) { |
||
38 | if (! is_string($argument)) { |
||
39 | continue; |
||
40 | } |
||
41 | |||
42 | $method = Text::camel('set_' . $argument); |
||
43 | if (method_exists($this, $method)) { |
||
44 | call_user_func([$this, $method], $value); |
||
45 | } elseif (property_exists($this, $argument)) { |
||
46 | $this->{$argument} = $value; |
||
47 | } |
||
48 | } |
||
49 | |||
50 | return $this; |
||
51 | } |
||
52 | |||
53 | public static function make(...$args): static |
||
54 | { |
||
55 | return new static(...$args); |
||
0 ignored issues
–
show
|
|||
56 | } |
||
57 | |||
58 | public function __get($name) |
||
59 | { |
||
60 | return $this->arguments[$name] ?? null; |
||
61 | } |
||
62 | |||
63 | /** |
||
64 | * @internal |
||
65 | */ |
||
66 | final public function fill(array $params): static |
||
67 | { |
||
68 | foreach ($this->fillable as $key) { |
||
69 | if ($params === []) { |
||
70 | break; |
||
71 | } |
||
72 | $this->arguments[$key] = array_shift($params); |
||
73 | } |
||
74 | |||
75 | $this->arguments += $params; |
||
76 | |||
77 | return $this; |
||
78 | } |
||
79 | } |
||
80 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.