BasicRelationshipPaginationStrategy   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 39
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getParameters() 0 10 4
A getDefaultPageSize() 0 4 1
1
<?php declare (strict_types = 1);
2
3
namespace Limoncello\Flute\Api;
4
5
/**
6
 * Copyright 2015-2019 [email protected]
7
 *
8
 * Licensed under the Apache License, Version 2.0 (the "License");
9
 * you may not use this file except in compliance with the License.
10
 * You may obtain a copy of the License at
11
 *
12
 * http://www.apache.org/licenses/LICENSE-2.0
13
 *
14
 * Unless required by applicable law or agreed to in writing, software
15
 * distributed under the License is distributed on an "AS IS" BASIS,
16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
 * See the License for the specific language governing permissions and
18
 * limitations under the License.
19
 */
20
21
use Limoncello\Flute\Contracts\Api\RelationshipPaginationStrategyInterface;
22
use function assert;
23
24
/**
25
 * @package Limoncello\Flute
26
 */
27
class BasicRelationshipPaginationStrategy implements RelationshipPaginationStrategyInterface
28
{
29
    /**
30
     * @var int
31
     */
32
    private $defaultPageSize;
33
34
    /**
35
     * @param int $defaultPageSize
36 66
     */
37
    public function __construct(int $defaultPageSize)
38 66
    {
39
        assert($defaultPageSize > 0);
40 66
41
        $this->defaultPageSize = $defaultPageSize;
42
    }
43
44
    /**
45
     * @inheritdoc
46 9
     */
47
    public function getParameters(string $rootClass, string $class, string $path, string $relationshipName): array
48
    {
49
        // input parameters are ignored (same paging params for all)
50 9
        // feel free to change it in child classes
51
        assert($rootClass || $class || $path || $relationshipName);
52 9
53
        $offset = 0;
54 9
55
        return [$offset, $this->getDefaultPageSize()];
56
    }
57
58
    /**
59
     * @return int
60 9
     */
61
    public function getDefaultPageSize(): int
62 9
    {
63
        return $this->defaultPageSize;
64
    }
65
}
66