Passed
Push — main ( 7ab255...594771 )
by Axel
04:33
created

InitBundleCommand::execute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 2
dl 0
loc 11
rs 10
c 0
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\Bundle\CoreBundle\Command;
15
16
use InvalidArgumentException;
17
use Symfony\Component\Console\Command\Command;
18
use Symfony\Component\Console\Input\InputArgument;
19
use Symfony\Component\Console\Input\InputInterface;
20
use Symfony\Component\Console\Output\OutputInterface;
21
use Symfony\Component\HttpKernel\KernelInterface;
22
23
/**
24
 * Command that performs setup tasks for a given bundle implementing InitializableBundleInterface.
25
 */
26
class InitBundleCommand extends Command
27
{
28
    protected static $defaultName = 'zikula:init-bundle';
29
30
    public function __construct(private readonly KernelInterface $kernel)
31
    {
32
        parent::__construct();
33
    }
34
35
    protected function configure()
36
    {
37
        $this
38
            ->addArgument('bundle', InputArgument::REQUIRED, 'The bundle name')
39
            ->setDescription('Performs setup tasks for a given initializable bundle.')
40
            ->setHelp(
41
                <<<'EOT'
42
The <info>%command.name%</info> command performs setup tasks for a given bundle implementing <info>InitializableBundleInterface</info>.
43
44
<info>php %command.full_name% AcmeFooBundle</info>
45
46
EOT
47
            );
48
    }
49
50
    /**
51
     * @throws InvalidArgumentException When the bundle is not an initializable bundle
52
     */
53
    protected function execute(InputInterface $input, OutputInterface $output): int
54
    {
55
        $bundleName = $input->getArgument('bundle');
56
        $bundle = $kernel->getBundle($bundleName);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $kernel seems to be never defined.
Loading history...
57
        if (!($bundle instanceof InitializableBundleInterface)) {
0 ignored issues
show
Bug introduced by
The type Zikula\Bundle\CoreBundle...alizableBundleInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
58
            throw new InvalidArgumentException(sprintf('"%s" is not an initializable bundle.', $bundleName));
59
        }
60
61
        $bundle->getInitializer()->init();
62
63
        return Command::SUCCESS;
64
    }
65
}
66