Skip to content

Commit

Permalink
Make coder abstract
Browse files Browse the repository at this point in the history
  • Loading branch information
Stadly committed Apr 16, 2019
1 parent 738971a commit bd8e7f6
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 2 additions & 7 deletions src/Formatter/Coder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -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.
Expand Down
20 changes: 20 additions & 0 deletions tests/Formatter/CoderClass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace Stadly\PasswordPolice\Formatter;

use Stadly\PasswordPolice\CharTree;

final class CoderClass extends Coder
{
use Chaining;

/**
* {@inheritDoc}
*/
protected function applyCurrent(CharTree $charTree): CharTree
{
return $this->format($charTree);
}
}
10 changes: 5 additions & 5 deletions tests/Formatter/CoderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand All @@ -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(''),
Expand All @@ -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'),
Expand All @@ -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'),
Expand All @@ -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(
Expand Down

0 comments on commit bd8e7f6

Please sign in to comment.