These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace TreeHouse\WorkerBundle\Command; |
||
4 | |||
5 | use Pheanstalk\Exception\ServerException; |
||
6 | use Symfony\Component\Console\Command\Command; |
||
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 ClearCommand 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() |
|
34 | { |
||
35 | $this |
||
36 | ->setName('worker:clear') |
||
37 | ->addArgument('action', InputArgument::OPTIONAL | InputArgument::IS_ARRAY, 'Selects which actions to clear. Defaults to all actions') |
||
38 | ->addOption('state', null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'The state of jobs to peek for. Valid options are <comment>ready</comment>, <comment>delayed</comment> and <comment>buried</comment>.', ['ready']) |
||
39 | ->setDescription('Clears jobs for action(s)') |
||
40 | ; |
||
41 | } |
||
42 | |||
43 | /** |
||
44 | * @inheritdoc |
||
45 | */ |
||
46 | protected function execute(InputInterface $input, OutputInterface $output) |
||
47 | { |
||
48 | $actions = $input->getArgument('action'); |
||
49 | if (empty($actions)) { |
||
50 | $actions = array_keys($this->manager->getExecutors()); |
||
51 | } |
||
52 | |||
53 | $states = $input->getOption('state'); |
||
54 | |||
55 | $pheanstalk = $this->manager->getPheanstalk(); |
||
56 | |||
57 | foreach ($actions as $action) { |
||
58 | try { |
||
59 | $stats = $pheanstalk->statsTube($action); |
||
60 | |||
61 | $amount = 0; |
||
62 | foreach ($states as $state) { |
||
63 | $amount += $stats['current-jobs-' . $state]; |
||
64 | } |
||
65 | |||
66 | $output->writeln( |
||
67 | sprintf( |
||
68 | 'Clearing <info>%d %s jobs</info> with <info>%s</info> status', |
||
69 | $amount, |
||
70 | $action, |
||
71 | implode(', ', $states) |
||
72 | ) |
||
73 | ); |
||
74 | |||
75 | $this->manager->clear($action, $states); |
||
76 | |||
77 | $output->writeln(['<info>Done!</info>', '']); |
||
0 ignored issues
–
show
|
|||
78 | } catch (ServerException $e) { |
||
79 | if (false === strpos($e->getMessage(), 'NOT_FOUND')) { |
||
80 | throw $e; |
||
81 | } |
||
82 | } |
||
83 | } |
||
84 | } |
||
85 | } |
||
86 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: