Passed
Push — master ( c86b81...7621ad )
by Valentin
04:59 queued 02:13
created

DeleteWorkflowCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 8
ccs 6
cts 6
cp 1
crap 1
rs 10
1
<?php
2
3
namespace Pyrowman\PheanstalkBundle\Command;
4
5
use Doctrine\Common\Collections\ArrayCollection;
6
use Pheanstalk\Exception;
7
use Pheanstalk\Structure\Workflow;
8
use Symfony\Component\Console\Input\InputArgument;
9
use Symfony\Component\Console\Input\InputInterface;
10
use Symfony\Component\Console\Output\OutputInterface;
11
12
class DeleteWorkflowCommand extends AbstractPheanstalkCommand
13
{
14
    /**
15
     * @inheritdoc
16
     */
17 4
    protected function configure()
18
    {
19
        $this
20 4
            ->setName('pyrowman:pheanstalk:delete-workflow')
21 4
            ->addArgument('name', InputArgument::REQUIRED, 'Workflow name to delete.')
22 4
            ->addArgument('group', InputArgument::REQUIRED, 'Workflow group to delete.')
23 4
            ->addArgument('pheanstalk', InputArgument::OPTIONAL, 'Pheanstalk name.')
24 4
            ->setDescription('Delete the specified workflow if it exists.');
25
    }
26
27
    /**
28
     * @inheritdoc
29
     */
30 4
    protected function execute(InputInterface $input, OutputInterface $output)
31
    {
32 4
        $workflowName       = $input->getArgument('name');
33 4
        $workflowGroup      = $input->getArgument('group');
34 4
        $name       = $input->getArgument('pheanstalk');
35 4
        $pheanstalk = $this->getPheanstalk($name);
0 ignored issues
show
Bug introduced by
It seems like $name can also be of type string[]; however, parameter $name of Pyrowman\PheanstalkBundl...ommand::getPheanstalk() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

35
        $pheanstalk = $this->getPheanstalk(/** @scrutinizer ignore-type */ $name);
Loading history...
36
37
        try {
38 2
            $workflow = new Workflow($workflowName, $workflowGroup, new ArrayCollection([]));
0 ignored issues
show
Bug introduced by
It seems like $workflowName can also be of type null and string[]; however, parameter $name of Pheanstalk\Structure\Workflow::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

38
            $workflow = new Workflow(/** @scrutinizer ignore-type */ $workflowName, $workflowGroup, new ArrayCollection([]));
Loading history...
Bug introduced by
It seems like $workflowGroup can also be of type null and string[]; however, parameter $group of Pheanstalk\Structure\Workflow::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

38
            $workflow = new Workflow($workflowName, /** @scrutinizer ignore-type */ $workflowGroup, new ArrayCollection([]));
Loading history...
39 2
            $pheanstalk->delete($workflow);
40
41 1
            $output->writeln("Pheanstalk: <info>$name</info>");
42 1
            $output->writeln("Workflow <info>$workflowName</info> deleted.");
43
44 1
            return 0;
45 1
        } catch (Exception $e) {
46 1
            $output->writeln("Pheanstalk: <info>$name</info>");
47 1
            $output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
48
49 1
            return 1;
50
        }
51
    }
52
}
53