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

PaginableQueryAdapter::count()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
ccs 0
cts 2
cp 0
cc 1
nc 1
nop 0
crap 2
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