Completed
Push — 1.4 ( f8c621...762927 )
by Rafał
22:37 queued 11:18
created

ArticleMediaAssetProvider::getArticleMediaId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Superdesk Web Publisher Content Bundle.
7
 *
8
 * Copyright 2018 Sourcefabric z.ú. and contributors.
9
 *
10
 * For the full copyright and license information, please see the
11
 * AUTHORS and LICENSE files distributed with this source code.
12
 *
13
 * @copyright 2018 Sourcefabric z.ú
14
 * @license http://www.superdesk.org/license
15
 */
16
17
namespace SWP\Bundle\ContentBundle\Provider\ORM;
18
19
use SWP\Bundle\ContentBundle\Doctrine\FileRepositoryInterface;
20
use SWP\Bundle\ContentBundle\Doctrine\ImageRepositoryInterface;
21
use SWP\Bundle\ContentBundle\Model\ArticleMedia;
22
use SWP\Bundle\ContentBundle\Model\FileInterface;
23
use SWP\Bundle\ContentBundle\Model\ImageInterface;
24
use SWP\Component\Bridge\Model\RenditionInterface;
25
26
class ArticleMediaAssetProvider implements ArticleMediaAssetProviderInterface
27
{
28
    /**
29
     * @var ImageRepositoryInterface
30
     */
31
    private $imageRepository;
32
33
    /**
34
     * @var FileRepositoryInterface
35
     */
36
    private $fileRepository;
37
38
    public function __construct(ImageRepositoryInterface $imageRepository, FileRepositoryInterface $fileRepository)
39
    {
40
        $this->imageRepository = $imageRepository;
41
        $this->fileRepository = $fileRepository;
42
    }
43
44
    public function getImage(RenditionInterface $rendition): ?ImageInterface
45
    {
46
        return  $this->imageRepository->findImageByAssetId($this->getArticleMediaId($rendition));
47
    }
48
49
    public function getFile(RenditionInterface $rendition): ?FileInterface
50
    {
51
        return $this->fileRepository->findFileByAssetId($this->getArticleMediaId($rendition));
52
    }
53
54
    private function getArticleMediaId(RenditionInterface $rendition): string
55
    {
56
        return ArticleMedia::handleMediaId($rendition->getMedia());
57
    }
58
}
59