1 | <?php |
||
13 | class CatchAll extends BaseHandler |
||
14 | { |
||
15 | /** |
||
16 | * If this function returns true, the handle method will get called. |
||
17 | * |
||
18 | * @param \Spatie\SlashCommand\Request $request |
||
19 | * |
||
20 | * @return bool |
||
21 | */ |
||
22 | public function canHandle(Request $request): bool |
||
26 | |||
27 | /** |
||
28 | * Handle the given request. Remember that Slack expects a response |
||
29 | * within three seconds after the slash command was issued. If |
||
30 | * there is more time needed, dispatch a job. |
||
31 | * |
||
32 | * @param \Spatie\SlashCommand\Request $request |
||
33 | * |
||
34 | * @return \Spatie\SlashCommand\Response |
||
35 | */ |
||
36 | public function handle(Request $request): Response |
||
56 | |||
57 | protected function findAlternativeHandlers(string $command): Collection |
||
58 | { |
||
59 | $alternativeHandlers = collect(config('laravel-slack-slash-command.handlers')) |
||
60 | ->map(function (string $handlerClassName) { |
||
61 | return new $handlerClassName($this->request); |
||
62 | }) |
||
63 | ->filter(function (HandlesSlashCommand $handler) { |
||
64 | return $handler instanceof SignatureHandler; |
||
65 | }) |
||
66 | ->filter(function (SignatureHandler $handler) { |
||
67 | $signatureParts = new SignatureParts($handler->getSignature()); |
||
68 | |||
69 | return Str::is($signatureParts->getSlashCommandName(), $this->request->command); |
||
70 | }); |
||
71 | |||
72 | if (strpos($command, ':') !== false) { |
||
73 | $subHandlers = $this->findInNamespace($alternativeHandlers, $command); |
||
74 | if ($subHandlers->count()) { |
||
75 | return $subHandlers; |
||
76 | } |
||
77 | } |
||
78 | |||
79 | return $alternativeHandlers->filter(function (SignatureHandler $handler) use ($command) { |
||
80 | return levenshtein($handler->getName(), $command) <= 2; |
||
81 | }); |
||
82 | } |
||
83 | |||
84 | protected function findInNamespace(Collection $handlers, string $command): Collection |
||
95 | |||
96 | protected function getCommandListAttachment(Collection $handlers): Attachment |
||
109 | |||
110 | protected function containsHelpHandler(Collection $alternativeHandlers): bool |
||
116 | } |
||
117 |
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.