Skip to content
This repository has been archived by the owner on May 3, 2023. It is now read-only.

Create a new ready session use case #10

Merged
merged 19 commits into from Apr 8, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/Application/ReadySession/GetReadySessionQuery.php
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace StepupReadId\Application\ReadySession;

final class GetReadySessionQuery
{
/** @var int */
private $ttl;

public function __construct(int $ttl)
{
$this->ttl = $ttl;
}

public function ttl(): int
{
return $this->ttl;
}
}
27 changes: 27 additions & 0 deletions src/Application/ReadySession/GetReadySessionQueryHandler.php
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace StepupReadId\Application\ReadySession;

use StepupReadId\Domain\ReadySession\Model\ReadySession;
use StepupReadId\Domain\ReadySession\Model\ReadySessionTTL;
use StepupReadId\Domain\ReadySession\Services\RequestReadySessionInterface;

final class GetReadySessionQueryHandler
{
/** @var RequestReadySessionInterface */
private $requestReadySession;

public function __construct(RequestReadySessionInterface $requestReadySession)
{
$this->requestReadySession = $requestReadySession;
}

public function __invoke(GetReadySessionQuery $query): ReadySession
{
$ttl = ReadySessionTTL::fromInteger($query->ttl());

return $this->requestReadySession->with($ttl);
}
}
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace StepupReadId\Domain\ReadySession\Exception;

use InvalidArgumentException;
use StepupReadId\Domain\ReadySession\Model\ReadySessionTTL;
use function sprintf;

final class InvalidReadySessionTTLException extends InvalidArgumentException
{
public static function becauseOutOfRange(int $ttl): self
{
return new self(
sprintf(
'Invalid TTL (%d), must be between %d and %d',
$ttl,
ReadySessionTTL::MINIMUM_TTL,
ReadySessionTTL::MINIMUM_TTL
)
);
}
sgomez marked this conversation as resolved.
Show resolved Hide resolved
}
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

namespace StepupReadId\Domain\ReadySession\Exception;

use RuntimeException;

final class RequestReadySessionAuthorizationException extends RuntimeException
{
}
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

namespace StepupReadId\Domain\ReadySession\Exception;

use RuntimeException;

final class RequestReadySessionBadRequestException extends RuntimeException
{
}
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace StepupReadId\Domain\ReadySession\Exception;

use RuntimeException;
use function sprintf;

final class RequestReadySessionConnectionException extends RuntimeException
{
public static function becauseTransportError(string $cause): self
{
return new self(sprintf('Transport error: %s', $cause));
}

public static function becauseResponseIsInvalid(): self
{
return new self('Invalid response');
}
}
40 changes: 40 additions & 0 deletions src/Domain/ReadySession/Model/ReadySessionTTL.php
@@ -0,0 +1,40 @@
<?php

declare(strict_types=1);

namespace StepupReadId\Domain\ReadySession\Model;

use StepupReadId\Domain\ReadySession\Exception\InvalidReadySessionTTLException;

final class ReadySessionTTL
{
public const MINIMUM_TTL = 30;
public const MAXIMUM_TTL = 72000;

/** @var int */
private $value;

private function __construct(int $ttl)
{
if ($ttl < self::MINIMUM_TTL || $ttl > self::MAXIMUM_TTL) {
throw InvalidReadySessionTTLException::becauseOutOfRange($ttl);
}

$this->value = $ttl;
}

public static function fromInteger(int $ttl): self
{
return new self($ttl);
}

public function value(): int
{
return $this->value;
}

public function equals(ReadySessionTTL $other): bool
{
return $this->value === $other->value;
}
}
21 changes: 21 additions & 0 deletions src/Domain/ReadySession/Services/RequestReadySessionInterface.php
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace StepupReadId\Domain\ReadySession\Services;

use StepupReadId\Domain\ReadySession\Exception\RequestReadySessionAuthorizationException;
use StepupReadId\Domain\ReadySession\Exception\RequestReadySessionBadRequestException;
use StepupReadId\Domain\ReadySession\Exception\RequestReadySessionConnectionException;
use StepupReadId\Domain\ReadySession\Model\ReadySession;
use StepupReadId\Domain\ReadySession\Model\ReadySessionTTL;

/**
* @throws RequestReadySessionAuthorizationException
* @throws RequestReadySessionBadRequestException
* @throws RequestReadySessionConnectionException
*/
interface RequestReadySessionInterface
{
public function with(ReadySessionTTL $ttl): ReadySession;
}