fix minor issues

This commit is contained in:
myrmidex 2026-08-31 00:13:38 +02:00
parent ae11ea6a56
commit 3f0ffc7f1d
6 changed files with 5195 additions and 24 deletions

View file

@ -3,10 +3,10 @@
require __DIR__ . '/../autoload.php';
use Lvl0\AnagramFinder\TUI\Commands\FindAnagramWordsCommand;
use Lvl0\Countdown\TUI\Commands\FindAnagramWordsCommand;
use Symfony\Component\Console\Application;
$application = new Application('Anagram Finder', '1.0.0');
$application->addCommand(new FindAnagramWordsCommand());
$application->setDefaultCommand('anagram:find-words');
$application->setDefaultCommand('countdown:letters');
$application->run();

View file

@ -3,7 +3,7 @@
require __DIR__ . '/../autoload.php';
use Lvl0\AnagramFinder\TUI\Commands\FindNumbersCommand;
use Lvl0\Countdown\TUI\Commands\FindNumbersCommand;
use Symfony\Component\Console\Application;
$application = new Application('Countdown numbers Finder', '1.0.0');

View file

@ -3,7 +3,7 @@
"description": "A TUI anagram finder in PHP",
"type": "project",
"require": {
"countdown/letters": "^0.1.2",
"countdown/letters": "^0.1.3",
"countdown/numbers": "^0.1.0",
"illuminate/collections": "^13.26",
"laravel/prompts": "^0.3.23"
@ -11,8 +11,8 @@
"license": "AGPL-3.0-only",
"autoload": {
"psr-4": {
"Lvl0\\AnagramFinder\\TUI\\": "src/",
"Lvl0\\AnagramFinder\\TUI\\Tests\\": "tests/"
"Lvl0\\Countdown\\TUI\\": "src/",
"Lvl0\\Countdown\\TUI\\Tests\\": "tests/"
}
},
"authors": [

5153
composer.lock generated Normal file

File diff suppressed because it is too large Load diff

View file

@ -1,8 +1,8 @@
<?php
namespace Lvl0\AnagramFinder\TUI\Commands;
namespace Lvl0\Countdown\TUI\Commands;
use Lvl0\AnagramFinder\Core\Matcher;
use Lvl0\Countdown\Letters\Matcher;
use Symfony\Component\Console\Attribute\Argument;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Attribute\Option;
@ -14,37 +14,38 @@ use function Laravel\Prompts\spin;
use function Laravel\Prompts\table;
use function Laravel\Prompts\text;
#[AsCommand(name: 'anagram:find-words')]
#[AsCommand(name: 'countdown:letters')]
class FindAnagramWordsCommand extends Command
{
public function __invoke(
#[Argument]
?string $anagram,
?string $letters,
#[Argument]
?int $minLength,
bool $all = false,
#[Option]
bool $top = false,
bool $single = false,
): int {
clear();
info("ANAGRAM FINDER");
$anagram = $anagram ??= text("Enter the anagram", required: true);
$minLength = $top === true
? 3
: ($minLength ?: text(label: "Enter the minimum length of the results. (default=3)", placeholder: 3, default: 3, required: true));
$letters = $letters ??= text("Enter the letters", required: true);
info("Results for your anagram: " . $anagram);
info("Results for your letters: " . $letters);
$matches = spin(
callback: fn() => Matcher::findWords($anagram, $minLength),
callback: fn() => Matcher::findWords($letters),
message: 'Checking dictionary...',
);
if ($top) {
if ($all) {
$matches = $matches->slice(0, 10);
}
if ($single) {
$matches = $matches->first();
}
table(
headers: ["word", "length"],
rows: $matches->map(fn(string $word) => ['word' => $word, 'length' => strlen($word)])->toArray(),

View file

@ -1,15 +1,17 @@
<?php
namespace Lvl0\AnagramFinder\TUI\Commands;
namespace Lvl0\Countdown\TUI\Commands;
use Lvl0\AnagramFinder\TUI\Dtos\NumbersBag;
use Lvl0\AnagramFinder\TUI\Dtos\Step;
use Lvl0\AnagramFinder\TUI\Services\NumbersService;
use Illuminate\Support\Collection;
use Lvl0\Countdown\Numbers\Dtos\NumbersBag;
use Lvl0\Countdown\Numbers\Dtos\Step;
use Lvl0\Countdown\Numbers\Services\NumbersService;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use function Laravel\Prompts\callout;
use function Laravel\Prompts\clear;
use function Laravel\Prompts\error;
use function Laravel\Prompts\intro;
use function Laravel\Prompts\spin;
use function Laravel\Prompts\text;
@ -23,9 +25,24 @@ class FindNumbersCommand extends Command
intro("NUMBERS FINDER");
$numbers = NumbersBag::fromArray(explode(" ", text("Enter the numbers", required: true)));
$numbersInput = text("Enter the numbers", required: true);
$numbers = new NumbersBag(
new Collection(preg_split('/\s+/', trim($numbersInput), -1, PREG_SPLIT_NO_EMPTY))
->filter(fn (string $number) => ctype_digit($number))
->map(fn (string $number) => intval($number))
);
$target = text(label: "Enter the target number", required: true);
if (! ctype_digit($target)) {
error("Invalid target number");
return self::FAILURE;
}
$target = intval($target);
$result = spin(
callback: fn() => new NumbersService($numbers)->solve($target),
message: 'Calculating...',