Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
100.00% |
1 / 1 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
10 / 10 |
Quote | |
100.00% |
1 / 1 |
|
100.00% |
5 / 5 |
5 | |
100.00% |
10 / 10 |
__construct | |
100.00% |
1 / 1 |
1 | |
100.00% |
3 / 3 |
|||
fromArray | |
100.00% |
1 / 1 |
1 | |
100.00% |
3 / 3 |
|||
getAuthor | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
getQuote | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
toArray | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
<?php | |
declare(strict_types=1); | |
namespace App\Quote\Model; | |
use Webmozart\Assert\Assert; | |
final class Quote implements QuoteInterface | |
{ | |
private string $author; | |
private string $quote; | |
public function __construct( | |
string $author, | |
string $quote | |
) { | |
$this->author = $author; | |
$this->quote = $quote; | |
} | |
public static function fromArray(array $data): self | |
{ | |
Assert::keyExists($data, 'author'); | |
Assert::keyExists($data, 'quote'); | |
return new self($data['author'], $data['quote']); | |
} | |
public function getAuthor(): string | |
{ | |
return $this->author; | |
} | |
public function getQuote(): string | |
{ | |
return $this->quote; | |
} | |
public function toArray(): array | |
{ | |
return [ | |
'author' => $this->author, | |
'quote' => $this->quote | |
]; | |
} | |
} |