Issues (590)

src/Query/Extension/PaginableTrait.php (2 issues)

1
<?php
2
3
namespace Bdf\Prime\Query\Extension;
4
5
use Bdf\Prime\Query\Contract\Paginable;
6
use Bdf\Prime\Query\Pagination\PaginatorFactory;
7
use Bdf\Prime\Query\Pagination\PaginatorInterface;
8
use Bdf\Prime\Query\Pagination\Walker;
9
10
/**
11
 * Trait for @see Paginable queries
12
 *
13
 * @template R as array|object
14
 * @psalm-require-implements Paginable
15
 */
16
trait PaginableTrait
17
{
18
    /**
19
     * @var PaginatorFactory|null
20
     */
21
    private $paginatorFactory;
22
23
    /**
24
     * @param PaginatorFactory $paginatorFactory
25
     */
26 657
    public function setPaginatorFactory(PaginatorFactory $paginatorFactory): void
27
    {
28 657
        $this->paginatorFactory = $paginatorFactory;
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     *
34
     * @return Walker<R>
35
     */
36 2
    public function getIterator(): \Iterator
37
    {
38 2
        return $this->walk();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->walk() returns the type Bdf\Prime\Query\Pagination\PaginatorInterface which is incompatible with the type-hinted return Iterator.
Loading history...
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     *
44
     * @see Paginable::paginate()
45
     * @psalm-suppress LessSpecificImplementedReturnType
46
     *
47
     * @return PaginatorInterface<R>
48
     */
49 33
    public function paginate(?int $maxRows = null, ?int $page = null, string $className = 'paginator'): PaginatorInterface
50
    {
51 33
        $factory = $this->paginatorFactory ?? PaginatorFactory::instance();
52
53 33
        return $factory->create($this, $className, $maxRows, $page);
0 ignored issues
show
$this of type Bdf\Prime\Query\Extension\PaginableTrait is incompatible with the type Bdf\Prime\Query\ReadCommandInterface expected by parameter $query of Bdf\Prime\Query\Paginati...inatorFactory::create(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

53
        return $factory->create(/** @scrutinizer ignore-type */ $this, $className, $maxRows, $page);
Loading history...
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     *
59
     * @see Paginable::walk()
60
     * @psalm-suppress LessSpecificImplementedReturnType
61
     *
62
     * @return Walker<R>
63
     */
64 12
    public function walk(?int $maxRows = null, ?int $page = null): PaginatorInterface
65
    {
66 12
        return $this->paginate($maxRows, $page, 'walker');
67
    }
68
}
69