GearmanWorkerListCommand::execute()   B
last analyzed

Complexity

Conditions 6
Paths 6

Size

Total Lines 30

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 6.0073

Importance

Changes 0
Metric Value
dl 0
loc 30
ccs 16
cts 17
cp 0.9412
rs 8.8177
c 0
b 0
f 0
cc 6
nc 6
nop 2
crap 6.0073
1
<?php
2
3
/**
4
 * Gearman Bundle for Symfony2 / Symfony3
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 *
9
 * Feel free to edit as you please, and have fun.
10
 *
11
 * @author Marc Morera <[email protected]>
12
 * @author Mickael Perraud <[email protected]>
13
 */
14
15
namespace Mkk\GearmanBundle\Command;
16
17
use Symfony\Component\Console\Input\InputInterface;
18
use Symfony\Component\Console\Output\OutputInterface;
19
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
20
21
/**
22
 * Gearman Job List Command class
23
 */
24
class GearmanWorkerListCommand extends ContainerAwareCommand
25
{
26
    /**
27
     * Console Command configuration
28
     */
29 16
    protected function configure()
30
    {
31 16
        parent::configure();
32
33
        $this
34 16
            ->setName('gearman:worker:list')
35 16
            ->setDescription('List all Gearman Workers and their Jobs');
36 16
    }
37
38
    /**
39
     * Executes the current command.
40
     *
41
     * @param InputInterface  $input  An InputInterface instance
42
     * @param OutputInterface $output An OutputInterface instance
43
     *
44
     * @return integer 0 if everything went fine, or an error code
0 ignored issues
show
Documentation introduced by
Should the return type not be integer|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
45
     *
46
     * @throws \LogicException When this abstract class is not implemented
47
     */
48 2
    protected function execute(InputInterface $input, OutputInterface $output)
49
    {
50 2
        if ($input->getOption('quiet')) {
51
            return;
52
        }
53
54 2
        $workers = $this->getContainer()->get('gearman')->getWorkers();
55
56 2
        if (is_array($workers)) {
57
58 2
            $it = 1;
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $it. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
59
60 2
            foreach ($workers as $worker) {
61
62 1
                $output->writeln('<comment>@Worker:  </comment><info>' . $worker['className'] . '</info>');
63 1
                $output->writeln('<comment>callablename:  </comment><info>' . $worker['callableName'] . '</info>');
64 1
                $output->writeln('<comment>Jobs:</comment>');
65 1
                foreach ($worker['jobs'] as $job) {
66 1
                    $output->writeln('<comment>  - #' . $it++ . '</comment>');
67 1
                    $output->writeln('<comment>      name: ' . $job['methodName'] . '</comment>');
68 1
                    $output->writeln('<comment>      callablename:</comment><info> ' . $job['realCallableNameNoPrefix'] . '</info>');
69
70 1
                    if (false === is_null($job['jobPrefix'])) {
71
72 1
                        $output->writeln('<comment>      jobPrefix:</comment><info> ' . $job['jobPrefix'] . '</info>');
73
                    }
74
                }
75
            }
76
        }
77 2
    }
78
}
79