Skip to content

Commit

Permalink
Change cs rules
Browse files Browse the repository at this point in the history
  • Loading branch information
danog committed Oct 1, 2023
1 parent 523a2e9 commit 27d2168
Show file tree
Hide file tree
Showing 174 changed files with 1,665 additions and 1,664 deletions.
1 change: 1 addition & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public function getRules(): array
'array_indentation' => true,
'ternary_to_null_coalescing' => true,
'assign_null_coalescing_to_coalesce_equal' => true,
"native_function_invocation" => ['include' => ['@compiler_optimized'], 'scope' => 'namespaced'],
]);
}
};
Expand Down
12 changes: 6 additions & 6 deletions src/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ public static function startAndLoopMulti(array $instances, array|string $eventHa
if (\is_string($eventHandler)) {
Assert::classExists($eventHandler);
$eventHandler::cachePlugins($eventHandler);
$eventHandler = \array_fill_keys(\array_keys($instances), $eventHandler);
$eventHandler = array_fill_keys(array_keys($instances), $eventHandler);
} else {
Assert::notEmpty($eventHandler);
Assert::allClassExists($eventHandler);
Expand All @@ -410,8 +410,8 @@ public static function startAndLoopMulti(array $instances, array|string $eventHa
}

$errors = [];
$started = \array_fill_keys(\array_keys($instances), false);
$instanceOne = \array_values($instances)[0];
$started = array_fill_keys(array_keys($instances), false);
$instanceOne = array_values($instances)[0];

$prev = EventLoop::getErrorHandler();
EventLoop::setErrorHandler(
Expand All @@ -422,13 +422,13 @@ public static function startAndLoopMulti(array $instances, array|string $eventHa
if ($e instanceof SecurityException || $e instanceof SignalException) {
throw $e;
}
if (\str_starts_with($e->getMessage(), 'Could not connect to DC ')) {
if (str_starts_with($e->getMessage(), 'Could not connect to DC ')) {
throw $e;
}
$t = \time();
$t = time();
$errors = [$t => $errors[$t] ?? 0];
$errors[$t]++;
if ($errors[$t] > 10 && \array_sum($started) !== \count($eventHandler)) {
if ($errors[$t] > 10 && array_sum($started) !== \count($eventHandler)) {
$instanceOne->wrapper->logger('More than 10 errors in a second and not inited, exiting!', Logger::FATAL_ERROR);
return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/AbstractAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ protected function startAndLoopInternal(string $eventHandler): void
if ($e instanceof SecurityException || $e instanceof SignalException) {
throw $e;
}
if (\str_starts_with($e->getMessage(), 'Could not connect to DC ')) {
if (str_starts_with($e->getMessage(), 'Could not connect to DC ')) {
throw $e;
}
$t = \time();
$t = time();
$errors = [$t => $errors[$t] ?? 0];
$errors[$t]++;
if ($errors[$t] > 10 && (!$this->wrapper->getAPI()->isInited() || !$started)) {
Expand Down
196 changes: 98 additions & 98 deletions src/AnnotationsBuilder.php

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions src/ApiWrappers/Start.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private function APIStart(Settings $settings)
$app = [];
if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') {
$stdout = getStdout();
$stdout->write(\sprintf(Lang::$current_lang['apiChooseManualAutoTip'], 'https://docs.madelineproto.xyz/docs/SETTINGS.html').PHP_EOL);
$stdout->write(sprintf(Lang::$current_lang['apiChooseManualAutoTip'], 'https://docs.madelineproto.xyz/docs/SETTINGS.html').PHP_EOL);
$stdout->write('1) '.Lang::$current_lang['apiManualInstructions0'].PHP_EOL);
$stdout->write('2) '.Lang::$current_lang['apiManualInstructions1'].PHP_EOL);
$stdout->write('3) ');
Expand Down Expand Up @@ -84,28 +84,28 @@ private function APIStart(Settings $settings)
*/
private function webAPIEcho(Settings $settings, string $message = ''): void
{
$message = \htmlentities($message);
$message = htmlentities($message);
$title = MTProto::getWebWarnings();
$title .= \htmlentities(Lang::$current_lang['apiManualWeb']);
$title .= htmlentities(Lang::$current_lang['apiManualWeb']);
$title .= "<br>";
$title .= \sprintf(Lang::$current_lang['apiChooseManualAutoTipWeb'], 'https://docs.madelineproto.xyz/docs/SETTINGS.html');
$title .= sprintf(Lang::$current_lang['apiChooseManualAutoTipWeb'], 'https://docs.madelineproto.xyz/docs/SETTINGS.html');
$title .= "<br><b>$message</b>";
$title .= '<ol>';
$title .= '<li>'.\str_replace('https://my.telegram.org', '<a href="https://my.telegram.org" target="_blank">https://my.telegram.org</a>', \htmlentities(Lang::$current_lang['apiManualInstructions0'])).'</li>';
$title .= '<li>'.\htmlentities(Lang::$current_lang['apiManualInstructions1']).'</li>';
$title .= '<li>'.str_replace('https://my.telegram.org', '<a href="https://my.telegram.org" target="_blank">https://my.telegram.org</a>', htmlentities(Lang::$current_lang['apiManualInstructions0'])).'</li>';
$title .= '<li>'.htmlentities(Lang::$current_lang['apiManualInstructions1']).'</li>';
$title .= '<li><ul>';
foreach (['App title', 'Short name', 'URL', 'Platform', 'Description'] as $k => $key) {
$title .= "<li>$key: ";
$title .= \htmlentities(Lang::$current_lang["apiAppInstructionsManual$k"]);
$title .= htmlentities(Lang::$current_lang["apiAppInstructionsManual$k"]);
$title .= '</li>';
}
$title .= '</li></ul>';
$title .= '<li>'.\htmlentities(Lang::$current_lang['apiManualInstructions2']).'</li>';
$title .= '<li>'.htmlentities(Lang::$current_lang['apiManualInstructions2']).'</li>';
$title .= '</ol>';
$form = '<input type="string" name="api_id" placeholder="API ID" required/>';
$form .= '<input type="string" name="api_hash" placeholder="API hash" required/>';
getOutputBufferStream()->write(
\sprintf(
sprintf(
$settings->getTemplates()->getHtmlTemplate(),
$title,
$form,
Expand Down
20 changes: 10 additions & 10 deletions src/AsyncTools.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ public static function callFork(callable|Generator|Future $callable, ...$args):
*/
public static function flock(string $file, int $operation, float $polling = 0.1, ?Cancellation $token = null, ?Closure $failureCb = null): ?Closure
{
if (!\file_exists($file)) {
\touch($file);
if (!file_exists($file)) {
touch($file);
}
$operation |= LOCK_NB;
$res = \fopen($file, 'c');
$res = fopen($file, 'c');
do {
$result = \flock($res, $operation);
$result = flock($res, $operation);
if (!$result) {
if ($failureCb) {
EventLoop::queue($failureCb);
Expand All @@ -110,8 +110,8 @@ public static function flock(string $file, int $operation, float $polling = 0.1,
} while (!$result);
return static function () use (&$res): void {
if ($res) {
\flock($res, LOCK_UN);
\fclose($res);
flock($res, LOCK_UN);
fclose($res);
$res = null;
}
};
Expand Down Expand Up @@ -153,14 +153,14 @@ public static function readLine(string $prompt = '', ?Cancellation $cancel = nul
}
static $lines = [''];
while (\count($lines) < 2 && ($chunk = $stdin->read($cancel)) !== null) {
$chunk = \explode("\n", \str_replace(["\r", "\n\n"], "\n", $chunk));
$lines[\count($lines) - 1] .= \array_shift($chunk);
$lines = \array_merge($lines, $chunk);
$chunk = explode("\n", str_replace(["\r", "\n\n"], "\n", $chunk));
$lines[\count($lines) - 1] .= array_shift($chunk);
$lines = array_merge($lines, $chunk);
}
} finally {
Magic::togglePeriodicLogging();
}
return \array_shift($lines) ?? '';
return array_shift($lines) ?? '';
}
/**
* Asynchronously write to stdout/browser.
Expand Down
2 changes: 1 addition & 1 deletion src/Broadcast/Action/ActionForward.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function act(int $broadcastId, int $peer, Cancellation $cancellation): vo
$id = 0;
foreach ($updates as $update) {
if (\in_array($update['_'], ['updateNewMessage', 'updateNewChannelMessage'], true)) {
$id = \max($id, $update['message']['id']);
$id = max($id, $update['message']['id']);
}
}
try {
Expand Down
2 changes: 1 addition & 1 deletion src/Broadcast/Action/ActionSend.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function act(int $broadcastId, int $peer, Cancellation $cancellation): vo
$message['media']['_'] !== 'messageMediaWebPage'
? 'messages.sendMedia'
: 'messages.sendMessage',
\array_merge($message, ['peer' => $peer]),
array_merge($message, ['peer' => $peer]),
['FloodWaitLimit' => 2*86400]
));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Broadcast/Broadcast.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function broadcastForwardMessages(mixed $from_peer, array $message_ids, b
public function broadcastCustom(Action $action, ?Filter $filter = null): int
{
// Ensure it can be serialized
Assert::eq(\unserialize(\serialize($action))::class, $action::class);
Assert::eq(unserialize(serialize($action))::class, $action::class);

$id = $this->broadcastId--;
$this->broadcasts[$id] = new InternalState($id, $this, $action, $filter ?? Filter::default());
Expand Down
4 changes: 2 additions & 2 deletions src/Broadcast/InternalState.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function __construct(
}
public function __serialize(): array
{
$vars = \get_object_vars($this);
$vars = get_object_vars($this);
$vars['status'] = match ($vars['status']) {
StatusInternal::GATHERING_PEERS => StatusInternal::IDLING_BEFORE_GATHERING_PEERS,
StatusInternal::BROADCASTING => StatusInternal::IDLING_BEFORE_BROADCASTING,
Expand Down Expand Up @@ -131,7 +131,7 @@ private function gatherPeers(): void
}
}
}
$peers = \array_filter($peers, function (int $peer): bool {
$peers = array_filter($peers, function (int $peer): bool {
if (\in_array($peer, $this->filter->blacklist, true)) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ private function methodAbstractions(string &$method, array &$arguments): void
}
}
return;
} elseif (\in_array($method, ['messages.addChatUser', 'messages.deleteChatUser', 'messages.editChatAdmin', 'messages.editChatPhoto', 'messages.editChatTitle', 'messages.getFullChat', 'messages.exportChatInvite', 'messages.editChatAdmin', 'messages.migrateChat'], true) && isset($arguments['chat_id']) && (!\is_numeric($arguments['chat_id']) || $arguments['chat_id'] < 0)) {
} elseif (\in_array($method, ['messages.addChatUser', 'messages.deleteChatUser', 'messages.editChatAdmin', 'messages.editChatPhoto', 'messages.editChatTitle', 'messages.getFullChat', 'messages.exportChatInvite', 'messages.editChatAdmin', 'messages.migrateChat'], true) && isset($arguments['chat_id']) && (!is_numeric($arguments['chat_id']) || $arguments['chat_id'] < 0)) {
$res = $this->API->getInfo($arguments['chat_id']);
if ($res['type'] !== 'chat') {
throw new Exception('chat_id is not a chat id (only normal groups allowed, not supergroups)!');
Expand Down
Loading

0 comments on commit 27d2168

Please sign in to comment.