CommandMiddleware::process()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 3
c 2
b 0
f 0
dl 0
loc 7
rs 10
cc 2
nc 2
nop 2
1
<?php
2
namespace PortlandLabs\Slackbot\Slack\Rtm\Event\Middleware;
3
4
use PortlandLabs\Slackbot\Bot;
5
use PortlandLabs\Slackbot\Slack\Api\Client;
6
use PortlandLabs\Slackbot\Slack\Rtm\Event;
7
use PortlandLabs\Slackbot\Slack\Rtm\Event\Handler;
8
use PortlandLabs\Slackbot\Slack\Rtm\Event\Middleware;
9
10
class CommandMiddleware implements Middleware
11
{
12
13
    /** @var Client */
14
    protected $bot;
15
16
    public function __construct(Bot $bot)
17
    {
18
        $this->bot = $bot;
0 ignored issues
show
Documentation Bug introduced by
It seems like $bot of type PortlandLabs\Slackbot\Bot is incompatible with the declared type PortlandLabs\Slackbot\Slack\Api\Client of property $bot.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
19
    }
20
21
    /**
22
     * Process an incoming event modifying it as needed
23
     * The returned event should optionally be passed to the next $handler
24
     *
25
     * @param Event $event
26
     * @param Handler $handler
27
     * @return Event
28
     */
29
    public function process(Event $event, Handler $handler): Event
30
    {
31
        if ($event instanceof Event\Message) {
32
            $this->bot->commands()->handle($event);
0 ignored issues
show
Bug introduced by
The method commands() does not exist on PortlandLabs\Slackbot\Slack\Api\Client. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

32
            $this->bot->/** @scrutinizer ignore-call */ 
33
                        commands()->handle($event);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
33
        }
34
35
        return $handler->handle($event);
36
    }
37
}