Skip to content

Commit

Permalink
refactor - entity to VO
Browse files Browse the repository at this point in the history
  • Loading branch information
roliod committed Dec 22, 2020
1 parent b565e97 commit a84d86f
Show file tree
Hide file tree
Showing 36 changed files with 235 additions and 235 deletions.
20 changes: 0 additions & 20 deletions src/Deck/Factories/Entity.php

This file was deleted.

20 changes: 20 additions & 0 deletions src/Deck/Factories/VO.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
declare(strict_types=1);

namespace Roliod\TexasHUPoker\Deck\Factories;

use Roliod\TexasHUPoker\Deck\VOs\Hand as HandVO;

class VO
{
/**
* @param string $sequence
*
* @return HandVO
*/
public static function buildHandVO(
string $sequence
): HandVO {
return new HandVO($sequence);
}
}
2 changes: 1 addition & 1 deletion src/Deck/Entities/Hand.php → src/Deck/VOs/Hand.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
declare(strict_types=1);

namespace Roliod\TexasHUPoker\Deck\Entities;
namespace Roliod\TexasHUPoker\Deck\VOs;

class Hand
{
Expand Down
4 changes: 2 additions & 2 deletions src/Evaluate.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Exception;
use Roliod\TexasHUPoker\Deck\Suite;
use Roliod\TexasHUPoker\Rules\Contracts\Rule as RuleContract;
use Roliod\TexasHUPoker\Deck\Factories\Entity as EntityFactory;
use Roliod\TexasHUPoker\Deck\Factories\VO as VOFactory;
use Roliod\TexasHUPoker\Exceptions\FileDoesNotExist as FileDoesNotExistException;
use Roliod\TexasHUPoker\Exceptions\InvalidFileContent as InvalidFileContentException;

Expand Down Expand Up @@ -81,7 +81,7 @@ private function reorderBasedOnHierarchy(array $hands): array
{
$deckHierarchy = [];
foreach ($hands as $hand) {
$hand = EntityFactory::buildHandEntity($hand);
$hand = VOFactory::buildHandVO($hand);

foreach (Config::RULES as $rule) {
/** @var RuleContract $rule */
Expand Down
10 changes: 5 additions & 5 deletions src/Rules/AbstractRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
use Roliod\TexasHUPoker\Rules\Contracts\Rule as RuleContract;
use Roliod\TexasHUPoker\Rules\Concerns\CanGetRanksFromSequence;
use Roliod\TexasHUPoker\Rules\Concerns\CanGetSuitsFromSequence;
use Roliod\TexasHUPoker\Rules\Factories\Entity as EntityFactory;
use Roliod\TexasHUPoker\Rules\Entities\RuleResponse as RuleResponseEntity;
use Roliod\TexasHUPoker\Rules\Factories\VO as VOFactory;
use Roliod\TexasHUPoker\Rules\VOs\RuleResponse as RuleResponseVO;

abstract class AbstractRule implements RuleContract
{
Expand All @@ -18,14 +18,14 @@ abstract class AbstractRule implements RuleContract
* @param int $rank
* @param bool $matches
*
* @return RuleResponseEntity
* @return RuleResponseVO
*/
protected function buildRuleResponse(
string $sequence,
int $rank,
bool $matches
): RuleResponseEntity {
return EntityFactory::buildRuleResponseEntity(
): RuleResponseVO {
return VOFactory::buildRuleResponseVO(
$sequence,
$rank,
$matches
Expand Down
10 changes: 5 additions & 5 deletions src/Rules/Contracts/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

namespace Roliod\TexasHUPoker\Rules\Contracts;

use Roliod\TexasHUPoker\Deck\Entities\Hand as HandEntity;
use Roliod\TexasHUPoker\Rules\Entities\RuleResponse as RuleResponseEntity;
use Roliod\TexasHUPoker\Deck\VOs\Hand as HandVO;
use Roliod\TexasHUPoker\Rules\VOs\RuleResponse as RuleResponseVO;

interface Rule
{
/**
* @param HandEntity $handEntity
* @param HandVO $handVO
*
* @return RuleResponseEntity
* @return RuleResponseVO
*/
public function validate(HandEntity $handEntity): RuleResponseEntity;
public function validate(HandVO $handVO): RuleResponseVO;
}
12 changes: 6 additions & 6 deletions src/Rules/Factories/Entity.php → src/Rules/Factories/VO.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@

namespace Roliod\TexasHUPoker\Rules\Factories;

use Roliod\TexasHUPoker\Rules\Entities\RuleResponse as RuleResponseEntity;
use Roliod\TexasHUPoker\Rules\VOs\RuleResponse as RuleResponseVO;

class Entity
class VO
{
/**
* @param string $hand
* @param int $rank
* @param bool $matches
*
* @return RuleResponseEntity
* @return RuleResponseVO
*/
public static function buildRuleResponseEntity(
public static function buildRuleResponseVO(
string $hand,
int $rank,
bool $matches = false
): RuleResponseEntity {
return new RuleResponseEntity(
): RuleResponseVO {
return new RuleResponseVO(
$hand,
$rank,
$matches
Expand Down
8 changes: 4 additions & 4 deletions src/Rules/Flush.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

namespace Roliod\TexasHUPoker\Rules;

use Roliod\TexasHUPoker\Deck\Entities\Hand as HandEntity;
use Roliod\TexasHUPoker\Rules\Entities\RuleResponse as RuleResponseEntity;
use Roliod\TexasHUPoker\Deck\VOs\Hand as HandVO;
use Roliod\TexasHUPoker\Rules\VOs\RuleResponse as RuleResponseVO;

class Flush extends AbstractRule
{
Expand All @@ -16,9 +16,9 @@ class Flush extends AbstractRule
/**
* {@inheritDoc}
*/
public function validate(HandEntity $handEntity): RuleResponseEntity
public function validate(HandVO $handVO): RuleResponseVO
{
$sequence = $handEntity->getSequence();
$sequence = $handVO->getSequence();
$isFlush = $this->isFlush($sequence);

return $this->buildRuleResponse(
Expand Down
8 changes: 4 additions & 4 deletions src/Rules/FourOfAKind.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

namespace Roliod\TexasHUPoker\Rules;

use Roliod\TexasHUPoker\Deck\Entities\Hand as HandEntity;
use Roliod\TexasHUPoker\Rules\Entities\RuleResponse as RuleResponseEntity;
use Roliod\TexasHUPoker\Deck\VOs\Hand as HandVO;
use Roliod\TexasHUPoker\Rules\VOs\RuleResponse as RuleResponseVO;

class FourOfAKind extends AbstractRule
{
Expand All @@ -16,9 +16,9 @@ class FourOfAKind extends AbstractRule
/**
* {@inheritDoc}
*/
public function validate(HandEntity $handEntity): RuleResponseEntity
public function validate(HandVO $handVO): RuleResponseVO
{
$sequence = $handEntity->getSequence();
$sequence = $handVO->getSequence();
$isFourAKind = $this->isFourOfAKind($sequence);

return $this->buildRuleResponse(
Expand Down
8 changes: 4 additions & 4 deletions src/Rules/FullHouse.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

namespace Roliod\TexasHUPoker\Rules;

use Roliod\TexasHUPoker\Deck\Entities\Hand as HandEntity;
use Roliod\TexasHUPoker\Rules\Entities\RuleResponse as RuleResponseEntity;
use Roliod\TexasHUPoker\Deck\VOs\Hand as HandVO;
use Roliod\TexasHUPoker\Rules\VOs\RuleResponse as RuleResponseVO;

class FullHouse extends AbstractRule
{
Expand All @@ -16,9 +16,9 @@ class FullHouse extends AbstractRule
/**
* {@inheritDoc}
*/
public function validate(HandEntity $handEntity): RuleResponseEntity
public function validate(HandVO $handVO): RuleResponseVO
{
$sequence = $handEntity->getSequence();
$sequence = $handVO->getSequence();
$isFullHouse = $this->isFullHouse($sequence);

return $this->buildRuleResponse(
Expand Down
8 changes: 4 additions & 4 deletions src/Rules/HighCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

namespace Roliod\TexasHUPoker\Rules;

use Roliod\TexasHUPoker\Deck\Entities\Hand as HandEntity;
use Roliod\TexasHUPoker\Rules\Entities\RuleResponse as RuleResponseEntity;
use Roliod\TexasHUPoker\Deck\VOs\Hand as HandVO;
use Roliod\TexasHUPoker\Rules\VOs\RuleResponse as RuleResponseVO;

class HighCard extends AbstractRule
{
Expand All @@ -16,9 +16,9 @@ class HighCard extends AbstractRule
/**
* {@inheritDoc}
*/
public function validate(HandEntity $handEntity): RuleResponseEntity
public function validate(HandVO $handVO): RuleResponseVO
{
$sequence = $handEntity->getSequence();
$sequence = $handVO->getSequence();
$isHighCard = $this->isHighCard($sequence);

return $this->buildRuleResponse(
Expand Down
8 changes: 4 additions & 4 deletions src/Rules/Pair.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

namespace Roliod\TexasHUPoker\Rules;

use Roliod\TexasHUPoker\Deck\Entities\Hand as HandEntity;
use Roliod\TexasHUPoker\Rules\Entities\RuleResponse as RuleResponseEntity;
use Roliod\TexasHUPoker\Deck\VOs\Hand as HandVO;
use Roliod\TexasHUPoker\Rules\VOs\RuleResponse as RuleResponseVO;

class Pair extends AbstractRule
{
Expand All @@ -16,9 +16,9 @@ class Pair extends AbstractRule
/**
* {@inheritDoc}
*/
public function validate(HandEntity $handEntity): RuleResponseEntity
public function validate(HandVO $handVO): RuleResponseVO
{
$sequence = $handEntity->getSequence();
$sequence = $handVO->getSequence();
$isPair = $this->isPair($sequence);

return $this->buildRuleResponse(
Expand Down
8 changes: 4 additions & 4 deletions src/Rules/RoyalFlush.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

namespace Roliod\TexasHUPoker\Rules;

use Roliod\TexasHUPoker\Deck\Entities\Hand as HandEntity;
use Roliod\TexasHUPoker\Rules\Entities\RuleResponse as RuleResponseEntity;
use Roliod\TexasHUPoker\Deck\VOs\Hand as HandVO;
use Roliod\TexasHUPoker\Rules\VOs\RuleResponse as RuleResponseVO;

class RoyalFlush extends AbstractRule
{
Expand All @@ -16,9 +16,9 @@ class RoyalFlush extends AbstractRule
/**
* {@inheritDoc}
*/
public function validate(HandEntity $handEntity): RuleResponseEntity
public function validate(HandVO $handVO): RuleResponseVO
{
$sequence = $handEntity->getSequence();
$sequence = $handVO->getSequence();
$isRoyalSequence = $this->isRoyalFlushSequence($sequence);

return $this->buildRuleResponse(
Expand Down
8 changes: 4 additions & 4 deletions src/Rules/Straight.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
namespace Roliod\TexasHUPoker\Rules;

use Roliod\TexasHUPoker\Deck\Rank;
use Roliod\TexasHUPoker\Deck\Entities\Hand as HandEntity;
use Roliod\TexasHUPoker\Rules\Entities\RuleResponse as RuleResponseEntity;
use Roliod\TexasHUPoker\Deck\VOs\Hand as HandVO;
use Roliod\TexasHUPoker\Rules\VOs\RuleResponse as RuleResponseVO;

class Straight extends AbstractRule
{
Expand All @@ -17,9 +17,9 @@ class Straight extends AbstractRule
/**
* {@inheritDoc}
*/
public function validate(HandEntity $handEntity): RuleResponseEntity
public function validate(HandVO $handVO): RuleResponseVO
{
$sequence = $handEntity->getSequence();
$sequence = $handVO->getSequence();
$isStraight = $this->isStraight($sequence);

return $this->buildRuleResponse(
Expand Down
18 changes: 9 additions & 9 deletions src/Rules/StraightFlush.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

namespace Roliod\TexasHUPoker\Rules;

use Roliod\TexasHUPoker\Deck\Entities\Hand as HandEntity;
use Roliod\TexasHUPoker\Rules\Entities\RuleResponse as RuleResponseEntity;
use Roliod\TexasHUPoker\Deck\VOs\Hand as HandVO;
use Roliod\TexasHUPoker\Rules\VOs\RuleResponse as RuleResponseVO;

class StraightFlush extends AbstractRule
{
Expand All @@ -16,10 +16,10 @@ class StraightFlush extends AbstractRule
/**
* {@inheritDoc}
*/
public function validate(HandEntity $handEntity): RuleResponseEntity
public function validate(HandVO $handVO): RuleResponseVO
{
$sequence = $handEntity->getSequence();
$isStraightFlush = $this->isStraightFlush($handEntity);
$sequence = $handVO->getSequence();
$isStraightFlush = $this->isStraightFlush($handVO);

return $this->buildRuleResponse(
$sequence,
Expand All @@ -29,14 +29,14 @@ public function validate(HandEntity $handEntity): RuleResponseEntity
}

/**
* @param HandEntity $handEntity
* @param HandVO $handVO
*
* @return bool
*/
private function isStraightFlush(HandEntity $handEntity): bool
private function isStraightFlush(HandVO $handVO): bool
{
$flush = (new Flush())->validate($handEntity);
$straight = (new Straight())->validate($handEntity);
$flush = (new Flush())->validate($handVO);
$straight = (new Straight())->validate($handVO);

return $flush->getMatches() && $straight->getMatches();
}
Expand Down
8 changes: 4 additions & 4 deletions src/Rules/ThreeOfAKind.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

namespace Roliod\TexasHUPoker\Rules;

use Roliod\TexasHUPoker\Deck\Entities\Hand as HandEntity;
use Roliod\TexasHUPoker\Rules\Entities\RuleResponse as RuleResponseEntity;
use Roliod\TexasHUPoker\Deck\VOs\Hand as HandVO;
use Roliod\TexasHUPoker\Rules\VOs\RuleResponse as RuleResponseVO;

class ThreeOfAKind extends AbstractRule
{
Expand All @@ -16,9 +16,9 @@ class ThreeOfAKind extends AbstractRule
/**
* {@inheritDoc}
*/
public function validate(HandEntity $handEntity): RuleResponseEntity
public function validate(HandVO $handVO): RuleResponseVO
{
$sequence = $handEntity->getSequence();
$sequence = $handVO->getSequence();
$isThreeAKind = $this->isThreeOfAKind($sequence);

return $this->buildRuleResponse(
Expand Down
8 changes: 4 additions & 4 deletions src/Rules/TwoPair.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

namespace Roliod\TexasHUPoker\Rules;

use Roliod\TexasHUPoker\Deck\Entities\Hand as HandEntity;
use Roliod\TexasHUPoker\Rules\Entities\RuleResponse as RuleResponseEntity;
use Roliod\TexasHUPoker\Deck\VOs\Hand as HandVO;
use Roliod\TexasHUPoker\Rules\VOs\RuleResponse as RuleResponseVO;

class TwoPair extends AbstractRule
{
Expand All @@ -16,9 +16,9 @@ class TwoPair extends AbstractRule
/**
* {@inheritDoc}
*/
public function validate(HandEntity $handEntity): RuleResponseEntity
public function validate(HandVO $handVO): RuleResponseVO
{
$sequence = $handEntity->getSequence();
$sequence = $handVO->getSequence();
$isTwoPair = $this->isTwoPair($sequence);

return $this->buildRuleResponse(
Expand Down
Loading

0 comments on commit a84d86f

Please sign in to comment.