PaginationExtension   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 46
Duplicated Lines 34.78 %

Coupling/Cohesion

Components 2
Dependencies 2

Importance

Changes 0
Metric Value
wmc 8
lcom 2
cbo 2
dl 16
loc 46
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A offset() 8 8 4
A limit() 8 8 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Ntb\RestAPI;
4
5
/**
6
 * Class PaginationExtension
7
 * @author Christian Blank <[email protected]>
8
 */
9
class PaginationExtension extends \Extension {
10
11
    /**
12
     * The default limit.
13
     * Can be overridden in children.
14
     * @var int
15
     */
16
    protected static $default_limit = 20;
17
18
    /**
19
     * The default offset.
20
     * Can be overridden in children.
21
     * @var int
22
     */
23
    protected static $default_offset = 0;
24
25
    /**
26
     * Returns the offset, either given in request by `offset` or from the default settings in the controller.
27
     *
28
     * @param \SS_HTTPRequest $request
29
     * @return int the offset value
30
     */
31 View Code Duplication
    public function offset($request) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
32
        $offset = (int)$request->getVar('offset');
33
        if($offset && is_int($offset) && $offset >= 0) {
34
            return $offset;
35
        } else {
36
            return static::$default_offset;
37
        }
38
    }
39
40
    /**
41
     * Returns the limit, either given in request by `limit` or from the default settings in the controller.
42
     *
43
     * @param \SS_HTTPRequest $request
44
     * @return int the limit value
45
     */
46 View Code Duplication
    public function limit($request) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
47
        $limit = (int)$request->getVar('limit');
48
        if($limit && is_int($limit) && $limit > 0) {
49
            return $limit;
50
        } else {
51
            return static::$default_limit;
52
        }
53
    }
54
}