Test Setup Failed
Push — master ( 2ef000...2741a1 )
by Florian
04:53
created

CakeOrmAdapter   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 24
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A paginate() 0 15 2
1
<?php
2
/**
3
 * Copyright (c) Phauthentic (https://github.com/Phauthentic)
4
 *
5
 * Licensed under The MIT License
6
 * For full copyright and license information, please see the LICENSE.txt
7
 * Redistributions of files must retain the above copyright notice.
8
 *
9
 * @copyright     Copyright (c) Phauthentic (https://github.com/Phauthentic)
10
 * @link          https://github.com/Phauthentic
11
 * @license       https://opensource.org/licenses/mit-license.php MIT License
12
 */
13
declare(strict_types = 1);
14
15
namespace Phauthentic\Pagination;
16
17
use Cake\Datasource\QueryInterface;
18
use Psr\Http\Message\ServerRequestInterface;
19
20
/**
21
 * Pagination To Cake Orm Mapper
22
 */
23
class CakeOrmAdapter implements PaginationAdapterInterface
24
{
25
    /**
26
     * Maps the params to the repository
27
     *
28
     * @param \Phauthentic\Pagination\PaginationParamsInterface $paginationParams Pagination params
29
     * @param mixed $repository
30
     * @return mixed
31
     */
32
    public function paginate(PaginationParamsInterface $paginationParams, $object)
33
    {
34
        $query = null;
35
        if ($object instanceof QueryInterface) {
36
            $query = $object;
37
            $object = $query->getRepository();
0 ignored issues
show
Unused Code introduced by
The assignment to $object is dead and can be removed.
Loading history...
38
        }
39
40
        $count = $query->count();
0 ignored issues
show
Bug introduced by
The method count() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

40
        /** @scrutinizer ignore-call */ 
41
        $count = $query->count();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
41
        $paginationParams->setCount($count);
42
43
        return $query
44
            ->limit($paginationParams->getLimit())
45
            ->offSet($paginationParams->getOffSet())
46
            ->all();
47
    }
48
}
49