Passed
Push — master ( ccac26...8af3ec )
by Derek Stephen
17:23 queued 15:42
created

Pagination::paginate()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 4
nop 3
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Bone\BoneDoctrine\Traits;
6
7
use Bone\Application;
0 ignored issues
show
Bug introduced by
The type Bone\Application was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Doctrine\Common\Collections\ArrayCollection;
9
use Doctrine\Common\Collections\Collection;
10
use Doctrine\Persistence\ObjectRepository;
11
12
trait Pagination
13
{
14
    public function paginate(ObjectRepository $repository,  array $where = [], $orderBy = []): Collection
15
    {
16
        $request = Application::ahoy()->getGlobalRequest();
17
        $params = $request->getQueryParams();
18
        $page = isset($params['page']) ? (int) $params['page'] : 1;
19
        $limit = isset($params['limit']) ? (int) $params['limit'] : 25;
20
        $offset = ($page *  $limit) - $limit;
21
22
        return new ArrayCollection($repository->findBy($where, $orderBy, $limit, $offset));
23
    }
24
}
25