Completed
Push — master ( 16b7cb...b112db )
by Vladimir
07:44
created

IntentManager::setFallbackIntent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FondBot\Conversation;
6
7
use FondBot\Events\MessageReceived;
8
9
class IntentManager
10
{
11
    /** @var Intent[] */
12
    private $intents = [];
13
14
    /** @var Intent */
15
    private $fallbackIntent;
16
17
    /**
18
     * Register intents.
19
     *
20
     * @param array  $intents
21
     * @param string $fallbackIntent
22
     */
23
    public function register(array $intents, string $fallbackIntent): void
24
    {
25
        $this->intents = $intents;
26
        $this->fallbackIntent = $fallbackIntent;
0 ignored issues
show
Documentation Bug introduced by
It seems like $fallbackIntent of type string is incompatible with the declared type object<FondBot\Conversation\Intent> of property $fallbackIntent.

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...
27
    }
28
29
    /**
30
     * Find intent.
31
     *
32
     * @param MessageReceived $message
33
     *
34
     * @return Intent|null
35
     */
36
    public function find(MessageReceived $message): ?Intent
37
    {
38
        foreach ($this->intents as $intent) {
39
            foreach ($intent->activators() as $activator) {
40
                if ($activator->matches($message) && $intent->passesAuthorization($message)) {
41
                    return resolve($intent);
0 ignored issues
show
Documentation introduced by
$intent is of type object<FondBot\Conversation\Intent>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
42
                }
43
            }
44
        }
45
46
        // Otherwise, return fallback intent
47
        return resolve($this->fallbackIntent);
0 ignored issues
show
Documentation introduced by
$this->fallbackIntent is of type object<FondBot\Conversation\Intent>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
48
    }
49
}
50