Skip to content

Commit

Permalink
Actualize to 7.4 (#474)
Browse files Browse the repository at this point in the history
* Actualized Types:
Chat
User

Added missed Types:
ArrayOfReactionType
MessageOriginChannel
ReactionType
ReactionTypeCustomEmoji
ReactionTypeEmoji

Added some tests

* Actualized Types

* Actualized Types

* Actualized Types

* Actualized Types

* rm tracker

* rm tracker

* upd Chat classes

* php cs-fixer

* upd MessageOriginChannel

* fix BotApiTest

* added types to User
  • Loading branch information
iGusev authored Jun 30, 2024
1 parent fcc0241 commit d11cf3a
Show file tree
Hide file tree
Showing 140 changed files with 13,145 additions and 2,431 deletions.
8 changes: 0 additions & 8 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,6 @@ jobs:
os:
- ubuntu-latest
php:
- "5.5"
- "5.6"
- "7.0"
- "7.1"
- "7.2"
- "7.3"
- "7.4"
- "8.0"
- "8.1"
- "8.2"
steps:
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
}
],
"require": {
"php" : ">=5.5.0",
"php" : ">=8.1",
"ext-curl": "*",
"ext-json": "*"
},
Expand Down
2 changes: 1 addition & 1 deletion psalm.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<psalm
errorLevel="2"
phpVersion="5.5"
phpVersion="8.1"
findUnusedBaselineEntry="false"
findUnusedCode="false"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
Expand Down
82 changes: 1 addition & 81 deletions src/BotApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,42 +167,18 @@ class BotApi
*/
private $fileEndpoint;

/**
* @deprecated
*
* Botan tracker
*
* @var Botan|null
*/
protected $tracker;

/**
* @deprecated
*
* list of event ids
*
* @var array
*/
protected $trackedEvents = [];

/**
* @param string $token Telegram Bot API token
* @param string|null $trackerToken Yandex AppMetrica application api_key
* @param HttpClientInterface|null $httpClient
* @param string|null $endpoint
*/
public function __construct($token, $trackerToken = null, HttpClientInterface $httpClient = null, $endpoint = null)
public function __construct($token, HttpClientInterface $httpClient = null, $endpoint = null)
{
$this->token = $token;
$this->endpoint = ($endpoint ?: self::URL_PREFIX) . $token;

Check failure on line 178 in src/BotApi.php

View workflow job for this annotation

GitHub Actions / PHP 8.1-ubuntu-latest

RiskyTruthyFalsyComparison

src/BotApi.php:178:28: RiskyTruthyFalsyComparison: Operand of type null|string contains type string, which can be falsy and truthy. This can cause possibly unexpected behavior. Use strict comparison instead. (see https://psalm.dev/356)
$this->fileEndpoint = $endpoint ? null : (self::FILE_URL_PREFIX . $token);

Check failure on line 179 in src/BotApi.php

View workflow job for this annotation

GitHub Actions / PHP 8.1-ubuntu-latest

RiskyTruthyFalsyComparison

src/BotApi.php:179:31: RiskyTruthyFalsyComparison: Operand of type null|string contains type string, which can be falsy and truthy. This can cause possibly unexpected behavior. Use strict comparison instead. (see https://psalm.dev/356)

$this->httpClient = $httpClient ?: new CurlHttpClient();

if ($trackerToken) {
@trigger_error(sprintf('Passing $trackerToken to %s is deprecated', self::class), \E_USER_DEPRECATED);
$this->tracker = new Botan($trackerToken);
}
}

/**
Expand Down Expand Up @@ -643,12 +619,6 @@ public function getUpdates($offset = 0, $limit = 100, $timeout = 0)
'timeout' => $timeout,
]));

if ($this->tracker instanceof Botan) {
foreach ($updates as $update) {
$this->trackUpdate($update);
}
}

return $updates;
}

Expand Down Expand Up @@ -1804,56 +1774,6 @@ public function deleteMessage($chatId, $messageId)
]);
}

/**
* @deprecated
*
* @param Update $update
* @param string $eventName
*
* @throws Exception
*
* @return void
*/
public function trackUpdate(Update $update, $eventName = 'Message')
{
@trigger_error(sprintf('Method "%s::%s" is deprecated', __CLASS__, __METHOD__), \E_USER_DEPRECATED);

if (!in_array($update->getUpdateId(), $this->trackedEvents)) {
$message = $update->getMessage();
if (!$message) {
return;
}
$this->trackedEvents[] = $update->getUpdateId();

$this->track($message, $eventName);

if (count($this->trackedEvents) > self::MAX_TRACKED_EVENTS) {
$this->trackedEvents = array_slice($this->trackedEvents, (int) round(self::MAX_TRACKED_EVENTS / 4));
}
}
}

/**
* @deprecated
*
* Wrapper for tracker
*
* @param Message $message
* @param string $eventName
*
* @throws Exception
*
* @return void
*/
public function track(Message $message, $eventName = 'Message')
{
@trigger_error(sprintf('Method "%s::%s" is deprecated', __CLASS__, __METHOD__), \E_USER_DEPRECATED);

if ($this->tracker instanceof Botan) {
$this->tracker->track($message, $eventName);
}
}

/**
* Use this method to send invoices. On success, the sent Message is returned.
*
Expand Down
95 changes: 0 additions & 95 deletions src/Botan.php

This file was deleted.

10 changes: 3 additions & 7 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,13 @@ class Client
* Client constructor
*
* @param string $token Telegram Bot API token
* @param string|null $trackerToken Yandex AppMetrica application api_key
* @param HttpClientInterface|null $httpClient
* @param string|null $endpoint
*/
public function __construct($token, $trackerToken = null, HttpClientInterface $httpClient = null, $endpoint = null)
public function __construct($token, HttpClientInterface $httpClient = null, $endpoint = null)
{
if ($trackerToken) {
@trigger_error(sprintf('Passing $trackerToken to %s is deprecated', self::class), \E_USER_DEPRECATED);
}
$this->api = new BotApi($token, $trackerToken, $httpClient, $endpoint);
$this->events = new EventCollection($trackerToken);
$this->api = new BotApi($token, $httpClient, $endpoint);
$this->events = new EventCollection();
}

/**
Expand Down
29 changes: 1 addition & 28 deletions src/Events/EventCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
namespace TelegramBot\Api\Events;

use Closure;
use ReflectionFunction;
use TelegramBot\Api\Botan;
use TelegramBot\Api\Types\Update;

class EventCollection
Expand All @@ -14,28 +12,7 @@ class EventCollection
*
* @var array
*/
protected $events;

/**
* Botan tracker
*
* @var \TelegramBot\Api\Botan|null
*/
protected $tracker;

/**
* EventCollection constructor.
*
* @param string $trackerToken
*/
public function __construct($trackerToken = null)
{
$this->events = [];
if ($trackerToken) {
@trigger_error(sprintf('Passing $trackerToken to %s is deprecated', self::class), \E_USER_DEPRECATED);
$this->tracker = new Botan($trackerToken);
}
}
protected $events = [];

/**
* Add new event to collection
Expand All @@ -62,10 +39,6 @@ public function handle(Update $update)
/* @var \TelegramBot\Api\Events\Event $event */
if ($event->executeChecker($update) === true) {
if ($event->executeAction($update) === false) {
if ($this->tracker && ($message = $update->getMessage())) {
$checker = new ReflectionFunction($event->getChecker());
$this->tracker->track($message, $checker->getStaticVariables()['name']);
}
break;
}
}
Expand Down
Loading

0 comments on commit d11cf3a

Please sign in to comment.