Completed
Push — master ( ffa897...a71648 )
by Алексей
03:11
created

Bot::__construct()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 4.125

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 11
ccs 4
cts 8
cp 0.5
rs 9.4285
cc 3
eloc 7
nc 4
nop 2
crap 4.125
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
16
/**
17
 * Class Bot
18
 * @package Telegram
19
 * @method static Message message
20
 */
21
class Bot
22
{
23
    /**
24
     * Bot constructor.
25
     * @param null|string $token
26
     * @param array       $options
27
     * @throws TelegramCoreException
28
     */
29 1
    public function __construct($token = null, $options = [])
30
    {
31 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...
32 1
        if (!$this->token) {
33 1
            throw new TelegramCoreException('Token must be defined');
34
        }
35
        $baseOptions  = [
36
            'base_uri' => sprintf('https://api.telegram.org/bot%s/', $token),
37
        ];
38
        $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...
39
    }
40
41 1
    public static function __callStatic($name, $arguments)
0 ignored issues
show
Unused Code introduced by
The parameter $arguments is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
42
    {
43 1
        $class = '\\Telegram\\Actions\\' . ucfirst($name);
44 1
        if (!class_exists($class)) {
45
            throw new TelegramCoreException('Action ' . $name . ' not exists');
46
        }
47
48 1
        return new $class;
49
    }
50
51
52
}