ListWorkersCommand::formatRunnerName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Gendoria\CommandQueue\Console\Command;
4
5
use Gendoria\CommandQueue\Worker\WorkerRunnerManager;
6
use Symfony\Component\Console\Command\Command;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Output\OutputInterface;
9
10
/**
11
 * Description of RunWorkerCommand
12
 *
13
 * @author Tomasz Struczyński <[email protected]>
14
 */
15
class ListWorkersCommand extends Command
16
{
17
    /**
18
     * Worker runner manager.
19
     * 
20
     * @var WorkerRunnerManager
21
     */
22
    private $runnerManager;
23
    
24
    /**
25
     * Set worker runner manager.
26
     * 
27
     * @param WorkerRunnerManager $runnerManager Worker runner manager instance.
28
     */
29 1
    public function setRunnerManager(WorkerRunnerManager $runnerManager)
30
    {
31 1
        $this->runnerManager = $runnerManager;
32 1
    }    
33
34 2
    protected function configure()
35
    {
36 2
        $this->setName('cmq:worker:list')
37 2
            ->setDescription('List available workers');
38 2
    }
39
40 2
    public function execute(InputInterface $input, OutputInterface $output)
41
    {
42 2
        if (null === $this->runnerManager) {
43 1
            $output->writeln("<error>Runner manager not provided to command. Command is not correctly initialized.</error>");
44 1
            return 1;
45
        }
46 1
        $runners = $this->runnerManager->getRunners();
47 1
        $runnersFormatted = array_map(array($this, 'formatRunnerName'), $runners);
48 1
        $output->writeln('Registered workers:');
49 1
        $output->writeln($runnersFormatted);
50 1
    }
51
52 1
    public function formatRunnerName($name)
53
    {
54 1
        return sprintf("  * <info>%s</info>", $name);
55
    }    
56
}
57