Completed
Pull Request — master (#4433)
by Craig
04:27
created

MetaDataTranslatorHelper   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 41
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A translateMetaData() 0 14 4
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Zikula package.
7
 *
8
 * Copyright Zikula - https://ziku.la/
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Zikula\ExtensionsModule\Helper;
15
16
use Symfony\Contracts\Translation\TranslatorInterface;
17
use Zikula\Bundle\CoreBundle\Composer\MetaData;
18
use Zikula\Bundle\CoreBundle\HttpKernel\ZikulaKernel;
19
use Zikula\Bundle\CoreBundle\Translation\TranslatorTrait;
20
use Zikula\ExtensionsModule\Entity\Repository\ExtensionRepository;
21
use Zikula\ExtensionsModule\Entity\RepositoryInterface\ExtensionRepositoryInterface;
22
23
class MetaDataTranslatorHelper
24
{
25
    use TranslatorTrait;
26
27
    /**
28
     * @var ExtensionRepository
29
     */
30
    private $extensionRepository;
31
32
    /**
33
     * @var bool
34
     */
35
    private $installed;
36
37
    public function __construct(
38
        TranslatorInterface $translator,
39
        ExtensionRepositoryInterface $extensionRepository,
40
        string $installed
41
    ) {
42
        $this->setTranslator($translator);
43
        $this->extensionRepository = $extensionRepository;
0 ignored issues
show
Documentation Bug introduced by
$extensionRepository is of type Zikula\ExtensionsModule\...sionRepositoryInterface, but the property $extensionRepository was declared to be of type Zikula\ExtensionsModule\...ory\ExtensionRepository. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
44
        $this->installed = ZikulaKernel::VERSION === $installed;
45
    }
46
47
    /**
48
     * overwrite composer.json settings with dynamic values from extension repository
49
     */
50
    public function translateMetaData(MetaData $metaData): MetaData
51
    {
52
        if ($this->installed && isset($this->translator)) {
53
            $extensionEntity = $this->extensionRepository->get($metaData->getShortName());
54
            if (null !== $extensionEntity) {
55
                $metaData->setTranslator($this->translator);
56
                $metaData->setUrl($extensionEntity->getUrl());
57
                $metaData->setDisplayName($extensionEntity->getDisplayname());
58
                $metaData->setDescription($extensionEntity->getDescription());
59
                $metaData->setIcon($extensionEntity->getIcon());
60
            }
61
        }
62
63
        return $metaData;
64
    }
65
}
66