Completed
Push — master ( 0585fd...6ce168 )
by Mickael
03:38
created

GearmanJobExecuteCommand   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 121
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 6
dl 0
loc 121
ccs 0
cts 84
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B configure() 0 35 1
B execute() 0 61 7
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\Helper\QuestionHelper;
18
use Symfony\Component\Console\Input\InputArgument;
19
use Symfony\Component\Console\Input\InputInterface;
20
use Symfony\Component\Console\Input\InputOption;
21
use Symfony\Component\Console\Output\OutputInterface;
22
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
23
use Symfony\Component\Console\Question\ConfirmationQuestion;
24
25
/**
26
 * Gearman Job Execute Command class
27
 */
28
class GearmanJobExecuteCommand extends ContainerAwareCommand
29
{
30
31
    /**
32
     * @var QuestionHelper
33
     *
34
     * Question
35
     */
36
    protected $question;
37
38
    /**
39
     * Console Command configuration
40
     */
41
    protected function configure()
42
    {
43
        $this
44
            ->setName('gearman:job:execute')
45
            ->setDescription('Execute one single job')
46
            ->addArgument(
47
                'job',
48
                InputArgument::REQUIRED,
49
                'job to execute'
50
            )
51
            ->addOption(
52
                'no-description',
53
                null,
54
                InputOption::VALUE_NONE,
55
                'Don\'t print job description'
56
            )
57
            ->addOption(
58
                'iterations',
59
                null,
60
                InputOption::VALUE_OPTIONAL,
61
                'Override configured iterations'
62
            )
63
            ->addOption(
64
                'minimum-execution-time',
65
                null,
66
                InputOption::VALUE_OPTIONAL,
67
                'Override configured minimum execution time'
68
            )
69
            ->addOption(
70
                'timeout',
71
                null,
72
                InputOption::VALUE_OPTIONAL,
73
                'Override configured timeout'
74
            );
75
    }
76
77
    /**
78
     * Executes the current command.
79
     *
80
     * @param InputInterface  $input  An InputInterface instance
81
     * @param OutputInterface $output An OutputInterface instance
82
     *
83
     * @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...
84
     *
85
     * @throws \LogicException When this abstract class is not implemented
86
     */
87
    protected function execute(InputInterface $input, OutputInterface $output)
88
    {
89
        /**
90
         * @var QuestionHelper $question
91
         */
92
        $question = $this->getHelperSet()->get('question');
93
94
        if (
95
            !$input->getOption('no-interaction') &&
96
            !$question->ask(
97
                $input,
98
                $output,
99
                new ConfirmationQuestion('This will execute asked job?')
100
            )
101
        ) {
102
            return;
103
        }
104
105
        if (!$input->getOption('quiet')) {
106
107
            $output->writeln(sprintf(
108
                '<info>[%s] loading...</info>',
109
                date('Y-m-d H:i:s')
110
            ));
111
        }
112
113
        $job = $input->getArgument('job');
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 10 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
114
        $jobStructure = $this
115
            ->getContainer()->get('gearman')
116
            ->getJob($job);
117
118
        if (
119
            !$input->getOption('no-description') &&
120
            !$input->getOption('quiet')
121
        ) {
122
123
            $this
124
                ->getContainer()->get('gearman.describer')
125
                ->describeJob(
126
                    $output,
127
                    $jobStructure
128
                );
129
        }
130
131
        if (!$input->getOption('quiet')) {
132
133
            $output->writeln(sprintf(
134
                '<info>[%s] loaded. Ctrl+C to break</info>',
135
                date('Y-m-d H:i:s')
136
            ));
137
        }
138
139
        $this
140
            ->getContainer()->get('gearman.execute')
141
            ->setOutput($output)
142
            ->executeJob($job, array(
143
                'iterations'             => $input->getOption('iterations'),
144
                'minimum_execution_time' => $input->getOption('minimum-execution-time'),
145
                'timeout'                => $input->getOption('timeout')
146
            ));
147
    }
148
}
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...
149