mmucklo /
DtcQueueBundle
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Dtc\QueueBundle\Command; |
||
| 4 | |||
| 5 | use Dtc\QueueBundle\Manager\JobManagerInterface; |
||
| 6 | use Symfony\Component\Console\Command\Command; |
||
|
0 ignored issues
–
show
|
|||
| 7 | use Symfony\Component\Console\Input\InputInterface; |
||
|
0 ignored issues
–
show
The type
Symfony\Component\Console\Input\InputInterface was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 8 | use Symfony\Component\Console\Output\OutputInterface; |
||
|
0 ignored issues
–
show
The type
Symfony\Component\Console\Output\OutputInterface was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 9 | |||
| 10 | class CountCommand extends Command |
||
| 11 | { |
||
| 12 | /** @var JobManagerInterface */ |
||
| 13 | private $jobManager; |
||
| 14 | |||
| 15 | 4 | public function setJobManager($jobManager) |
|
| 16 | { |
||
| 17 | 4 | $this->jobManager = $jobManager; |
|
| 18 | 4 | } |
|
| 19 | |||
| 20 | 4 | protected function configure(): void |
|
| 21 | { |
||
| 22 | $this |
||
| 23 | 4 | ->setName('dtc:queue:count') |
|
| 24 | 4 | ->setDescription('Display job queue status.'); |
|
| 25 | 4 | } |
|
| 26 | |||
| 27 | 4 | protected function execute(InputInterface $input, OutputInterface $output): int |
|
| 28 | { |
||
| 29 | 4 | $waitingCount = $this->jobManager->getWaitingJobCount(); |
|
| 30 | 4 | $status = $this->jobManager->getStatus(); |
|
| 31 | 4 | $firstJob = key($status); |
|
| 32 | 4 | if ($firstJob) { |
|
| 33 | 1 | $jobKeys = array_keys($status); |
|
| 34 | 1 | $maxLength = max(array_map(function ($item) { |
|
| 35 | 1 | return strlen($item ?: ''); |
|
| 36 | 1 | }, $jobKeys)); |
|
| 37 | 1 | $formatLen = $this->determineFormatLength($maxLength); |
|
| 38 | 1 | $format = '%-'.$formatLen.'s'; |
|
| 39 | 1 | $headingArgs = ['Job name']; |
|
| 40 | 1 | $initialKeys = array_keys($status[$firstJob]); |
|
| 41 | 1 | $this->formatHeadings($initialKeys, $headingArgs, $format); |
|
| 42 | 1 | array_unshift($headingArgs, $format); |
|
| 43 | 1 | $msg = call_user_func_array('sprintf', $headingArgs); |
|
| 44 | 1 | $output->writeln($msg); |
|
| 45 | 1 | $this->outputStatus($output, $status, $initialKeys, $format); |
|
| 46 | } |
||
| 47 | 4 | $output->writeln("Total waiting jobs: {$waitingCount}"); |
|
| 48 | |||
| 49 | 4 | return $this::SUCCESS; |
|
| 50 | } |
||
| 51 | |||
| 52 | /** |
||
| 53 | * @param string $format |
||
| 54 | */ |
||
| 55 | 1 | private function outputStatus(OutputInterface $output, array $status, array $initialKeys, $format) |
|
| 56 | { |
||
| 57 | 1 | foreach ($status as $func => $info) { |
|
| 58 | 1 | $lineArgs = [$format, $func]; |
|
| 59 | 1 | foreach ($initialKeys as $statusKey) { |
|
| 60 | 1 | $lineArgs[] = $info[$statusKey]; |
|
| 61 | } |
||
| 62 | 1 | $msg = call_user_func_array('sprintf', $lineArgs); |
|
| 63 | 1 | $output->writeln($msg); |
|
| 64 | } |
||
| 65 | 1 | } |
|
| 66 | |||
| 67 | /** |
||
| 68 | * @param string $format |
||
| 69 | */ |
||
| 70 | 1 | private function formatHeadings(array $initialKeys, array &$headingArgs, &$format) |
|
| 71 | { |
||
| 72 | 1 | foreach ($initialKeys as $statusName) { |
|
| 73 | 1 | $headingStr = ucwords(str_replace('_', ' ', $statusName)); |
|
| 74 | 1 | $format .= ' %'.(1 + strlen($headingStr)).'s'; |
|
| 75 | 1 | $headingArgs[] = $headingStr; |
|
| 76 | } |
||
| 77 | 1 | } |
|
| 78 | |||
| 79 | /** |
||
| 80 | * @param int $maxLength |
||
| 81 | * |
||
| 82 | * @return int |
||
| 83 | */ |
||
| 84 | 1 | private function determineFormatLength($maxLength) |
|
| 85 | { |
||
| 86 | 1 | $formatLen = $maxLength > 50 ? 50 : $maxLength; |
|
| 87 | 1 | $formatMinLen = strlen('Job name') + 1; |
|
| 88 | 1 | $formatLen = $formatLen < $formatMinLen ? $formatMinLen : $formatLen; |
|
| 89 | |||
| 90 | 1 | return $formatLen; |
|
| 91 | } |
||
| 92 | } |
||
| 93 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths