Completed
Push — master ( 81acf3...241a18 )
by
unknown
60:32 queued 45:22
created

ThumbnailChainStrategy   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 26
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getThumbnail() 0 12 3
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
declare(strict_types=1);
8
9
namespace eZ\Publish\Core\Repository\Strategy\ContentThumbnail;
10
11
use eZ\Publish\API\Repository\Values\Content\Thumbnail;
12
use eZ\Publish\API\Repository\Values\ContentType\ContentType;
13
use eZ\Publish\SPI\Repository\Strategy\ContentThumbnail\ThumbnailStrategy;
14
15
final class ThumbnailChainStrategy implements ThumbnailStrategy
16
{
17
    /** @var \eZ\Publish\SPI\Repository\Strategy\ContentThumbnail\ThumbnailStrategy[] */
18
    private $strategies;
19
20
    /**
21
     * @param \eZ\Publish\SPI\Repository\Strategy\ContentThumbnail\ThumbnailStrategy[] $strategies
22
     */
23
    public function __construct(iterable $strategies)
24
    {
25
        $this->strategies = $strategies;
26
    }
27
28
    public function getThumbnail(ContentType $contentType, array $fields): ?Thumbnail
29
    {
30
        foreach ($this->strategies as $strategy) {
31
            $thumbnail = $strategy->getThumbnail($contentType, $fields);
32
33
            if ($thumbnail !== null) {
34
                return $thumbnail;
35
            }
36
        }
37
38
        return null;
39
    }
40
}
41