1 | <?php |
||
16 | abstract class SignatureHandler extends BaseHandler |
||
17 | { |
||
18 | /** @var string */ |
||
19 | protected $name; |
||
20 | |||
21 | /** @var string */ |
||
22 | protected $signature; |
||
23 | |||
24 | /** @var string */ |
||
25 | protected $description; |
||
26 | |||
27 | /** @var \Symfony\Component\Console\Input\StringInput */ |
||
28 | protected $input; |
||
29 | |||
30 | /** @var \Symfony\Component\Console\Input\InputDefinition */ |
||
31 | protected $inputDefinition; |
||
32 | |||
33 | /** @var bool */ |
||
34 | protected $signatureIsBound; |
||
35 | |||
36 | public function __construct(Request $request) |
||
37 | { |
||
38 | parent::__construct($request); |
||
39 | |||
40 | if (empty($this->signature)) { |
||
41 | throw InvalidHandler::signatureIsRequired(static::class); |
||
42 | } |
||
43 | |||
44 | $this->signatureIsBound = $this->bindSignature($this->signature); |
||
|
|||
45 | } |
||
46 | |||
47 | public function getName(): string |
||
48 | { |
||
49 | return $this->name; |
||
50 | } |
||
51 | |||
52 | public function getSignature(): string |
||
53 | { |
||
54 | return $this->signature; |
||
55 | } |
||
56 | |||
57 | public function getDescription(): string |
||
58 | { |
||
59 | return $this->description ?: ''; |
||
60 | } |
||
61 | |||
62 | public function getArgument($foo) |
||
63 | { |
||
64 | return $this->input->getArgument($foo); |
||
65 | } |
||
66 | |||
67 | public function getOption($foo) |
||
68 | { |
||
69 | return $this->input->getOption($foo); |
||
70 | } |
||
71 | |||
72 | public function getArguments(): array |
||
76 | |||
77 | public function getOptions(): array |
||
81 | |||
82 | /** |
||
83 | * Get the full command (eg. `/bot ping`). |
||
84 | * |
||
85 | * @return string |
||
86 | */ |
||
87 | public function getFullCommand(): string |
||
91 | |||
92 | /** |
||
93 | * Get the usage description, including parameters and options. |
||
94 | * |
||
95 | * @return string |
||
96 | */ |
||
97 | public function getHelpDescription(): string |
||
113 | |||
114 | public function canHandle(Request $request): bool |
||
133 | |||
134 | protected function bindSignature() |
||
167 | } |
||
168 |
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.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.