Completed
Push — config_debug_commands ( 541e55...c862e0 )
by André
34:11 queued 09:30
created

DebugServiceCommand::execute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 2
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
5
 * @license For full copyright and license information view LICENSE file distributed with this source code.
6
 */
7
namespace eZ\Bundle\EzPublishCoreBundle\Command;
8
9
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
10
use Symfony\Component\Console\Input\InputArgument;
11
use Symfony\Component\Console\Input\InputInterface;
12
use Symfony\Component\Console\Input\InputOption;
13
use Symfony\Component\Console\Output\OutputInterface;
14
15
class DebugServiceCommand extends ContainerAwareCommand
16
{
17
    /**
18
     * {@inheritdoc}.
19
     */
20
    public function configure()
21
    {
22
        $this->setName('ezplatform:debug:service');
23
        $this->setDescription('Debug / Retrive class name of a service');
24
        $this->addArgument(
25
            'service',
26
            InputArgument::REQUIRED,
27
            'The service to return class name for, for instance "ezpublish.cache_pool"'
28
        );
29
        $this->addOption(
30
            'oneline',
31
            'o',
32
            InputOption::VALUE_NONE,
33
            'Only return value, for automation / testing use on a single line.'
34
        );
35
        $this->setHelp(<<<EOM
36
Outputs a given service class name.
37
38
To rather see service definition, use: <comment>debug:container ezpublish.cache_pool</comment>
39
40
EOM
41
        );
42
    }
43
44
    /**
45
     * {@inheritdoc}.
46
     */
47
    protected function execute(InputInterface $input, OutputInterface $output)
48
    {
49
        $service = $input->getArgument('service');
50
        $className = get_class($this->getContainer()->get($service));
0 ignored issues
show
Bug introduced by
It seems like $service defined by $input->getArgument('service') on line 49 can also be of type array<integer,string> or null; however, Symfony\Component\Depend...ntainerInterface::get() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
51
        if ($input->getOption('oneline')) {
52
            $output->write($className);
53
        } else {
54
            $output->writeln("<comment>Class name:</> ".$className);
55
        }
56
    }
57
}
58