Skip to content

Commit

Permalink
refactor: fix used void return type (#9341)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbalandan authored Dec 28, 2024
1 parent e363f47 commit 19ad2b9
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 23 deletions.
12 changes: 9 additions & 3 deletions system/Commands/ListCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,24 @@ class ListCommands extends BaseCommand

/**
* Displays the help for the spark cli script itself.
*
* @return int
*/
public function run(array $params)
{
$commands = $this->commands->getCommands();
ksort($commands);

// Check for 'simple' format
return array_key_exists('simple', $params) || CLI::getOption('simple')
return array_key_exists('simple', $params) || CLI::getOption('simple') === true
? $this->listSimple($commands)
: $this->listFull($commands);
}

/**
* Lists the commands with accompanying info.
*
* @return void
* @return int
*/
protected function listFull(array $commands)
{
Expand Down Expand Up @@ -124,17 +126,21 @@ protected function listFull(array $commands)
CLI::newLine();
}
}

return EXIT_SUCCESS;
}

/**
* Lists the commands only.
*
* @return void
* @return int
*/
protected function listSimple(array $commands)
{
foreach (array_keys($commands) as $title) {
CLI::write($title);
}

return EXIT_SUCCESS;
}
}
7 changes: 6 additions & 1 deletion tests/system/Log/LoggerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
use CodeIgniter\Test\Mock\MockLogger as LoggerConfig;
use Exception;
use PHPUnit\Framework\Attributes\Group;
use ReflectionMethod;
use ReflectionNamedType;
use Tests\Support\Log\Handlers\TestHandler;
use TypeError;

Expand Down Expand Up @@ -67,7 +69,10 @@ public function testLogAlwaysReturnsVoid(): void

$logger = new Logger($config);

$this->assertNull($logger->log('debug', ''));
$refMethod = new ReflectionMethod($logger, 'log');
$this->assertTrue($refMethod->hasReturnType());
$this->assertInstanceOf(ReflectionNamedType::class, $refMethod->getReturnType());
$this->assertSame('void', $refMethod->getReturnType()->getName());
}

public function testLogActuallyLogs(): void
Expand Down
1 change: 0 additions & 1 deletion utils/phpstan-baseline/loader.neon
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ includes:
- method.impossibleType.neon
- method.notFound.neon
- method.unused.neon
- method.void.neon
- missingType.callable.neon
- missingType.iterableValue.neon
- missingType.parameter.neon
Expand Down
18 changes: 0 additions & 18 deletions utils/phpstan-baseline/method.void.neon

This file was deleted.

0 comments on commit 19ad2b9

Please sign in to comment.