From 699279888aa1c6d14a484afb17ab9fd525ef1e45 Mon Sep 17 00:00:00 2001 From: myrmidex Date: Sat, 22 Aug 2026 19:56:24 +0200 Subject: [PATCH] Replace local matcher with core package --- bin/anagram-finder.php | 5 ++-- composer.json | 13 +++++++--- composer.lock | 36 ++++++++++++++++++++++++++- src/Matcher.php | 51 -------------------------------------- tests/Unit/MatcherTest.php | 27 -------------------- 5 files changed, 47 insertions(+), 85 deletions(-) delete mode 100644 src/Matcher.php delete mode 100644 tests/Unit/MatcherTest.php diff --git a/bin/anagram-finder.php b/bin/anagram-finder.php index ccdfbae..fb72184 100644 --- a/bin/anagram-finder.php +++ b/bin/anagram-finder.php @@ -2,8 +2,8 @@ require __DIR__ . '/../autoload.php'; +use Lvl0\AnagramFinder\Core\Matcher; use Myrmidex\AnagramFinder\ArgHandler; -use Myrmidex\AnagramFinder\Matcher; use Myrmidex\AnagramFinder\Output; const DICTIONARY = __DIR__ . '/../assets/words.txt'; @@ -22,5 +22,4 @@ $matches = Matcher::findWords($anagram, $minLength); if ($top10) { $matches = $matches->slice(0, 10); } -$matches->each(fn (string $word) => Output::line($word . " (" . strlen($word) . ")")); - +$matches->each(fn(string $word) => Output::line($word . " (" . strlen($word) . ")")); diff --git a/composer.json b/composer.json index 5218e79..67abff5 100644 --- a/composer.json +++ b/composer.json @@ -1,8 +1,9 @@ { - "name": "myrmidex/anagram-finder", - "description": "An anagram finder in PHP", + "name": "anagram-finder/tui", + "description": "A TUI anagram finder in PHP", "type": "project", "require": { + "anagram-finder/core": "^0.1.0", "illuminate/collections": "^13.26" }, "license": "AGPL-3.0-only", @@ -21,5 +22,11 @@ "require-dev": { "phpunit/phpunit": "^13", "friendsofphp/php-cs-fixer": "^3.95" - } + }, + "repositories": [ + { + "type": "vcs", + "url": "ssh://git@forge.lvl0.xyz:2222/anagram-finder/core.git" + } + ] } diff --git a/composer.lock b/composer.lock index 872c099..2942983 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,42 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "fda7b586750778a7250234cef7e8462d", + "content-hash": "c36dc53654ea02e67b64da57d7bc91f3", "packages": [ + { + "name": "anagram-finder/core", + "version": "v0.1.0", + "source": { + "type": "git", + "url": "ssh://git@forge.lvl0.xyz:2222/anagram-finder/core.git", + "reference": "4b8ce74729fa9a6d0ca91c5d661256ca256e5291" + }, + "require": { + "illuminate/collections": "^13.26" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^3.95", + "phpunit/phpunit": "^13" + }, + "type": "library", + "autoload": { + "psr-4": { + "Lvl0\\AnagramFinder\\Core\\": "src/", + "Lvl0\\AnagramFinder\\Core\\Tests\\": "tests/" + } + }, + "license": [ + "AGPL-3.0-only" + ], + "authors": [ + { + "name": "myrmidex", + "email": "myrmidex@myrmidex.net" + } + ], + "description": "AnagramFinder core", + "time": "2026-08-22T17:50:27+00:00" + }, { "name": "illuminate/collections", "version": "v13.26.1", diff --git a/src/Matcher.php b/src/Matcher.php deleted file mode 100644 index ac63b62..0000000 --- a/src/Matcher.php +++ /dev/null @@ -1,51 +0,0 @@ -filter(fn (string $word) => strlen($word) >= $minLength) - ->filter(fn (string $word) => ctype_alpha($word)) - ->filter(fn (string $word) => $word === strtolower($word)) - ->filter(fn (string $word) => self::check($anagram, $word)) - ->toArray(); - - return new Collection($matches) - ->sort(fn ($a, $b) => strlen($b) - strlen($a)); - } - - public static function check(string $anagram, string $word): bool - { - $pool = array_count_values(str_split($anagram)); - - foreach (str_split($word) as $char) { - if (($pool[$char] ?? 0) === 0) { - return false; - } - - $pool[$char]--; - } - - return true; - } - - private static function getWordList(): LazyCollection - { - return LazyCollection::make(function () { - $fh = fopen(DICTIONARY, 'rb'); - try { - while (($line = fgets($fh)) !== false) { - yield rtrim($line, "\r\n"); - } - } finally { - fclose($fh); - } - }); - } -} diff --git a/tests/Unit/MatcherTest.php b/tests/Unit/MatcherTest.php deleted file mode 100644 index d9e24f1..0000000 --- a/tests/Unit/MatcherTest.php +++ /dev/null @@ -1,27 +0,0 @@ -assertEquals($isExpectedMatch, Matcher::check($anagram, $word)); - } - - public static function checkProvider(): array - { - return [ - 'valid1' => [ "eamstoxil", "steam", true ], - 'valid2' => [ "wordneoxs", "downers", true ], - 'valid3' => [ "ioevpmoef", "movie", true ], - 'invalid_basic' => [ "eamstoxil", "smear", false], - 'invalid_double_e' => [ "eamstexil", "smear", false], - ]; - } -}