Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Actualize to 7.4 #474

Merged
merged 12 commits into from
Jun 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
*/
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)

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)

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 All @@ -217,7 +193,7 @@
$sign = $data['hash'];
unset($data['hash']);

if ($authDateDiff && (time() - $data['auth_date'] > $authDateDiff)) {

Check failure on line 196 in src/BotApi.php

View workflow job for this annotation

GitHub Actions / PHP 8.1-ubuntu-latest

RiskyTruthyFalsyComparison

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

Check failure on line 196 in src/BotApi.php

View workflow job for this annotation

GitHub Actions / PHP 8.1-ubuntu-latest

RiskyTruthyFalsyComparison

src/BotApi.php:196:13: RiskyTruthyFalsyComparison: Operand of type int|null contains type int, which can be falsy and truthy. This can cause possibly unexpected behavior. Use strict comparison instead. (see https://psalm.dev/356)
return false;
}

Expand Down Expand Up @@ -287,10 +263,10 @@
public function downloadFile($fileId)
{
$file = $this->getFile($fileId);
if (!$path = $file->getFilePath()) {

Check failure on line 266 in src/BotApi.php

View workflow job for this annotation

GitHub Actions / PHP 8.1-ubuntu-latest

RiskyTruthyFalsyComparison

src/BotApi.php:266:13: 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)

Check failure on line 266 in src/BotApi.php

View workflow job for this annotation

GitHub Actions / PHP 8.1-ubuntu-latest

RiskyTruthyFalsyComparison

src/BotApi.php:266:13: 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)
throw new Exception('Empty file_path property');
}
if (!$this->fileEndpoint) {

Check failure on line 269 in src/BotApi.php

View workflow job for this annotation

GitHub Actions / PHP 8.1-ubuntu-latest

RiskyTruthyFalsyComparison

src/BotApi.php:269:13: 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)

Check failure on line 269 in src/BotApi.php

View workflow job for this annotation

GitHub Actions / PHP 8.1-ubuntu-latest

RiskyTruthyFalsyComparison

src/BotApi.php:269:13: 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)
return file_get_contents($path);
}

Expand All @@ -313,12 +289,12 @@
{
@trigger_error(sprintf('Method "%s::%s" is deprecated', __CLASS__, __METHOD__), \E_USER_DEPRECATED);

if ($response) {

Check failure on line 292 in src/BotApi.php

View workflow job for this annotation

GitHub Actions / PHP 8.1-ubuntu-latest

RiskyTruthyFalsyComparison

src/BotApi.php:292:13: RiskyTruthyFalsyComparison: Operand of type false|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)

Check failure on line 292 in src/BotApi.php

View workflow job for this annotation

GitHub Actions / PHP 8.1-ubuntu-latest

RiskyTruthyFalsyComparison

src/BotApi.php:292:13: RiskyTruthyFalsyComparison: Operand of type false|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)
$json = json_decode($response, true) ?: [];
} else {
$json = [];
}
if (($httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE))

Check failure on line 297 in src/BotApi.php

View workflow job for this annotation

GitHub Actions / PHP 8.1-ubuntu-latest

InvalidArgument

src/BotApi.php:297:39: InvalidArgument: Argument 1 of curl_getinfo expects CurlHandle, but resource provided (see https://psalm.dev/004)

Check failure on line 297 in src/BotApi.php

View workflow job for this annotation

GitHub Actions / PHP 8.1-ubuntu-latest

InvalidArgument

src/BotApi.php:297:39: InvalidArgument: Argument 1 of curl_getinfo expects CurlHandle, but resource provided (see https://psalm.dev/004)
&& !in_array($httpCode, [self::DEFAULT_STATUS_CODE, self::NOT_MODIFIED_STATUS_CODE])
) {
$errorDescription = array_key_exists('description', $json) ? $json['description'] : self::$codes[$httpCode];
Expand Down Expand Up @@ -643,12 +619,6 @@
'timeout' => $timeout,
]));

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

return $updates;
}

Expand Down Expand Up @@ -1804,56 +1774,6 @@
]);
}

/**
* @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 @@
* 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 Expand Up @@ -169,7 +165,7 @@
*/
public function run()
{
if ($data = BotApi::jsonValidate((string) $this->getRawBody(), true)) {

Check failure on line 168 in src/Client.php

View workflow job for this annotation

GitHub Actions / PHP 8.1-ubuntu-latest

RiskyTruthyFalsyComparison

src/Client.php:168:13: RiskyTruthyFalsyComparison: Operand of type array<array-key, mixed>|object contains type array<array-key, mixed>, which can be falsy and truthy. This can cause possibly unexpected behavior. Use strict comparison instead. (see https://psalm.dev/356)

Check failure on line 168 in src/Client.php

View workflow job for this annotation

GitHub Actions / PHP 8.1-ubuntu-latest

RiskyTruthyFalsyComparison

src/Client.php:168:13: RiskyTruthyFalsyComparison: Operand of type array<array-key, mixed>|object contains type array<array-key, mixed>, which can be falsy and truthy. This can cause possibly unexpected behavior. Use strict comparison instead. (see https://psalm.dev/356)
/** @var array $data */
$this->handle([Update::fromResponse($data)]);
}
Expand Down Expand Up @@ -369,7 +365,7 @@
return false;
}
$text = $message->getText();
if (empty($text)) {

Check failure on line 368 in src/Client.php

View workflow job for this annotation

GitHub Actions / PHP 8.1-ubuntu-latest

RiskyTruthyFalsyComparison

src/Client.php:368:17: 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)

Check failure on line 368 in src/Client.php

View workflow job for this annotation

GitHub Actions / PHP 8.1-ubuntu-latest

RiskyTruthyFalsyComparison

src/Client.php:368:17: 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)
return false;
}

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
Loading