InitBundleCommand::execute()   A
last analyzed

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\CoreBundle\Command;
15
16
use InvalidArgumentException;
17
use Symfony\Component\Console\Attribute\AsCommand;
18
use Symfony\Component\Console\Command\Command;
19
use Symfony\Component\Console\Input\InputArgument;
20
use Symfony\Component\Console\Input\InputInterface;
21
use Symfony\Component\Console\Output\OutputInterface;
22
use Symfony\Component\HttpKernel\KernelInterface;
23
24
/**
25
 * Command that performs setup tasks for a given bundle implementing InitializableBundleInterface.
26
 */
27
#[AsCommand(name: 'zikula:init-bundle', description: 'Performs setup tasks for a given initializable bundle.')]
28
class InitBundleCommand extends Command
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
            ->setHelp(
40
                <<<'EOT'
41
The <info>%command.name%</info> command performs setup tasks for a given bundle implementing <info>InitializableBundleInterface</info>.
42
43
<info>php %command.full_name% AcmeFooBundle</info>
44
45
EOT
46
            );
47
    }
48
49
    /**
50
     * @throws InvalidArgumentException When the bundle is not an initializable bundle
51
     */
52
    protected function execute(InputInterface $input, OutputInterface $output): int
53
    {
54
        $bundleName = $input->getArgument('bundle');
55
        $bundle = $kernel->getBundle($bundleName);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $kernel seems to be never defined.
Loading history...
56
        if (!($bundle instanceof InitializableBundleInterface)) {
0 ignored issues
show
Bug introduced by
The type Zikula\CoreBundle\Comman...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...
57
            throw new InvalidArgumentException(sprintf('"%s" is not an initializable bundle.', $bundleName));
58
        }
59
60
        $bundle->getInitializer()->init();
61
62
        return Command::SUCCESS;
63
    }
64
}
65