Completed
Push — master ( 05bb5a...5289b8 )
by Rafał
34:32 queued 04:15
created

EmbeddedImageProcessor::processImageElement()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 3
1
<?php
2
3
/*
4
 * This file is part of the Superdesk Web Publisher Core Bundle.
5
 *
6
 * Copyright 2019 Sourcefabric z.ú. and contributors.
7
 *
8
 * For the full copyright and license information, please see the
9
 * AUTHORS and LICENSE files distributed with this source code.
10
 *
11
 * @copyright 2019 Sourcefabric z.ú
12
 * @license http://www.superdesk.org/license
13
 */
14
15
namespace SWP\Bundle\CoreBundle\Processor;
16
17
use SWP\Bundle\ContentBundle\File\FileExtensionCheckerInterface;
18
use SWP\Bundle\ContentBundle\Manager\MediaManagerInterface;
19
use SWP\Bundle\ContentBundle\Model\ArticleMediaInterface;
20
use SWP\Bundle\ContentBundle\Model\ImageRendition;
21
use SWP\Bundle\ContentBundle\Processor\EmbeddedImageProcessor as BaseEmbeddedImageProcessor;
22
use SWP\Bundle\CoreBundle\Context\ArticlePreviewContextInterface;
23
use SWP\Bundle\SettingsBundle\Manager\SettingsManagerInterface;
24
use SWP\Component\MultiTenancy\Context\TenantContextInterface;
25
26
final class EmbeddedImageProcessor extends BaseEmbeddedImageProcessor
27
{
28
    /**
29
     * @var ArticlePreviewContextInterface
30
     */
31
    private $articlePreviewContext;
32
33
    /**
34
     * @var SettingsManagerInterface
35
     */
36
    private $settingsManager;
37
38
    /**
39
     * @var TenantContextInterface
40
     */
41
    private $tenantContext;
42
43
    public function __construct(
44
        MediaManagerInterface $mediaManager,
45
        FileExtensionCheckerInterface $fileExtensionChecker,
46
        ArticlePreviewContextInterface $articlePreviewContext,
47
        SettingsManagerInterface $settingsManager,
48
        TenantContextInterface $tenantContext
49
    ) {
50
        parent::__construct($mediaManager, $fileExtensionChecker);
51
        $this->articlePreviewContext = $articlePreviewContext;
52
        $this->settingsManager = $settingsManager;
53
        $this->tenantContext = $tenantContext;
54
    }
55
56
    protected function processImageElement(\DOMElement $imageElement, ImageRendition $rendition, string $mediaId): void
57
    {
58
        parent::processImageElement($imageElement, $rendition, $mediaId);
59
60
        if ($this->articlePreviewContext->isPreview()) {
61
            $imageElement->setAttribute('src', $rendition->getPreviewUrl());
62
        }
63
    }
64
65
    public function applyByline(ArticleMediaInterface $articleMedia): string
66
    {
67
        $imageAuthorTemplate = $this->settingsManager->get('embedded_image_author_template', 'tenant', $this->tenantContext->getTenant());
0 ignored issues
show
Documentation introduced by
$this->tenantContext->getTenant() is of type object<SWP\Component\Mul...\Model\TenantInterface>, but the function expects a null|object<SWP\Bundle\S...SettingsOwnerInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
68
69
        if (null === ($byline = $articleMedia->getByLine())) {
70
            return '';
71
        }
72
73
        return str_replace('{{ author }}', $byline, $imageAuthorTemplate);
74
    }
75
}
76