Skip to content

Commit 59274ca

Browse files
committed
chore: minor clean up and phpstan fixes
1 parent 16b299e commit 59274ca

6 files changed

Lines changed: 22 additions & 10 deletions

File tree

packages/console/src/ConsoleArgument.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function __construct(
2020
public ?string $name = null,
2121
public ?string $description = null,
2222
public ?string $prompt = null,
23-
public string $help = '',
23+
public ?string $help = null,
2424
public array $aliases = [],
2525
) {}
2626
}

packages/core/src/Commands/InstallCommand.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ public function __invoke(
4747
$installer = $this->resolveInstaller($installer);
4848

4949
if (! $installer instanceof InstallerDefinition) {
50-
$this->error('The provided installer was not found.');
50+
$this->console->writeln();
51+
$this->console->error('The provided installer was not found.');
52+
5153
return;
5254
}
5355

@@ -86,7 +88,7 @@ private function resolveInstallerArguments(InstallerDefinition $installer): ?arr
8688
$installerArgumentBag = $this->buildInstallerArgumentBag();
8789
$argumentDefinitions = $this->buildInstallerArgumentDefinitions($installer);
8890

89-
do {
91+
while (true) {
9092
[$validArguments, $invalidArguments] = ($this->resolveConsoleInput)(
9193
argumentBag: $installerArgumentBag,
9294
argumentDefinitions: $argumentDefinitions,
@@ -114,7 +116,7 @@ private function resolveInstallerArguments(InstallerDefinition $installer): ?arr
114116
argumentDefinition: $argumentDefinition,
115117
);
116118
}
117-
} while ($invalidArguments !== []);
119+
}
118120

119121
return array_map(
120122
callback: fn (ConsoleInputArgument $argument) => $argument->value,

packages/core/src/Installer.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
use Attribute;
88

9+
/**
10+
* Defines an installer that will be available as an option when using the `install` console command.
11+
*/
912
#[Attribute(Attribute::TARGET_METHOD)]
1013
final readonly class Installer
1114
{

packages/core/src/InstallerDefinition.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
namespace Tempest\Core;
66

77
use Tempest\Reflection\MethodReflector;
8+
use Tempest\Support\Str;
89

910
use function Tempest\Support\arr;
10-
use function Tempest\Support\Str\to_kebab_case;
1111

1212
final class InstallerDefinition
1313
{
@@ -38,7 +38,7 @@ public function __construct(
3838
public array $aliases {
3939
get => $this->aliases ??= arr($this->installer->alias)
4040
->push($this->handler->getDeclaringClass()->getName())
41-
->push(to_kebab_case($this->name))
41+
->push(Str\to_kebab_case($this->name))
4242
->filter()
4343
->unique()
4444
->toArray();

packages/http/src/Session/Installer/SessionInstaller.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,18 @@ public function install(
2727
?SessionStorage $storage = null,
2828
?bool $migrate = null,
2929
): void {
30+
/** @var null|SessionStorage $storage */
3031
$storage ??= $this->console->ask(
3132
question: 'Which session storage do you want to use?',
3233
options: SessionStorage::class,
3334
default: SessionStorage::FILE,
3435
);
3536

37+
if (! $storage instanceof SessionStorage) {
38+
$this->console->error('Invalid session storage selected.');
39+
return;
40+
}
41+
3642
$cleanupStrategy = match ($storage) {
3743
SessionStorage::REDIS => null,
3844
default => $this->resolveCleanupStrategy(),
@@ -67,7 +73,7 @@ public function install(
6773
}
6874
}
6975

70-
private function resolveCleanupStrategy(): ?CleanupStrategy
76+
private function resolveCleanupStrategy(): CleanupStrategy
7177
{
7278
$strategy = [
7379
'Random requests' => CleanupStrategy::RANDOM_REQUESTS,
@@ -84,13 +90,13 @@ private function resolveCleanupStrategy(): ?CleanupStrategy
8490
return $strategy[$result];
8591
}
8692

87-
private function resolveSessionConfigStub(SessionStorage $sessionStrategy, ?CleanupStrategy $cleanupStrategy): string
93+
private function resolveSessionConfigStub(SessionStorage $storage, ?CleanupStrategy $cleanupStrategy): string
8894
{
89-
if ($sessionStrategy === SessionStorage::REDIS) {
95+
if ($storage === SessionStorage::REDIS) {
9096
return __DIR__ . '/session.redis.config.stub.php';
9197
}
9298

93-
return match ([$sessionStrategy, $cleanupStrategy]) {
99+
return match ([$storage, $cleanupStrategy]) {
94100
[SessionStorage::FILE, CleanupStrategy::EVERY_REQUEST] => __DIR__ . '/session.file.every-request.config.stub.php',
95101
[SessionStorage::FILE, CleanupStrategy::RANDOM_REQUESTS] => __DIR__ . '/session.file.random-requests.config.stub.php',
96102
[SessionStorage::FILE, CleanupStrategy::DISABLED] => __DIR__ . '/session.file.disabled.config.stub.php',

packages/http/src/Session/Installer/SessionStorage.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Tempest\Http\Session\Installer;
66

7+
/** @internal */
78
enum SessionStorage: string
89
{
910
case FILE = 'file';

0 commit comments

Comments
 (0)