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::generatePaginationRange()   B
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 34
Code Lines 19

Duplication

Lines 18
Ratio 52.94 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 4
eloc 19
c 3
b 0
f 0
nc 4
nop 3
dl 18
loc 34
rs 8.5806
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