Completed
Push — master ( a71648...4666df )
by Алексей
06:15
created

Bot::message()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1.037

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 2
cts 3
cp 0.6667
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1.037
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: akeinhell
5
 * Date: 22.06.16
6
 * Time: 12:03
7
 */
8
9
namespace Telegram;
10
11
12
use GuzzleHttp\Client;
13
use Telegram\Actions\Message;
14
use Telegram\Exceptions\TelegramCoreException;
15
use Telegram\Methods\GetMe;
16
use Telegram\Types\User;
17
18
/**
19
 * Class Bot
20
 * @package Telegram
21
 */
22
class Bot
23
{
24
    /**
25
     * Bot constructor.
26
     * @param null|string $token
27
     * @param array       $options
28
     * @throws TelegramCoreException
29 1
     */
30
    public function __construct($token = null, $options = [])
31 1
    {
32 1
        $this->token = $token ?: getenv('TELEGRAM_TOKEN');
0 ignored issues
show
Bug introduced by
The property token does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
33 1
        if (!$this->token) {
34
            throw new TelegramCoreException('Token must be defined');
35
        }
36
        $baseOptions  = [
37
            'base_uri' => sprintf('https://api.telegram.org/bot%s/', $token),
38
        ];
39
        $this->client = new Client(array_merge($baseOptions, $options));
0 ignored issues
show
Bug introduced by
The property client does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
40
    }
41 1
42
    public function message()
43 1
    {
44 1
        return new Message();
45
    }
46
47
    public function getMe()
48 1
    {
49
        $method = new GetMe($this);
50
51
        return $method();
52
    }
53
54
    public function send($method, $params = [])
55
    {
56
        $response = $this->client->post($method, ['body_params' => $params])->getBody()->__toString();
57
        $data     = json_decode($response, true);
58
        var_dump($data['result']);
0 ignored issues
show
Security Debugging Code introduced by
var_dump($data['result']); looks like debug code. Are you sure you do not want to remove it? This might expose sensitive data.
Loading history...
59
60
        return new User($data['result']);
61
62
    }
63
64
65
}