Completed
Push — master ( b3f90f...c5536c )
by Daniel
03:02
created

PurgeCommand::execute()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 18
ccs 12
cts 12
cp 1
rs 9.4285
cc 3
eloc 10
nc 3
nop 2
crap 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
 * Purge command class.
15
 *
16
 * @package GravityMedia\Commander\Console\Command
17
 */
18
class PurgeCommand extends Command
19
{
20
    /**
21
     * {@inheritdoc}
22
     */
23
    protected function configure()
24
    {
25
        parent::configure();
26
27
        $this
28
            ->setName('purge')
29
            ->setDescription('Remove all terminated tasks');
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35 4
    protected function execute(InputInterface $input, OutputInterface $output)
36
    {
37 4
        $commander = $this->getCommander()->initialize();
38 4
        $taskManager = $commander->getTaskManager();
39
40 4
        $tasks = $taskManager->findAllTerminatedTasks();
41
42 4
        if (0 === count($tasks)) {
43 2
            $output->writeln('No tasks found');
44 2
            return;
45
        }
46
47 2
        foreach ($tasks as $task) {
48 2
            $task->remove();
49 1
        }
50
51 2
        $output->writeln(sprintf('Removed %s terminated task(s)', count($tasks)));
52 2
    }
53
}
54