Completed
Push — drop-container-aware-command ( 55eeca )
by Christian
02:20
created

CreateProfileCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 0
cts 8
cp 0
rs 9.9
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
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 since 1.5
24
 */
25
class CreateProfileCommand extends CloudCommand
26
{
27
    protected static $defaultName = 'panda:profile:create';
28
29
    /**
30
     * {@inheritDoc}
31
     */
32
    protected function configure()
33
    {
34
        $this->setDescription('Create a profile based on a given preset');
35
        $this->addArgument(
36
        'preset',
37
            InputArgument::REQUIRED,
38
            'Name of the preset to use'
39
        );
40
41
        parent::configure();
42
    }
43
44
    /**
45
     * {@inheritDoc}
46
     */
47
    protected function doExecuteCommand(InputInterface $input, OutputInterface $output)
48
    {
49
        $cloud = $this->getCloud($input);
50
        $preset = $input->getArgument('preset');
51
        $profile = $cloud->addProfileFromPreset($preset);
0 ignored issues
show
Bug introduced by
It seems like $preset defined by $input->getArgument('preset') on line 50 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...
52
        $output->writeln(
53
            sprintf(
54
                '<info>Successfully created profile %s with id %s</info>',
55
                $profile->getName(),
56
                $profile->getId()
57
            )
58
        );
59
    }
60
}
61