GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Math   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 40 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 18
loc 45
rs 10
wmc 4
lcom 0
cbo 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B generatePaginationRange() 18 34 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
 * Math.php
4
 */
5
namespace w3l\Holt45;
6
7
/**
8
 * Calculate stuff
9
 */
10
trait Math
11
{
12
    /**
13
     * Create range for pagination
14
     *
15
     * @param int $totalPages
16
     * @param int $selectedPage
17
     * @param int $numberOfResults
18
     * @return array Array with all page-numbers limited by $number_of_results
19
     */
20
    public static function generatePaginationRange($totalPages, $selectedPage = 1, $numberOfResults = 7)
21
    {
22
        // Get the numbers
23
        $tempArrayRange = range(1, $totalPages);
24
25
        if ($totalPages <= $numberOfResults) {
26
            // all
27
            $arrayData = $tempArrayRange;
28 View Code Duplication
        } elseif ($selectedPage <= (round(($numberOfResults / 2), 0, PHP_ROUND_HALF_UP))) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
29
            // 1-6+last
30
            $arrayData = array_slice($tempArrayRange, 0, ($numberOfResults-1));
31
            $arrayData[] = $totalPages;
32
33
        } elseif ($selectedPage >= $totalPages-round(($numberOfResults / 2), 0, PHP_ROUND_HALF_DOWN)) {
34
            // first + $totalPages-5 - $totalPages
35
            $arrayData = array_slice($tempArrayRange, $totalPages-($numberOfResults-1));
36
            $arrayData[] = 1;
37 View Code Duplication
        } else {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
38
            // first + $totalPages-2 - $totalPages+2 + last
39
            $arrayData = array_slice(
40
                $tempArrayRange,
41
                $selectedPage-(round(($numberOfResults / 2), 0, PHP_ROUND_HALF_DOWN)),
42
                ($numberOfResults-2)
43
            );
44
45
            $arrayData[] = 1;
46
            $arrayData[] = $totalPages;
47
48
        }
49
50
        sort($arrayData);
51
52
        return $arrayData;
53
    }
54
}
55