update deps & install rector

This commit is contained in:
Dominik Liebler
2019-12-14 12:50:05 +01:00
parent 04acce6759
commit 579a5ac946
87 changed files with 2432 additions and 786 deletions

View File

@@ -2,6 +2,8 @@
namespace DesignPatterns\More\Repository\Domain;
use InvalidArgumentException;
/**
* Like PostId, this is a value object which holds the value of the current status of a Post. It can be constructed
* either from a string or int and is able to validate itself. An instance can then be converted back to int or string.
@@ -14,20 +16,13 @@ class PostStatus
const STATE_DRAFT = 'draft';
const STATE_PUBLISHED = 'published';
private static $validStates = [
private static array $validStates = [
self::STATE_DRAFT_ID => self::STATE_DRAFT,
self::STATE_PUBLISHED_ID => self::STATE_PUBLISHED,
];
/**
* @var int
*/
private $id;
/**
* @var string
*/
private $name;
private int $id;
private string $name;
public static function fromInt(int $statusId)
{
@@ -39,8 +34,13 @@ class PostStatus
public static function fromString(string $status)
{
self::ensureIsValidName($status);
$state = array_search($status, self::$validStates);
return new self(array_search($status, self::$validStates), $status);
if ($state === false) {
throw new InvalidArgumentException('Invalid state given!');
}
return new self($state, $status);
}
private function __construct(int $id, string $name)
@@ -66,7 +66,7 @@ class PostStatus
private static function ensureIsValidId(int $status)
{
if (!in_array($status, array_keys(self::$validStates), true)) {
throw new \InvalidArgumentException('Invalid status id given');
throw new InvalidArgumentException('Invalid status id given');
}
}
@@ -74,7 +74,7 @@ class PostStatus
private static function ensureIsValidName(string $status)
{
if (!in_array($status, self::$validStates, true)) {
throw new \InvalidArgumentException('Invalid status name given');
throw new InvalidArgumentException('Invalid status name given');
}
}
}