TaskRunnerSubscriber::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
/*
4
 * This file is part of the Conveyor package.
5
 *
6
 * (c) Jeroen Fiege <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Webcreate\Conveyor\Subscriber;
13
14
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
15
use Symfony\Component\EventDispatcher\GenericEvent;
16
use Webcreate\Conveyor\Event\TaskRunnerEvents;
17
use Webcreate\Conveyor\IO\IOInterface;
18
19
class TaskRunnerSubscriber implements EventSubscriberInterface
20
{
21
    protected $io;
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $io. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
22
    protected $showProgress = false;
23
    protected $needsNewline = false;
24
25 1
    public function __construct(IOInterface $io)
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $io. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
26
    {
27 1
        $this->io = $io;
28 1
    }
29
30 1
    public static function getSubscribedEvents()
31
    {
32
        return array(
33 1
            TaskRunnerEvents::TASKRUNNER_PRE_EXECUTE_TASK  => array('onTaskPreExecute'),
34
            TaskRunnerEvents::TASKRUNNER_POST_EXECUTE_TASK  => array('onTaskPostExecute'),
35
        );
36
    }
37
38 View Code Duplication
    public function onTaskPreExecute(GenericEvent $event)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
39
    {
40
        $task = $event->getSubject();
41
        $io   = $this->io;
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $io. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
42
43
        $self = $this;
44
45
        $task->setOutput(function ($output) use ($io, $self) {
46
            if ($io->isVerbose()) {
47
                $io->write(sprintf('%s', $output));
48
                $self->needsNewline = false;
49
            } else {
50
                $io->overwrite(sprintf('%s', $output), false);
51
                $self->needsNewline = true;
52
            }
53
        });
54
55
        if ($event->getArgument('index') > 0) {
56
            if (true === $this->needsNewline) {
57
                $this->io->write('');
58
                $this->needsNewline = false;
59
            }
60
            $this->io->write('');
61
        }
62
63
        $this->io->write(sprintf('- Executing task <info>%s</info>', get_class($task)));
64
        $this->io->increaseIndention(2);
65
    }
66
67
    public function onTaskPostExecute(GenericEvent $event)
68
    {
69
        $task = $event->getSubject();
0 ignored issues
show
Unused Code introduced by
$task is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
70
71
        $this->io->write('');
72
73
        $this->io->decreaseIndention(2);
74
    }
75
}
76