CreateProfileCommand::doExecuteCommand()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1.0008

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 9
cts 10
cp 0.9
rs 9.8333
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1.0008
1
<?php
2
3
/*
4
 * This file is part of the XabbuhPandaBundle package.
5
 *
6
 * (c) Christian Flothmann <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Xabbuh\PandaBundle\Command;
13
14
use Symfony\Component\Console\Input\InputArgument;
15
use Symfony\Component\Console\Input\InputInterface;
16
use Symfony\Component\Console\Output\OutputInterface;
17
18
/**
19
 * Command to create a profile based on a preset.
20
 *
21
 * @author Christian Flothmann <[email protected]>
22
 */
23
final class CreateProfileCommand extends CloudCommand
24
{
25
    protected static $defaultName = 'panda:profile:create';
26
27
    /**
28
     * {@inheritDoc}
29
     */
30 5
    protected function configure()
31
    {
32 5
        $this->setDescription('Create a profile based on a given preset');
33 5
        $this->addArgument(
34 5
        'preset',
35 5
            InputArgument::REQUIRED,
36 5
            'Name of the preset to use'
37
        );
38
39 5
        parent::configure();
40 5
    }
41
42
    /**
43
     * {@inheritDoc}
44
     */
45 3
    protected function doExecuteCommand(InputInterface $input, OutputInterface $output)
46
    {
47 3
        $cloud = $this->getCloud($input);
48 3
        $preset = $input->getArgument('preset');
49 3
        $profile = $cloud->addProfileFromPreset($preset);
0 ignored issues
show
Bug introduced by
It seems like $preset defined by $input->getArgument('preset') on line 48 can also be of type array<integer,string> or null; however, Xabbuh\PandaClient\Api\C...:addProfileFromPreset() 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...
50 1
        $output->writeln(
51
            sprintf(
52 1
                '<info>Successfully created profile %s with id %s</info>',
53 1
                $profile->getName(),
54 1
                $profile->getId()
55
            )
56
        );
57 1
    }
58
}
59