Test Setup Failed
Pull Request — master (#1)
by Florian
10:46
created

PaginationService::setPaginator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
ccs 0
cts 1
cp 0
crap 2
1
<?php
2
declare(strict_types = 1);
3
/**
4
 * Copyright (c) Phauthentic (https://github.com/Phauthentic)
5
 *
6
 * Licensed under The MIT License
7
 * For full copyright and license information, please see the LICENSE.txt
8
 * Redistributions of files must retain the above copyright notice.
9
 *
10
 * @copyright     Copyright (c) Phauthentic (https://github.com/Phauthentic)
11
 * @link          https://github.com/Phauthentic
12
 * @license       https://opensource.org/licenses/mit-license.php MIT License
13
 */
14
namespace Phauthentic\Pagination;
15
16
use Phauthentic\Pagination\Paginator\PaginatorInterface;
17
use Phauthentic\Pagination\ParamsFactory\PaginationParamsFactoryInterface;
18
use Psr\Http\Message\ServerRequestInterface;
19
20
/**
21
 * Pagination Service
22
 *
23
 * Application layer pagination service that should in theory be able to paginate
24
 * any data / persistence layer implementation through the mappers.
25
 */
26
class PaginationService
27
{
28
    /**
29
     * Pagination Params Factory
30
     *
31
     * @var \Phauthentic\Pagination\PaginationParamsFactoryInterface
0 ignored issues
show
Bug introduced by
The type Phauthentic\Pagination\P...nParamsFactoryInterface 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...
32
     */
33
    protected $paginationParamsFactory;
34
35
    /**
36
     * Pagination to data layer implementation mapper
37
     *
38
     * @var \Phauthentic\Pagination\Paginator\PaginatorInterface;
39
     */
40
    protected $paginator;
41
42
    /**
43
     * Constructor
44
     *
45
     * @param \Phauthentic\Pagination\PaginationParamsFactoryInterface
46
     */
47
    public function __construct(
48
        PaginationParamsFactoryInterface $paginationParamsFactory,
49
        PaginatorInterface $paginationAdapter
50
    ) {
51
        $this->paginationParamsFactory = $paginationParamsFactory;
0 ignored issues
show
Documentation Bug introduced by
It seems like $paginationParamsFactory of type Phauthentic\Pagination\P...nParamsFactoryInterface is incompatible with the declared type Phauthentic\Pagination\P...nParamsFactoryInterface of property $paginationParamsFactory.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
52
        $this->paginator = $paginationAdapter;
53
    }
54
55
    /**
56
     * Sets the object that maps the pagination data to the underlying implementation
57
     *
58
     * @return $this
59
     */
60
    public function setPaginator(PaginatorInterface $paginator): self
61
    {
62
        $this->paginator = $paginator;
63
64
        return $this;
65
    }
66
67
    /**
68
     * Sets the pagination params factory
69
     *
70
     * @return $this
71
     */
72
    public function setPaginationParamsFactory(PaginationParamsFactoryInterface $factory): self
73
    {
74
        $this->paginationParamsFactory = $factory;
0 ignored issues
show
Documentation Bug introduced by
It seems like $factory of type Phauthentic\Pagination\P...nParamsFactoryInterface is incompatible with the declared type Phauthentic\Pagination\P...nParamsFactoryInterface of property $paginationParamsFactory.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
75
76
        return $this;
77
    }
78
79
    /**
80
     * Triggers the pagination
81
     *
82
     * @param \Psr\Http\Message\ServerRequestInterface
83
     * @param mixed $repository The repository / array / collection to paginate
84
     * @param \Phauthentic\Pagination\PaginationParamsInterface $paginationParams Paging Params
85
     * @return mixed
86
     */
87
    public function paginate($repository, ?PaginationParamsInterface $paginationParams)
88
    {
89
        if ($paginationParams === null) {
90
            $paginationParams = $this->paginationParamsFactory->build($repository);
91
        }
92
93
        return $this->paginator->paginate($repository, $paginationParams);
94
    }
95
}
96