Passed
Push — develop ( 209048...cb8559 )
by Septianata
02:54
created

ExampleConversation::askReason()   A

Complexity

Conditions 3
Paths 1

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 13
nc 1
nop 0
dl 0
loc 20
ccs 0
cts 14
cp 0
crap 12
rs 9.8333
c 1
b 0
f 0
1
<?php
2
3
namespace App\Conversations;
4
5
use Illuminate\Foundation\Inspiring;
6
use BotMan\BotMan\Messages\Incoming\Answer;
7
use BotMan\BotMan\Messages\Outgoing\Question;
8
use BotMan\BotMan\Messages\Outgoing\Actions\Button;
9
use BotMan\BotMan\Messages\Conversations\Conversation;
10
use Illuminate\Support\Facades\Http;
11
12
class ExampleConversation extends Conversation
13
{
14
    /**
15
     * Start the conversation.
16
     *
17
     * {@inheritDoc}
18
     */
19
    public function run()
20
    {
21
        return $this->askReason();
22
    }
23
24
    /**
25
     * Run ask reason process.
26
     *
27
     * @return $this
28
     */
29
    public function askReason()
30
    {
31
        $question = Question::create("Huh - you woke me up. What do you need?")
32
            ->fallback('Unable to ask question')
33
            ->callbackId('ask_reason')
34
            ->addButtons([
35
                Button::create('Tell a joke')->value('joke'),
36
                Button::create('Give me a fancy quote')->value('quote'),
37
            ]);
38
39
        return $this->ask($question, function (Answer $answer) {
40
            if (!$answer->isInteractiveMessageReply()) {
41
                return;
42
            }
43
44
            $response = $answer->getValue() === 'joke'
45
                ? Http::get('http://api.icndb.com/jokes/random')->json('value.joke')
46
                : Inspiring::quote();
47
48
            $this->say($response);
0 ignored issues
show
Bug introduced by
It seems like $response can also be of type array and array and array and array<mixed,array|mixed|null>; however, parameter $message of BotMan\BotMan\Messages\C...ons\Conversation::say() does only seem to accept BotMan\BotMan\Messages\Outgoing\Question|string, maybe add an additional type check? ( Ignorable by Annotation )

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

48
            $this->say(/** @scrutinizer ignore-type */ $response);
Loading history...
49
        });
50
    }
51
}
52