Passed
Pull Request — master (#361)
by Alejandro
05:54
created

PaginableQueryAdapter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
eloc 10
dl 0
loc 24
rs 10
c 0
b 0
f 0
ccs 0
cts 10
cp 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getItems() 0 6 1
A count() 0 3 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Shlinkio\Shlink\Common\Paginator\Adapter;
5
6
use Doctrine\ORM\Query;
7
use Zend\Paginator\Adapter\AdapterInterface;
8
9
class PaginableQueryAdapter implements AdapterInterface
10
{
11
    /** @var Query */
12
    private $query;
13
    /** @var int */
14
    private $totalItems;
15
16
    public function __construct(Query $query, int $totalItems)
17
    {
18
        $this->query = $query;
19
        $this->totalItems = $totalItems;
20
    }
21
22
    public function getItems($offset, $itemCountPerPage): iterable
23
    {
24
        return $this->query
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->query->set...ult($offset)->iterate() returns the type Doctrine\ORM\Internal\Hydration\IterableResult which is incompatible with the return type mandated by Zend\Paginator\Adapter\A...erInterface::getItems() of array.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
25
            ->setMaxResults($itemCountPerPage)
26
            ->setFirstResult($offset)
27
            ->iterate();
28
    }
29
30
    public function count(): int
31
    {
32
        return $this->totalItems;
33
    }
34
}
35