CallableDecoratorAdapter   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 22
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getNbResults() 0 3 1
A getSlice() 0 6 2
A __construct() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Damax\Common\Pagerfanta;
6
7
use Pagerfanta\Adapter\AdapterInterface;
8
use Traversable;
9
10
final class CallableDecoratorAdapter implements AdapterInterface
11
{
12
    private $adapter;
13
    private $callback;
14
15
    public function __construct(AdapterInterface $adapter, callable $callback)
16
    {
17
        $this->adapter = $adapter;
18
        $this->callback = $callback;
19
    }
20
21
    public function getNbResults(): int
22
    {
23
        return $this->adapter->getNbResults();
24
    }
25
26
    public function getSlice($offset, $length): array
27
    {
28
        $items = $this->adapter->getSlice($offset, $length);
29
        $items = $items instanceof Traversable ? iterator_to_array($items, false) : $items;
30
31
        return array_values(array_map($this->callback, $items));
0 ignored issues
show
Bug introduced by
It seems like $items can also be of type iterable; however, parameter $array of array_map() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

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

31
        return array_values(array_map($this->callback, /** @scrutinizer ignore-type */ $items));
Loading history...
32
    }
33
}
34