Completed
Push — master ( 38bba2...5afe5b )
by Kevin
02:40
created

PorpaginasSubscriber::getSubscribedEvents()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Zenstruck\Porpaginas\Bridge\KnpPager;
4
5
use Knp\Component\Pager\Event\ItemsEvent;
6
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
7
use Zenstruck\Porpaginas\Result;
8
9
/**
10
 * @author Kevin Bond <[email protected]>
11
 */
12
final class PorpaginasSubscriber implements EventSubscriberInterface
13
{
14 3
    public function items(ItemsEvent $event)
15
    {
16 3
        if (!$event->target instanceof Result) {
17 1
            return;
18
        }
19
20 2
        $event->count = $event->target->count();
21 2
        $event->items = $event->target->take($event->getOffset(), $event->getLimit())->getIterator();
22
23 2
        $event->stopPropagation();
24 2
    }
25
26
    /**
27
     * {@inheritdoc}
28
     */
29 2
    public static function getSubscribedEvents()
30
    {
31 2
        return ['knp_pager.items' => ['items', 0]];
32
    }
33
}
34