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

ArticleMediaAssetProvider   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getImage() 0 4 1
A getFile() 0 4 1
A getArticleMediaId() 0 4 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