Completed
Pull Request — master (#156)
by Lucas
02:51
created

SimplePaginate::simplePaginate()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 9.6
c 0
b 0
f 0
cc 2
nc 1
nop 0
1
<?php
2
3
namespace Spatie\CollectionMacros\Macros;
4
5
6
use Illuminate\Pagination\Paginator;
7
8
class SimplePaginate
9
{
10
    /**
11
     * Paginate the collection into a simple paginator
12
     *
13
     * @param int $perPage
0 ignored issues
show
Bug introduced by
There is no parameter named $perPage. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
14
     * @param int $page
0 ignored issues
show
Bug introduced by
There is no parameter named $page. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
15
     * @param string $pageName
0 ignored issues
show
Bug introduced by
There is no parameter named $pageName. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
16
     *
17
     * @return \Illuminate\Contracts\Pagination\Paginator
18
     */
19
    public function simplePaginate()
20
    {
21
        return function (
22
            int $perPage = 15,
23
            string $pageName = 'page',
24
            int $page = null,
25
            array $options = []
26
        ): Paginator {
27
            $page = $page ?: Paginator::resolveCurrentPage($pageName);
28
29
            $results = $this->slice(($page - 1) * $perPage)->take($perPage + 1);
0 ignored issues
show
Bug introduced by
The method slice() does not seem to exist on object<Spatie\Collection...\Macros\SimplePaginate>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
30
31
            $options += [
32
                'path' => Paginator::resolveCurrentPath(),
33
                'pageName' => $pageName,
34
            ];
35
36
            return new Paginator($results, $perPage, $page, $options);
37
        };
38
    }
39
}
40