Skip to content

Commit

Permalink
Use first-class callable syntax
Browse files Browse the repository at this point in the history
Promote all remaining string-based callables to first-class callable
syntax. See smrealms#1183.

This refactoring was performed with rector.
  • Loading branch information
hemberger committed Feb 4, 2023
1 parent 87fcd10 commit cc71191
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 2 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<?php declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\Php81\Rector\Array_\FirstClassCallableRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
__DIR__ . '/test',
__DIR__ . '/src',
]);
$rectorConfig->rule(FirstClassCallableRector::class);
};
6 changes: 3 additions & 3 deletions src/lib/Smr/Discord/Commands/Turns.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Smr\Discord\Commands;

use Smr\AbstractPlayer;
use Smr\Discord\DatabaseCommand;
use Smr\Player;

class Turns extends DatabaseCommand {

Expand All @@ -16,10 +16,10 @@ public function description(): string {
}

public function databaseResponse(string ...$args): array {
return array_map([$this, 'getTurnsMessage'], $this->player->getSharingPlayers(true));
return array_map($this->getTurnsMessage(...), $this->player->getSharingPlayers(true));
}

private function getTurnsMessage(Player $player): string {
private function getTurnsMessage(AbstractPlayer $player): string {
// turns only update when the player is active, so calculate current turns
$turns = min(
$player->getTurns() + $player->getTurnsGained(time(), true),
Expand Down
6 changes: 3 additions & 3 deletions src/lib/Smr/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,14 @@ public static function get(string $index, string $default = null): string {
* Note that this does not save the result in $var (see Smr\Session).
*/
public static function getVar(string $index, string $default = null): string {
return self::getVarX($index, $default, [self::class, 'get']);
return self::getVarX($index, $default, self::get(...));
}

/**
* Like getVar, but returns an int instead of a string.
*/
public static function getVarInt(string $index, int $default = null): int {
return self::getVarX($index, $default, [self::class, 'getInt']);
return self::getVarX($index, $default, self::getInt(...));
}

/**
Expand All @@ -136,7 +136,7 @@ public static function getVarInt(string $index, int $default = null): int {
* @return array<int>
*/
public static function getVarIntArray(string $index, array $default = null): array {
return self::getVarX($index, $default, [self::class, 'getIntArray']);
return self::getVarX($index, $default, self::getIntArray(...));
}

/**
Expand Down

0 comments on commit cc71191

Please sign in to comment.