Completed
Push — master ( 355f41...200862 )
by Mickael
06:25
created

GearmanWorkerListCommand::execute()   B

Complexity

Conditions 6
Paths 6

Size

Total Lines 30
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 6.4689

Importance

Changes 0
Metric Value
dl 0
loc 30
ccs 13
cts 17
cp 0.7647
rs 8.439
c 0
b 0
f 0
cc 6
eloc 16
nc 6
nop 2
crap 6.4689
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
 */
13
14
namespace Mkk\GearmanBundle\Command;
15
16
use Symfony\Component\Console\Input\InputInterface;
17
use Symfony\Component\Console\Output\OutputInterface;
18
use Mkk\GearmanBundle\Command\Abstracts\AbstractGearmanCommand;
19
use Mkk\GearmanBundle\Service\GearmanClient;
20
21
/**
22
 * Gearman Job List Command class
23
 */
24
class GearmanWorkerListCommand extends AbstractGearmanCommand
25
{
26
    /**
27
     * @var GearmanClient
28
     *
29
     * Gearman client
30
     */
31
    protected $gearmanClient;
32
33
    /**
34
     * Set gearman client
35
     *
36
     * @param GearmanClient $gearmanClient Gearman client
37
     *
38
     * @return GearmanWorkerListCommand self Object
39
     */
40 2
    public function setGearmanClient(GearmanClient $gearmanClient)
41
    {
42 2
        $this->gearmanClient = $gearmanClient;
43
44 2
        return $this;
45
    }
46
47
    /**
48
     * Console Command configuration
49
     */
50 2
    protected function configure()
51
    {
52 2
        parent::configure();
53
54
        $this
55 2
            ->setName('gearman:worker:list')
56 2
            ->setDescription('List all Gearman Workers and their Jobs');
57 2
    }
58
59
    /**
60
     * Executes the current command.
61
     *
62
     * @param InputInterface  $input  An InputInterface instance
63
     * @param OutputInterface $output An OutputInterface instance
64
     *
65
     * @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...
66
     *
67
     * @throws \LogicException When this abstract class is not implemented
68
     */
69 2
    protected function execute(InputInterface $input, OutputInterface $output)
70
    {
71 2
        if ($input->getOption('quiet')) {
72 1
            return;
73
        }
74
75 1
        $workers = $this->gearmanClient->getWorkers();
76
77 1
        if (is_array($workers)) {
78
79 1
            $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...
80
81 1
            foreach ($workers as $worker) {
82
83 1
                $output->writeln('<comment>@Worker:  </comment><info>' . $worker['className'] . '</info>');
84 1
                $output->writeln('<comment>callablename:  </comment><info>' . $worker['callableName'] . '</info>');
85 1
                $output->writeln('<comment>Jobs:</comment>');
86 1
                foreach ($worker['jobs'] as $job) {
87
                    $output->writeln('<comment>  - #' . $it++ . '</comment>');
0 ignored issues
show
Coding Style introduced by
Increment and decrement operators must be bracketed when used in string concatenation
Loading history...
88
                    $output->writeln('<comment>      name: ' . $job['methodName'] . '</comment>');
89
                    $output->writeln('<comment>      callablename:</comment><info> ' . $job['realCallableNameNoPrefix'] . '</info>');
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 133 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
90
91
                    if (false === is_null($job['jobPrefix'])) {
92
93 1
                        $output->writeln('<comment>      jobPrefix:</comment><info> ' . $job['jobPrefix'] . '</info>');
94
                    }
95
                }
96
            }
97
        }
98 1
    }
99
}
0 ignored issues
show
Coding Style introduced by
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
100