Passed
Push — develop ( 62f833...95decf )
by Septianata
11:22
created

CheckOrderStatusConversation::run()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace App\Conversations;
4
5
use App\Http\Requests\Auth\LoginRequest;
6
use App\Models\Order;
7
use App\Models\User;
8
use App\Support\Auth\MultipleIdentifier;
9
use BotMan\BotMan\Messages\Incoming\Answer;
10
use BotMan\Drivers\Telegram\Extensions\Keyboard;
11
use BotMan\Drivers\Telegram\Extensions\KeyboardButton;
12
use Illuminate\Support\Facades\Auth;
13
14
class CheckOrderStatusConversation extends Conversation
15
{
16
    use MultipleIdentifier;
17
18
    /**
19
     * Start the conversation.
20
     *
21
     * @return $this
22
     */
23
    public function run()
24
    {
25
        return $this->askCode();
26
    }
27
28
    /**
29
     * Ask order code.
30
     *
31
     * @param  string|null  $validationErrorMessage
32
     * @return $this
33
     */
34
    protected function askCode(string $validationErrorMessage = null)
35
    {
36
        $this->displayValidationErrorMessage($validationErrorMessage);
37
38
        return $this->askRenderable('conversations.check-order-status.ask-code', function (Answer $answer) {
39
            if (trim($answer->getText()) === $this->cancelText()) {
40
                return $this->cancelCheck();
41
            }
42
43
            if (!$order = Order::firstWhere('code', $answer->getText())) {
44
                return $this->askCode(trans('No Results Found.'));
0 ignored issues
show
Bug introduced by
It seems like trans('No Results Found.') can also be of type array and array; however, parameter $validationErrorMessage of App\Conversations\CheckO...Conversation::askCode() does only seem to accept null|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

44
                return $this->askCode(/** @scrutinizer ignore-type */ trans('No Results Found.'));
Loading history...
45
            }
46
47
            $order->load('customer:id,fullname', 'user:id,fullname', 'branch', 'items.denomination');
48
49
            return $this->sayRenderable('conversations.check-order-status.alert-order', compact('order'));
50
        }, additionalParameters: Keyboard::create(Keyboard::TYPE_KEYBOARD)->addRow(
51
            KeyboardButton::create($this->cancelText())
52
        )->toArray());
53
    }
54
55
    /**
56
     * Return cancel login text.
57
     *
58
     * @return string
59
     */
60
    protected function cancelText(): string
61
    {
62
        return trim(view('conversations.check-order-status.cancel')->render());
0 ignored issues
show
Bug introduced by
It seems like view('conversations.chec...atus.cancel')->render() can also be of type array; however, parameter $string of trim() does only seem to accept 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

62
        return trim(/** @scrutinizer ignore-type */ view('conversations.check-order-status.cancel')->render());
Loading history...
63
    }
64
65
    /**
66
     * Cancel check order code process.
67
     *
68
     * @return $this
69
     */
70
    protected function cancelCheck()
71
    {
72
        return $this->sayRenderable('conversations.check-order-status.alert-cancel', additionalParameters: ['reply_markup' => json_encode([
73
            'remove_keyboard' => true,
74
        ])]);
75
    }
76
}
77