-
Notifications
You must be signed in to change notification settings - Fork 0
/
Task.php
64 lines (51 loc) · 1.22 KB
/
Task.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
declare(strict_types=1);
namespace Netlogix\DependencyResolver;
use InvalidArgumentException;
class Task implements TaskInterface
{
/**
* @var true
*/
private bool $resolved = false;
/**
* @param array<string> $dependencies
*/
public function __construct(
private readonly string $name,
private readonly array $dependencies = []
) {
if (array_filter($dependencies, fn ($i) => !is_string($i))) {
throw new InvalidArgumentException('Dependencies must be strings');
}
}
public function getName(): string
{
return $this->name;
}
public function getDependencies(): array
{
return $this->dependencies;
}
/**
* @param iterable<string> $resolvedTasks
*/
public function checkDependencies(array $resolvedTasks): bool
{
return [] === array_diff($this->getDependencies(), $resolvedTasks);
}
public function resolve(): self
{
$this->resolved = true;
return $this;
}
public function isResolved(): bool
{
return $this->resolved;
}
public function reset(): self
{
$this->resolved = false;
return $this;
}
}