Completed
Push — ezp25946-migrate_files_to_othe... ( e1d3cb...7924de )
by
unknown
12:27
created

ImageFileLister::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
 * File containing the ImageFileLister class.
5
 *
6
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
7
 * @license For full copyright and license information view LICENSE file distributed with this source code.
8
 */
9
namespace eZ\Bundle\EzPublishIOBundle\Migration\FileLister;
10
11
use eZ\Bundle\EzPublishCoreBundle\Imagine\VariationPathGenerator;
12
use eZ\Bundle\EzPublishCoreBundle\Imagine\VariationPurger\ImageFileList;
13
use eZ\Bundle\EzPublishIOBundle\ApiLoader\HandlerFactory;
14
use eZ\Bundle\EzPublishIOBundle\Migration\FileListerInterface;
15
use eZ\Publish\Core\IO\IOServiceInterface;
16
use Iterator;
17
use Liip\ImagineBundle\Imagine\Filter\FilterConfiguration;
18
use LimitIterator;
19
use Psr\Log\LoggerInterface;
20
21
class ImageFileLister extends FileLister implements FileListerInterface
22
{
23
    /** @var ImageFileList */
24
    private $imageFileList;
25
26
    /** @var \eZ\Publish\Core\IO\IOServiceInterface */
27
    private $ioService;
28
29
    /** @var \eZ\Bundle\EzPublishCoreBundle\Imagine\VariationPathGenerator */
30
    private $variationPathGenerator;
31
32
    /** @var \Liip\ImagineBundle\Imagine\Filter\FilterConfiguration */
33
    private $filterConfiguration;
34
35
    public function __construct(
36
        HandlerFactory $metadataHandlerFactory,
37
        HandlerFactory $binarydataHandlerFactory,
38
        LoggerInterface $logger = null,
39
        Iterator $imageFileList,
40
        IOServiceInterface $ioService,
41
        VariationPathGenerator $variationPathGenerator,
42
        FilterConfiguration $filterConfiguration
43
    ) {
44
        $this->imageFileList = $imageFileList;
0 ignored issues
show
Documentation Bug introduced by
$imageFileList is of type object<Iterator>, but the property $imageFileList was declared to be of type object<eZ\Bundle\EzPubli...onPurger\ImageFileList>. 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...
45
        $this->ioService = $ioService;
46
        $this->variationPathGenerator = $variationPathGenerator;
47
        $this->filterConfiguration = $filterConfiguration;
48
49
        $this->imageFileList->rewind();
50
51
        parent::__construct($metadataHandlerFactory, $binarydataHandlerFactory, $logger);
52
    }
53
54
    public function countFiles()
55
    {
56
        return count($this->imageFileList);
57
    }
58
59
    public function loadMetadataList($limit = null, $offset = null)
60
    {
61
        $metadataList = [];
62
        $imageLimitList = new LimitIterator($this->imageFileList, $offset, $limit);
63
        $aliasNames = array_keys($this->filterConfiguration->all());
64
65
        foreach ($imageLimitList as $originalImageId) {
66
            $metadataList[] = $this->getSPIBinaryForMetadata([
67
                'path' => $originalImageId,
68
                'size' => null,
69
                'timestamp' => null,
70
            ]);
71
72
            foreach ($aliasNames as $aliasName) {
73
                $variationImageId = $this->variationPathGenerator->getVariationPath($originalImageId, $aliasName);
74
                if ($this->ioService->exists($variationImageId)) {
75
                    $metadataList[] = $this->getSPIBinaryForMetadata([
76
                        'path' => $variationImageId,
77
                        'size' => null,
78
                        'timestamp' => null,
79
                    ]);
80
                }
81
            }
82
        }
83
84
        return $metadataList;
85
    }
86
}
87