Test Setup Failed
Push — develop ( 01f508...e1be97 )
by Mattias
01:57
created

Bot::postDataEncoder()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
crap 2
1
<?php
2
3
namespace TelegramBot;
4
5
use TelegramBot\APIMessage;
6
7
class Bot implements BotInterface
8
{
9
    use \League\Event\EmitterTrait;
10
11
  /** @var string */
12
  private $botToken;
0 ignored issues
show
Unused Code introduced by
The property $botToken is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
13
  /** @var int */
14
  private $offset;
0 ignored issues
show
Unused Code introduced by
The property $offset is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
15
  /** @var APIPollClient */
16
  private $client;
17
18
  /**
19
   * @param APIClient $client
20
   */
21
  public function __construct(APIPollClient $client)
22
  {
23
      $this->client = $client;
24
  }
25
26
    public function poll()
27
    {
28
        $this->client->poll([$this, '_handlePollResponse']);
29
    }
30
31
  /**
32
   * @param \React\HttpClient\Response $response
33
   */
34
  public function _handlePollResponse(\React\HttpClient\Response $response)
35
  {
36
      $response->on('data', [$this, '_handlePollData']);
37
      $response->on('error', [$this, '_handlePollError']);
38
  }
39
40
  /**
41
   * @param array $data
42
   * @param \React\HttpClient\Response $response
43
   */
44
  public function _handlePollData($data, $response)
0 ignored issues
show
Unused Code introduced by
The parameter $response 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...
45
  {
46
      $data = json_decode($data, 1);
47
      $messageData = $data['result'];
48
49
      foreach ($messageData as $message) {
50
          $apiMessage = new APIMessage($message);
51
          $this->client->markMessageHandled($apiMessage);
52
53
          if (!$apiMessage->hasText()) {
54
              continue;
55
          }
56
57
          $this->getEmitter()->emit(
58
        $apiMessage->getText(),
59
        ['message' => $message, 'responder' => $this->getResponder($apiMessage)]
0 ignored issues
show
Unused Code introduced by
The call to EmitterInterface::emit() has too many arguments starting with array('message' => $mess...Responder($apiMessage)).

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
60
      );
61
      }
62
  }
63
64
  /**
65
   * @param \React\HttpClient\Response $response
66
   */
67
  public function _handlePollError(\React\HttpClient\Response $response)
0 ignored issues
show
Unused Code introduced by
The parameter $response 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...
68
  {
69
      throw new \Exception();
70
  }
71
72
  /**
73
   * @param APIMessage $message
74
   * @return function
75
   */
76
  public function getResponder(APIMessage $message)
77
  {
78
      return function ($text) use ($message) {
79
          $this->client->send($text, $message);
80
      };
81
  }
82
}
83