Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
75.00% covered (warning)
75.00%
3 / 4
CRAP
90.91% covered (success)
90.91%
10 / 11
QuoteService
0.00% covered (danger)
0.00%
0 / 1
75.00% covered (warning)
75.00%
3 / 4
5.02
90.91% covered (success)
90.91%
10 / 11
 __construct
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 getQuotes
0.00% covered (danger)
0.00%
0 / 1
2.02
83.33% covered (warning)
83.33%
5 / 6
 getQuotesFormatted
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 transformQuotesUsingPresenterWrapper
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
<?php
declare(strict_types=1);
namespace App\Quote\Service;
use App\Quote\Model\QuoteInterface;
use App\Quote\Presenter\ShoutPresenterWrapper;
use App\Quote\Repository\QuoteRepositoryInterface;
final class QuoteService implements QuoteServiceInterface
{
    private QuoteRepositoryInterface $repository;
    public function __construct(
        QuoteRepositoryInterface $repository
    ) {
        $this->repository = $repository;
    }
    public function getQuotes(string $author, int $limit = 10): array
    {
        $quotes = $this->repository->findByCriteria([
            'author' => trim($author),
            'limit' => $limit
        ]);
        if (empty($quotes)) {
            return [];
        }
        return $quotes;
    }
    public function getQuotesFormatted(string $author, int $limit = 1): array
    {
        return $this->transformQuotesUsingPresenterWrapper($this->getQuotes($author, $limit));
    }
    private function transformQuotesUsingPresenterWrapper(array $quotes): array
    {
        return array_map(static function (QuoteInterface $quote) {
            return (new ShoutPresenterWrapper($quote))->toArray();
        }, $quotes);
    }
}