Completed
Push — 2.0 ( d39b3c...f2914f )
by Kirill
02:52
created

Paginator::bootPaginator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of laravel.su package.
4
 * For the full copyright and license information, please view the LICENSE
5
 * file that was distributed with this source code.
6
 */
7
declare(strict_types=1);
8
9
namespace App\GraphQL\Feature;
10
11
use GraphQL\Type\Definition\Type;
12
use Illuminate\Database\Eloquent\Builder;
13
use App\GraphQL\Feature\Kernel\FeaturesSupport;
14
use App\GraphQL\Feature\Paginator\PaginatorConfiguration as P;
15
16
/**
17
 * Class Paginator
18
 * @mixin FeaturesSupport
19
 */
20
trait Paginator
21
{
22
    /**
23
     * @return void
24
     */
25
    public function bootPaginator(): void
26
    {
27
        $limit = [P::QUERY_LIMIT, Type::int(), 'Items per page: in 1...1000 range'];
28
        $page  = [P::QUERY_PAGE, Type::int(), 'Current page number (Usage without "_limit" argument gives no effect)'];
29
30
        $this->addArgument(...$limit);
0 ignored issues
show
Bug introduced by
It seems like addArgument() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
31
        $this->addArgument(...$page);
0 ignored issues
show
Bug introduced by
It seems like addArgument() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
32
    }
33
34
    /**
35
     * @param Builder $builder
36
     * @param int $count
37
     * @return P
38
     */
39
    protected function paginate(Builder $builder, int $count): P
40
    {
41
        return new P($builder, $count);
42
    }
43
}