InvalidTask::shouldRollbackDueTo()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
3
namespace Cerbero\ConsoleTasker\Tasks;
4
5
/**
6
 * An invalid task.
7
 *
8
 */
9
class InvalidTask extends AbstractTask
10
{
11
    /**
12
     * The invalid task class.
13
     *
14
     * @var string
15
     */
16
    protected $class;
17
18
    /**
19
     * Construct the class
20
     *
21
     * @param string $class
22
     */
23
    public function __construct(string $class)
24
    {
25
        $this->class = $class;
26
    }
27
28
    /**
29
     * Run the task
30
     *
31
     * @return mixed
32
     */
33
    public function run()
34
    {
35
        return false;
36
    }
37
38
    /**
39
     * Set the invalid task class
40
     *
41
     * @param string $class
42
     * @return self
43
     */
44
    public function getClass(): string
45
    {
46
        return $this->class;
47
    }
48
49
    /**
50
     * Retrieve this task purpose
51
     *
52
     * @return string
53
     */
54
    public function getPurpose(): string
55
    {
56
        return class_basename($this->class);
57
    }
58
59
    /**
60
     * Retrieve the error that caused this task to fail
61
     *
62
     * @return string|null
63
     */
64
    public function getError(): ?string
65
    {
66
        if ($e = $this->getException()) {
67
            return $e->getMessage();
68
        }
69
70
        return "The item [{$this->class}] is not a valid task";
71
    }
72
73
    /**
74
     * Determine whether this task should rollback if the given task fails
75
     *
76
     * @param AbstractTask|null $task
77
     * @return bool
78
     */
79
    public function shouldRollbackDueTo(?AbstractTask $task): bool
80
    {
81
        return false;
82
    }
83
}
84