Passed
Push — master ( 8361b2...989824 )
by Florian
08:31
created

PaginationService   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 2
dl 0
loc 26
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
1
<?php
2
/**
3
 * Copyright (c) Florian Krämer
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) Florian Krämer
10
 * @link          https://github.com/burzum/cakephp-service-layer
11
 * @since         1.0.0
12
 * @license       https://opensource.org/licenses/mit-license.php MIT License
13
 */
14
declare(strict_types = 1);
15
16
namespace Burzum\Cake\Service;
17
18
use Cake\Http\ServerRequest;
19
20
/**
21
 * Pagination Service
22
 */
23
class PaginationService {
24
25
    use ServicePaginatorTrait;
26
27
    /**
28
     * Server Request Object
29
     *
30
     * @var \Cake\Http\ServerRequest|null $request Server Request
31
     */
32
    protected $request;
33
34
    /**
35
     * Constructor
36
     *
37
     * @param \Cake\Http\ServerRequest $request Server Request
38
     */
39 1
    public function __construct(ServerRequest $request)
40
    {
41 1
        $this->request = $request;
42
43 1
        $_this = $this;
44 1
        $this->getEventManager()->on('Service.afterPaginate', function() use ($_this) {
45 1
            $_this->addPagingParamToRequest($_this->request);
0 ignored issues
show
Bug introduced by
It seems like $_this->request can be null; however, addPagingParamToRequest() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
46 1
        });
47 1
    }
48
}
49