Paginate::__invoke()   A
last analyzed

Complexity

Conditions 3
Paths 1

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 9.7
c 0
b 0
f 0
cc 3
nc 1
nop 0
1
<?php
2
3
namespace Spatie\CollectionMacros\Macros;
4
5
use Illuminate\Pagination\LengthAwarePaginator;
6
7
/**
8
 * Paginate the given collection.
9
 *
10
 * @param int $perPage
11
 * @param int $total
12
 * @param int $page
13
 * @param string $pageName
14
 *
15
 * @mixin \Illuminate\Support\Collection
16
 *
17
 * @return \Illuminate\Pagination\LengthAwarePaginator
18
 */
19
class Paginate
20
{
21
    public function __invoke()
22
    {
23
        return function (int $perPage = 15, string $pageName = 'page', int $page = null, int $total = null, array $options = []): LengthAwarePaginator {
24
            $page = $page ?: LengthAwarePaginator::resolveCurrentPage($pageName);
25
26
            $results = $this->forPage($page, $perPage)->values();
0 ignored issues
show
Bug introduced by
The method forPage() does not seem to exist on object<Spatie\CollectionMacros\Macros\Paginate>.

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...
27
28
            $total = $total ?: $this->count();
0 ignored issues
show
Bug introduced by
The method count() does not seem to exist on object<Spatie\CollectionMacros\Macros\Paginate>.

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...
29
30
            $options += [
31
                'path' => LengthAwarePaginator::resolveCurrentPath(),
32
                'pageName' => $pageName,
33
            ];
34
35
            return new LengthAwarePaginator($results, $total, $perPage, $page, $options);
36
        };
37
    }
38
}
39