Completed
Push — master ( e48710...5fe26c )
by Rafał
40:26 queued 26:25
created

SeoImageUploader::handleUpload()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 29

Duplication

Lines 24
Ratio 82.76 %

Importance

Changes 0
Metric Value
dl 24
loc 29
rs 9.456
c 0
b 0
f 0
cc 4
nc 8
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Superdesk Web Publisher Core Bundle.
7
 *
8
 * Copyright 2019 Sourcefabric z.u. 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 2019 Sourcefabric z.ú
14
 * @license http://www.superdesk.org/license
15
 */
16
17
namespace SWP\Bundle\CoreBundle\Service;
18
19
use SWP\Bundle\ContentBundle\Manager\MediaManagerInterface;
20
use SWP\Bundle\ContentBundle\Model\ArticleSeoMediaInterface;
21
use SWP\Bundle\ContentBundle\Model\ArticleSeoMetadataInterface;
22
use SWP\Component\Common\Generator\GeneratorInterface;
23
use SWP\Component\Storage\Factory\FactoryInterface;
24
25
class SeoImageUploader implements SeoImageUploaderInterface
26
{
27
    private $randomStringGenerator;
28
29
    private $mediaManager;
30
31
    private $factory;
32
33
    public function __construct(GeneratorInterface $randomStringGenerator, MediaManagerInterface $mediaManager, FactoryInterface $factory)
34
    {
35
        $this->randomStringGenerator = $randomStringGenerator;
36
        $this->mediaManager = $mediaManager;
37
        $this->factory = $factory;
38
    }
39
40
    public function handleUpload(ArticleSeoMetadataInterface $seoMetadata): void
41
    {
42 View Code Duplication
        if (null !== ($file = $seoMetadata->getMetaMediaFile())) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
43
            $image = $this->mediaManager->handleUploadedFile($file, $this->randomStringGenerator->generate(15));
44
            $seoImageMedia = $this->factory->create();
45
            $seoImageMedia->setKey(ArticleSeoMediaInterface::MEDIA_META_KEY);
46
            $seoImageMedia->setImage($image);
47
48
            $seoMetadata->setMetaMedia($seoImageMedia);
0 ignored issues
show
Bug introduced by
The method setMetaMedia() does not exist on SWP\Bundle\ContentBundle...cleSeoMetadataInterface. Did you maybe mean setMetaMediaFile()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
49
        }
50
51 View Code Duplication
        if (null !== ($file = $seoMetadata->getOgMediaFile())) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
52
            $image = $this->mediaManager->handleUploadedFile($file, $this->randomStringGenerator->generate(15));
53
            $seoImageMedia = $this->factory->create();
54
            $seoImageMedia->setKey(ArticleSeoMediaInterface::MEDIA_OG_KEY);
55
            $seoImageMedia->setImage($image);
56
57
            $seoMetadata->setOgMedia($seoImageMedia);
0 ignored issues
show
Bug introduced by
The method setOgMedia() does not exist on SWP\Bundle\ContentBundle...cleSeoMetadataInterface. Did you maybe mean setOgMediaFile()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
58
        }
59
60 View Code Duplication
        if (null !== ($file = $seoMetadata->getTwitterMediaFile())) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
61
            $image = $this->mediaManager->handleUploadedFile($file, $this->randomStringGenerator->generate(15));
62
            $seoImageMedia = $this->factory->create();
63
            $seoImageMedia->setKey(ArticleSeoMediaInterface::MEDIA_TWITTER_KEY);
64
            $seoImageMedia->setImage($image);
65
66
            $seoMetadata->setTwitterMedia($seoImageMedia);
0 ignored issues
show
Bug introduced by
The method setTwitterMedia() does not exist on SWP\Bundle\ContentBundle...cleSeoMetadataInterface. Did you maybe mean setTwitterMediaFile()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
67
        }
68
    }
69
}
70