Completed
Push — feature/refactor-app-design ( d959a3 )
by Avtandil
03:51
created

Kernel::handle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2.0185

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 5
cts 6
cp 0.8333
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 1
crap 2.0185
1
<?php
2
/**
3
 * This file is part of the TelegramBot package.
4
 *
5
 * (c) Avtandil Kikabidze aka LONGMAN <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Longman\TelegramBot\Http;
12
13
use Longman\TelegramBot\Entities\Update;
14
use Longman\TelegramBot\Telegram;
15
16
class Kernel
17
{
18
    /**
19
     * The application implementation.
20
     *
21
     * @var \Longman\TelegramBot\Telegram
22
     */
23
    protected $app;
24
25
    /**
26
     * Create a new HTTP kernel instance.
27
     *
28
     * @param  \Longman\TelegramBot\Telegram $app
29
     *
30
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
31
     */
32 1
    public function __construct(Telegram $app)
33
    {
34 1
        $this->app = $app;
35 1
    }
36
37
    /**
38
     * Handle an incoming HTTP request.
39
     *
40
     * @param  \Longman\TelegramBot\Request2 $request
41
     *
42
     * @return \Longman\TelegramBot\Response
43
     *
44
     * @throws \Longman\TelegramBot\Exception\TelegramException
45
     */
46 1
    public function handle(Request $request)
47
    {
48 1
        $params = $request->json();
49
50 1
        $update = new Update($params->all(), $this->app->getBotUsername());
51
52 1
        if ($response = $this->app->processUpdate($update)) {
53 1
            return $response->isOk();
54
        }
55
56
        return $response;
57
    }
58
}
59