diff --git a/CHANGELOG.md b/CHANGELOG.md index e7662e8..7db0d83 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) princip - Memoization for substring generator is done across instances. - Memoization for truncator is done across instances. - Coder does no longer have memoization. +- Coder can no longer be instantiated. ### Fixed - Capitalizer discarded empty strings. diff --git a/src/Formatter/Coder.php b/src/Formatter/Coder.php index 162b8ed..03d5001 100644 --- a/src/Formatter/Coder.php +++ b/src/Formatter/Coder.php @@ -8,10 +8,8 @@ use Stadly\PasswordPolice\CodeMap; use Stadly\PasswordPolice\Formatter; -class Coder implements Formatter +abstract class Coder implements Formatter { - use Chaining; - /** * @var CodeMap Code map for coding character trees. */ @@ -29,10 +27,7 @@ public function __construct(CodeMap $codeMap) * @param CharTree $charTree Character tree to format. * @return CharTree Coded variant of the character tree. */ - protected function applyCurrent(CharTree $charTree): CharTree - { - return $this->format($charTree); - } + abstract protected function applyCurrent(CharTree $charTree): CharTree; /** * @param CharTree $charTree Character tree to format. diff --git a/tests/Formatter/CoderClass.php b/tests/Formatter/CoderClass.php new file mode 100644 index 0000000..513005e --- /dev/null +++ b/tests/Formatter/CoderClass.php @@ -0,0 +1,20 @@ +format($charTree); + } +} diff --git a/tests/Formatter/CoderTest.php b/tests/Formatter/CoderTest.php index ea82a20..8e3b49a 100644 --- a/tests/Formatter/CoderTest.php +++ b/tests/Formatter/CoderTest.php @@ -44,7 +44,7 @@ static function (CharTree $charTree): array { */ public function testCanFormatEmptyCharacterTree(): void { - $formatter = new Coder($this->codeMap); + $formatter = new CoderClass($this->codeMap); self::assertSame(CharTree::fromArray([ ]), $formatter->apply(CharTree::fromArray([ @@ -56,7 +56,7 @@ public function testCanFormatEmptyCharacterTree(): void */ public function testCanFormatEmptyStringCharacterTree(): void { - $formatter = new Coder($this->codeMap); + $formatter = new CoderClass($this->codeMap); self::assertSame(CharTree::fromArray([ CharTree::fromString(''), @@ -70,7 +70,7 @@ public function testCanFormatEmptyStringCharacterTree(): void */ public function testCanFormatCharacterPath(): void { - $formatter = new Coder($this->codeMap); + $formatter = new CoderClass($this->codeMap); self::assertSame(CharTree::fromArray([ CharTree::fromString('gPpCbS'), @@ -84,7 +84,7 @@ public function testCanFormatCharacterPath(): void */ public function testCanFormatCharacterTree(): void { - $formatter = new Coder($this->codeMap); + $formatter = new CoderClass($this->codeMap); self::assertSame(CharTree::fromArray([ CharTree::fromString('gPp'), @@ -104,7 +104,7 @@ public function testCanFormatCharacterTree(): void */ public function testCanApplyFormatterChain(): void { - $formatter = new Coder($this->codeMap); + $formatter = new CoderClass($this->codeMap); $next = $this->createMock(Formatter::class); $next->method('apply')->willReturnCallback(