Completed
Push — master ( 4851fa...058e40 )
by Valentyn
04:07
created

PaginatedCollection   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 38
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getItems() 0 4 1
A getTotal() 0 4 1
A getOffset() 0 4 1
A getLimit() 0 4 1
A __construct() 0 11 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Pagination;
6
7
use Doctrine\ORM\Query;
8
use Doctrine\ORM\Tools\Pagination\Paginator;
9
10
class PaginatedCollection implements PaginatedCollectionInterface
11
{
12
    private $offset = 0;
13
    private $limit = 20;
14
    private $paginator;
15
16 19
    public function __construct(Query $query, int $offset, ?int $limit, bool $fetchJoinCollection = true)
17
    {
18 19
        $this->offset = abs($offset);
0 ignored issues
show
Documentation Bug introduced by
It seems like abs($offset) can also be of type double. However, the property $offset is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
19
20 19
        if ($limit !== null) {
21 3
            $this->limit = abs($limit);
0 ignored issues
show
Documentation Bug introduced by
It seems like abs($limit) can also be of type double. However, the property $limit is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
22
        }
23
24 19
        $query = $query->setFirstResult($this->offset)->setMaxResults($this->limit);
25 19
        $this->paginator = new Paginator($query, $fetchJoinCollection);
26 19
    }
27
28 19
    public function getItems()
29
    {
30 19
        return $this->paginator;
31
    }
32
33 19
    public function getTotal(): int
34
    {
35 19
        return (int) $this->getItems()->count();
36
    }
37
38 18
    public function getOffset(): int
39
    {
40 18
        return $this->offset;
41
    }
42
43 18
    public function getLimit(): int
44
    {
45 18
        return $this->limit;
46
    }
47
}
48