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

MetaDataTranslatorHelper::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
nc 1
nop 3
dl 0
loc 8
rs 10
c 1
b 0
f 0
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\Translation\TranslatorTrait;
19
use Zikula\ExtensionsModule\Entity\Repository\ExtensionRepository;
20
use Zikula\ExtensionsModule\Entity\RepositoryInterface\ExtensionRepositoryInterface;
21
22
class MetaDataTranslatorHelper
23
{
24
    use TranslatorTrait;
25
26
    /**
27
     * @var ExtensionRepository
28
     */
29
    private $extensionRepository;
30
31
    /**
32
     * @var bool
33
     */
34
    private $installed;
35
36
    public function __construct(
37
        TranslatorInterface $translator,
38
        ExtensionRepositoryInterface $extensionRepository,
39
        string $installed
40
    ) {
41
        $this->setTranslator($translator);
42
        $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...
43
        $this->installed = '0.0.0' !== $installed;
44
    }
45
46
    /**
47
     * overwrite composer.json settings with dynamic values from extension repository
48
     */
49
    public function translateMetaData(MetaData $metaData): MetaData
50
    {
51
        if ($this->installed && isset($this->translator)) {
52
            $extensionEntity = $this->extensionRepository->get($metaData->getShortName());
53
            if (null !== $extensionEntity) {
54
                $metaData->setTranslator($this->translator);
55
                $metaData->setUrl($extensionEntity->getUrl());
56
                $metaData->setDisplayName($extensionEntity->getDisplayname());
57
                $metaData->setDescription($extensionEntity->getDescription());
58
                $metaData->setIcon($extensionEntity->getIcon());
59
            }
60
        }
61
62
        return $metaData;
63
    }
64
}
65