FilestoragePager::getNbResults()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 7
rs 10
cc 2
nc 2
nop 0
1
<?php
2
3
namespace Apie\FileStoragePlugin\Pagers;
4
5
use Apie\FileStoragePlugin\DataLayers\FileStorageDataLayer;
6
use Iterator;
7
use LimitIterator;
8
use OutOfBoundsException;
9
use Pagerfanta\Adapter\AdapterInterface;
10
use Symfony\Component\Finder\Finder;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Finder\Finder was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use Symfony\Component\Finder\SplFileInfo;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Finder\SplFileInfo was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
13
class FilestoragePager implements AdapterInterface
14
{
15
    /**
16
     * @var FileStorageDataLayer
17
     */
18
    private $dataLayer;
19
20
    /**
21
     * @var Iterator
22
     */
23
    private $iterator;
24
25
    /**
26
     * @var string
27
     */
28
    private $resourceClass;
29
30
    /**
31
     * @var array
32
     */
33
    private $context;
34
35
    public function __construct(FileStorageDataLayer $dataLayer, Iterator $iterator, string $resourceClass, array $context)
36
    {
37
        $this->dataLayer = $dataLayer;
38
        $this->iterator = $iterator;
39
        $this->resourceClass = $resourceClass;
40
        $this->context = $context;
41
    }
42
43
    public function getNbResults()
44
    {
45
        $count = 0;
46
        for ($this->iterator->rewind(); $this->iterator->valid(); $this->iterator->next()) {
47
            $count++;
48
        }
49
        return $count;
50
    }
51
52
    public function getSlice($offset, $length)
53
    {
54
        $list = new LimitIterator(
55
            $this->iterator,
56
            $offset,
57
            $length
58
        );
59
        $result = [];
60
        try {
61
            foreach ($list as $file) {
62
                /** @var SplFileInfo $file */
63
                $result[] = $this->dataLayer->retrieve($this->resourceClass, $file->getBasename(), $this->context);
64
65
            }
66
        } catch (OutOfBoundsException $outOfBoundsException) {
67
            $outOfBoundsException->getMessage(); // ignore
68
        }
69
        return $result;
70
    }
71
}
72