Completed
Push — master ( 8784f3...9e63c5 )
by Peter
13:05
created

PeekCommand   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 63
Duplicated Lines 15.87 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 7
c 1
b 0
f 1
lcom 1
cbo 6
dl 10
loc 63
ccs 0
cts 38
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A configure() 10 10 1
B execute() 0 28 5

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace TreeHouse\WorkerBundle\Command;
4
5
use Symfony\Component\Console\Command\Command;
6
use Symfony\Component\Console\Helper\Table;
7
use Symfony\Component\Console\Input\InputArgument;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Input\InputOption;
10
use Symfony\Component\Console\Output\OutputInterface;
11
use TreeHouse\WorkerBundle\QueueManager;
12
13
class PeekCommand extends Command
14
{
15
    /**
16
     * @var QueueManager
17
     */
18
    protected $manager;
19
20
    /**
21
     * @param QueueManager $queueManager
22
     */
23
    public function __construct(QueueManager $queueManager)
24
    {
25
        $this->manager = $queueManager;
26
27
        parent::__construct();
28
    }
29
30
    /**
31
     * @inheritdoc
32
     */
33 View Code Duplication
    protected function configure()
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...
34
    {
35
        $this
36
            ->setName('worker:peek')
37
            ->addArgument('action', InputArgument::OPTIONAL | InputArgument::IS_ARRAY, 'Selects which actions to peek for. Defaults to all actions')
38
            ->addOption('state', null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'The state of job to peek for. Valid options are <comment>ready</comment>, <comment>delayed</comment> and <comment>buried</comment>.', ['ready'])
39
            ->setDescription('Peeks the next job from the queue')
40
            ->setHelp('Inspects the next job from the queue for one or more actions. Note that this does not reserve the job, so it will still be given to a worker if/once it\'s ready.')
41
        ;
42
    }
43
44
    /**
45
     * @inheritdoc
46
     */
47
    protected function execute(InputInterface $input, OutputInterface $output)
48
    {
49
        $actions = $input->getArgument('action');
50
        if (empty($actions)) {
51
            $actions = array_keys($this->manager->getExecutors());
52
        }
53
54
        $states = $input->getOption('state');
55
56
        foreach ($actions as $action) {
57
            $output->writeln(sprintf('Action: <info>%s</info>', $action));
58
59
            $table = new Table($output);
60
            $table->setHeaders(['state', 'id', 'data']);
61
            foreach ($states as $state) {
62
                $job = $this->manager->peek($action, $state);
63
64
                if (is_null($job)) {
65
                    $table->addRow([$state, '-', '-']);
66
                } else {
67
                    $table->addRow([$state, $job->getId(), $job->getData()]);
68
                }
69
            }
70
71
            $table->render();
72
            $output->writeln('');
73
        }
74
    }
75
}
76