| Total Complexity | 4 |
| Total Lines | 55 |
| Duplicated Lines | 0 % |
| 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 | public function __construct( |
||
| 26 | ShortUrlRepositoryInterface $repository, |
||
| 27 | $searchTerm = null, |
||
| 28 | array $tags = [], |
||
| 29 | $orderBy = null |
||
| 30 | ) { |
||
| 31 | $this->repository = $repository; |
||
| 32 | $this->searchTerm = $searchTerm !== null ? trim(strip_tags($searchTerm)) : null; |
||
| 33 | $this->orderBy = $orderBy; |
||
| 34 | $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 | public function getItems($offset, $itemCountPerPage): array |
||
| 45 | { |
||
| 46 | return $this->repository->findList( |
||
| 47 | $itemCountPerPage, |
||
| 48 | $offset, |
||
| 49 | $this->searchTerm, |
||
| 50 | $this->tags, |
||
| 51 | $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 | public function count(): int |
||
| 67 | } |
||
| 68 | } |
||
| 69 |