Completed
Push — ezp-30882-thumbnail ( 1223cf...3134e5 )
by
unknown
15:29
created

ThumbnailChainStrategy   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 33
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getThumbnail() 0 13 3
A setStrategies() 0 4 1
A addStrategy() 0 4 1
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
use Traversable;
15
16
final class ThumbnailChainStrategy implements ThumbnailStrategy
17
{
18
    protected $strategies = [];
19
20
    public function __construct(Traversable $strategies)
21
    {
22
        $this->setStrategies(iterator_to_array($strategies));
23
    }
24
25
    public function getThumbnail(ContentType $contentType, array $fields): ?Thumbnail
26
    {
27
        /** @var \eZ\Publish\SPI\Repository\Strategy\ContentThumbnail\ThumbnailStrategy $strategy */
28
        foreach ($this->strategies as $strategy) {
29
            $thumbnail = $strategy->getThumbnail($contentType, $fields);
30
31
            if ($thumbnail !== null) {
32
                return $thumbnail;
33
            }
34
        }
35
36
        return null;
37
    }
38
39
    public function setStrategies(array $strategies): void
40
    {
41
        $this->strategies = $strategies;
42
    }
43
44
    public function addStrategy(ThumbnailStrategy $strategy): void
45
    {
46
        $this->strategies[] = $strategy;
47
    }
48
}
49