Task::output()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 4
cp 0.75
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 1
crap 2.0625
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\Task;
13
14
use Webcreate\Conveyor\Repository\Version;
15
16
/**
17
 * @todo Instead of returning a ExecuteResult in the task, let each task implement,
18
 *       a getDerivedFiles() and getRemovedFiles() method. This should remove
19
 *       the "new ExecuteResult" dependency from the tasks.
20
 */
21
abstract class Task
22
{
23
    protected $output;
24
    protected $options;
25
26
    abstract public function execute($target, Version $version);
27
28
    public function supports($target, Version $version)
0 ignored issues
show
Unused Code introduced by
The parameter $version is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
29
    {
30
        return (
31
            empty($this->options['targets'])
32
            || in_array($target, $this->options['targets'])
33
        );
34
    }
35
36
    public function simulate($target, Version $version)
37
    {
38
    }
39
40
    /**
41
     * Sets the options for the task, as configured in the conveyor file.
42
     *
43
     * Gets called during the TaskCompilerPass.
44
     *
45
     * @param  array $options
46
     * @return Task
47
     */
48 5
    public function setOptions(array $options)
49
    {
50 5
        $this->options = $options;
51
52 5
        return $this;
53
    }
54
55
    /**
56
     * Sets a specific option
57
     *
58
     * @todo validate $name
59
     *
60
     * @param string $name
61
     * @param $value
62
     * @return Task
63
     */
64
    public function setOption($name, $value)
65
    {
66
        $this->options[$name] = $value;
67
68
        return $this;
69
    }
70
71
    /**
72
     * Probably set via the TaskRunnerSubscriber
73
     *
74
     * @param \Closure $callback
75
     */
76
    public function setOutput(\Closure $callback)
77
    {
78
        $this->output = $callback;
79
    }
80
81
    /**
82
     * @param string $output
83
     */
84 6
    protected function output($output)
85
    {
86 6
        if ($this->output) {
87
            call_user_func($this->output, $output);
88
        }
89 6
    }
90
}
91