Completed
Push — 6.7 ( caaa8b...485307 )
by
unknown
19:19
created

BinaryFileLister::countFiles()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
5
 * @license For full copyright and license information view LICENSE file distributed with this source code.
6
 */
7
namespace eZ\Bundle\EzPublishIOBundle\Migration\FileLister;
8
9
use eZ\Bundle\EzPublishIOBundle\ApiLoader\HandlerFactory;
10
use eZ\Bundle\EzPublishIOBundle\Migration\FileListerInterface;
11
use eZ\Bundle\EzPublishIOBundle\Migration\MigrationHandler;
12
use eZ\Publish\Core\IO\Exception\BinaryFileNotFoundException;
13
use Iterator;
14
use LimitIterator;
15
use Psr\Log\LoggerInterface;
16
17
class BinaryFileLister extends MigrationHandler implements FileListerInterface
18
{
19
    /** @var \eZ\Bundle\EzPublishIOBundle\Migration\FileLister\FileIteratorInterface */
20
    private $fileList;
21
22
    /** @var string Directory where files are stored, within the storage dir. Example: 'original' */
23
    private $filesDir;
24
25
    /**
26
     * @param \eZ\Bundle\EzPublishIOBundle\ApiLoader\HandlerFactory $metadataHandlerFactory
27
     * @param \eZ\Bundle\EzPublishIOBundle\ApiLoader\HandlerFactory $binarydataHandlerFactory
28
     * @param \Psr\Log\LoggerInterface $logger
29
     * @param \Iterator $fileList
30
     * @param string $filesDir Directory where files are stored, within the storage dir. Example: 'original'
31
     */
32
    public function __construct(
33
        HandlerFactory $metadataHandlerFactory,
34
        HandlerFactory $binarydataHandlerFactory,
35
        LoggerInterface $logger = null,
36
        Iterator $fileList,
37
        $filesDir
38
    ) {
39
        $this->fileList = $fileList;
0 ignored issues
show
Documentation Bug introduced by
$fileList is of type object<Iterator>, but the property $fileList was declared to be of type object<eZ\Bundle\EzPubli...\FileIteratorInterface>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
40
        $this->filesDir = $filesDir;
41
42
        $this->fileList->rewind();
43
44
        parent::__construct($metadataHandlerFactory, $binarydataHandlerFactory, $logger);
45
    }
46
47
    public function countFiles()
48
    {
49
        return count($this->fileList);
50
    }
51
52
    public function loadMetadataList($limit = null, $offset = null)
53
    {
54
        $metadataList = [];
55
        $fileLimitList = new LimitIterator($this->fileList, $offset, $limit);
56
57
        foreach ($fileLimitList as $fileId) {
58
            try {
59
                $metadataList[] = $this->fromMetadataHandler->load($this->filesDir . '/' . $fileId);
60
            } catch (BinaryFileNotFoundException $e) {
61
                $this->logMissingFile($fileId);
62
63
                continue;
64
            }
65
        }
66
67
        return $metadataList;
68
    }
69
}
70