Completed
Pull Request — master (#4433)
by Craig
05:37 queued 23s
created

MetaDataHelper::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 6
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 Zikula\Bundle\CoreBundle\Composer\MetaData;
17
use Zikula\Bundle\CoreBundle\HttpKernel\ZikulaKernel;
18
use Zikula\ExtensionsModule\Entity\Repository\ExtensionRepository;
19
use Zikula\ExtensionsModule\Entity\RepositoryInterface\ExtensionRepositoryInterface;
20
21
class MetaDataHelper
22
{
23
    /**
24
     * @var ExtensionRepository
25
     */
26
    private $extensionRepository;
27
28
    /**
29
     * @var bool
30
     */
31
    private $installed;
32
33
    public function __construct(
34
        ExtensionRepositoryInterface $extensionRepository,
35
        string $installed
36
    ) {
37
        $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...
38
        $this->installed = ZikulaKernel::VERSION === $installed;
39
    }
40
41
    /**
42
     * overwrite composer.json settings with dynamic values from extension repository
43
     */
44
    public function setDynamicMetaData(MetaData $metaData): MetaData
45
    {
46
        if ($this->installed) {
47
            $extensionEntity = $this->extensionRepository->get($metaData->getShortName());
48
            if (null !== $extensionEntity) {
49
                $metaData->setUrl($extensionEntity->getUrl());
50
                $metaData->setDisplayName($extensionEntity->getDisplayname());
51
                $metaData->setDescription($extensionEntity->getDescription());
52
                $metaData->setIcon($extensionEntity->getIcon());
53
            }
54
        }
55
56
        return $metaData;
57
    }
58
}
59