Completed
Push — master ( 7a08de...9ce2ea )
by Daniel
04:39
created

PruneCommand::execute()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 17
ccs 0
cts 11
cp 0
rs 9.4285
cc 3
eloc 9
nc 3
nop 2
crap 12
1
<?php
2
/**
3
 * This file is part of the Commander project.
4
 *
5
 * @author Daniel Schröder <[email protected]>
6
 */
7
8
namespace GravityMedia\Commander\Console\Command;
9
10
use Symfony\Component\Console\Input\InputInterface;
11
use Symfony\Component\Console\Output\OutputInterface;
12
13
/**
14
 * Prune command class.
15
 *
16
 * @package GravityMedia\Commander\Console\Command
17
 */
18
class PruneCommand extends Command
19
{
20
    /**
21
     * {@inheritdoc}
22
     */
23
    protected function configure()
24
    {
25
        parent::configure();
26
27
        $this
28
            ->setName('tasks:prune')
29
            ->setDescription('Prune tasks');
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    protected function execute(InputInterface $input, OutputInterface $output)
36
    {
37
        $taskManager = $this->getCommander()->getTaskManager();
38
39
        $tasks = $taskManager->findAllTerminatedTasks();
40
41
        if (0 === count($tasks)) {
42
            $output->writeln('No tasks found');
43
            return;
44
        }
45
46
        foreach ($tasks as $task) {
47
            $task->remove();
48
        }
49
50
        $output->writeln(sprintf('Removed %s terminated task(s)', count($tasks)));
51
    }
52
}
53