QueueBuildCommand::configure()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 13
ccs 0
cts 13
cp 0
rs 9.4285
cc 1
eloc 9
nc 1
nop 0
crap 2
1
<?php
2
3
/**
4
 * Copyright 2014 Underground Elephant
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 *
18
 * @package     qpush-bundle
19
 * @copyright   Underground Elephant 2014
20
 * @license     Apache License, Version 2.0
21
 */
22
23
namespace Uecode\Bundle\QPushBundle\Command;
24
25
use Symfony\Component\Console\Command\Command;
26
use Symfony\Component\Console\Input\InputArgument;
27
use Symfony\Component\Console\Input\InputInterface;
28
use Symfony\Component\Console\Output\OutputInterface;
29
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
30
use Symfony\Component\DependencyInjection\ContainerInterface;
31
32
/**
33
 * @author Keith Kirk <[email protected]>
34
 */
35
class QueueBuildCommand extends Command implements ContainerAwareInterface
36
{
37
    /**
38
     * @var ContainerInterface
39
     *
40
     * @api
41
     */
42
    protected $container;
43
44
    /**
45
     * Sets the Container associated with this Controller.
46
     *
47
     * @param ContainerInterface $container A ContainerInterface instance
48
     *
49
     * @api
50
     */
51
    public function setContainer(ContainerInterface $container = null)
52
    {
53
        $this->container = $container;
54
    }
55
56
    protected $output;
57
58
    protected function configure()
59
    {
60
        $this
61
            ->setName('uecode:qpush:build')
62
            ->setDescription('Builds the configured Queues')
63
            ->addArgument(
64
                'name',
65
                InputArgument::OPTIONAL,
66
                'Name of a specific queue to build',
67
                null
68
            )
69
        ;
70
    }
71
72 View Code Duplication
    protected function execute(InputInterface $input, OutputInterface $output)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
73
    {
74
        $this->output = $output;
75
        $registry = $this->container->get('uecode_qpush');
76
77
        $name = $input->getArgument('name');
78
79
        if (null !== $name) {
80
            return $this->buildQueue($registry, $name);
81
        }
82
83
        foreach ($registry->all() as $queue) {
84
            $this->buildQueue($registry, $queue->getName());
85
        }
86
87
        return 0;
88
    }
89
90
    private function buildQueue($registry, $name)
91
    {
92
        if (!$registry->has($name)) {
93
            return $this->output->writeln(
94
                sprintf("The [%s] queue you have specified does not exists!", $name)
95
            );
96
        }
97
98
        $registry->get($name)->create();
99
        $this->output->writeln(sprintf("The %s queue has been built successfully.", $name));
100
101
        return 0;
102
    }
103
}
104