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

PruneCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 0
cbo 6
dl 0
loc 35
ccs 0
cts 17
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 8 1
A execute() 0 17 3
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