| Total Complexity | 4 |
| Total Lines | 55 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 12 | class ShortUrlRepositoryAdapter implements AdapterInterface |
||
| 13 | { |
||
| 14 | public const ITEMS_PER_PAGE = 10; |
||
| 15 | |||
| 16 | /** @var ShortUrlRepositoryInterface */ |
||
| 17 | private $repository; |
||
| 18 | /** @var null|string */ |
||
| 19 | private $searchTerm; |
||
| 20 | /** @var null|array|string */ |
||
| 21 | private $orderBy; |
||
| 22 | /** @var array */ |
||
| 23 | private $tags; |
||
| 24 | |||
| 25 | 3 | public function __construct( |
|
| 26 | ShortUrlRepositoryInterface $repository, |
||
| 27 | $searchTerm = null, |
||
| 28 | array $tags = [], |
||
| 29 | $orderBy = null |
||
| 30 | ) { |
||
| 31 | 3 | $this->repository = $repository; |
|
| 32 | 3 | $this->searchTerm = $searchTerm !== null ? trim(strip_tags($searchTerm)) : null; |
|
| 33 | 3 | $this->orderBy = $orderBy; |
|
| 34 | 3 | $this->tags = $tags; |
|
| 35 | } |
||
| 36 | |||
| 37 | /** |
||
| 38 | * Returns a collection of items for a page. |
||
| 39 | * |
||
| 40 | * @param int $offset Page offset |
||
| 41 | * @param int $itemCountPerPage Number of items per page |
||
| 42 | * @return array |
||
| 43 | */ |
||
| 44 | 2 | public function getItems($offset, $itemCountPerPage): array |
|
| 45 | { |
||
| 46 | 2 | return $this->repository->findList( |
|
| 47 | 2 | $itemCountPerPage, |
|
| 48 | $offset, |
||
| 49 | 2 | $this->searchTerm, |
|
| 50 | 2 | $this->tags, |
|
| 51 | 2 | $this->orderBy |
|
| 52 | ); |
||
| 53 | } |
||
| 54 | |||
| 55 | /** |
||
| 56 | * Count elements of an object |
||
| 57 | * @link http://php.net/manual/en/countable.count.php |
||
| 58 | * @return int The custom count as an integer. |
||
| 59 | * </p> |
||
| 60 | * <p> |
||
| 61 | * The return value is cast to an integer. |
||
| 62 | * @since 5.1.0 |
||
| 63 | */ |
||
| 64 | 2 | public function count(): int |
|
| 67 | } |
||
| 68 | } |
||
| 69 |