PurgeCommand   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Test Coverage

Coverage 66.67%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 6
dl 0
loc 36
ccs 12
cts 18
cp 0.6667
rs 10

2 Methods

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