|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Stu\Component\Anomaly; |
|
6
|
|
|
|
|
7
|
|
|
use InvalidArgumentException; |
|
8
|
|
|
use Override; |
|
|
|
|
|
|
9
|
|
|
use Stu\Component\Anomaly\Type\AnomalyTypeEnum; |
|
10
|
|
|
use Stu\Module\Logging\LogTypeEnum; |
|
11
|
|
|
use Stu\Module\Logging\StuLogger; |
|
12
|
|
|
use Stu\Orm\Entity\Anomaly; |
|
13
|
|
|
use Stu\Orm\Entity\Location; |
|
14
|
|
|
use Stu\Orm\Repository\AnomalyRepositoryInterface; |
|
15
|
|
|
use Stu\Orm\Repository\AnomalyTypeRepositoryInterface; |
|
16
|
|
|
|
|
17
|
|
|
final class AnomalyCreation implements AnomalyCreationInterface |
|
18
|
|
|
{ |
|
19
|
4 |
|
public function __construct( |
|
20
|
|
|
private readonly AnomalyRepositoryInterface $anomalyRepository, |
|
21
|
|
|
private readonly AnomalyTypeRepositoryInterface $anomalyTypeRepository |
|
22
|
4 |
|
) {} |
|
23
|
|
|
|
|
24
|
3 |
|
#[Override] |
|
25
|
|
|
public function create( |
|
26
|
|
|
AnomalyTypeEnum $type, |
|
27
|
|
|
?Location $location, |
|
28
|
|
|
?Anomaly $parent = null, |
|
29
|
|
|
?Object $dataObject = null |
|
30
|
|
|
): Anomaly { |
|
31
|
|
|
|
|
32
|
3 |
|
$anomalyType = $this->anomalyTypeRepository->find($type->value); |
|
33
|
3 |
|
if ($anomalyType === null) { |
|
34
|
1 |
|
throw new InvalidArgumentException(sprintf('no anomaly in database for type: %d', $type->value)); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
2 |
|
$anomaly = $this->anomalyRepository |
|
38
|
2 |
|
->prototype() |
|
39
|
2 |
|
->setAnomalyType($anomalyType) |
|
40
|
2 |
|
->setRemainingTicks($anomalyType->getLifespanInTicks()) |
|
41
|
2 |
|
->setLocation($location); |
|
42
|
|
|
|
|
43
|
2 |
|
if ($parent !== null && $location !== null) { |
|
44
|
1 |
|
$parent->getChildren()->set($location->getId(), $anomaly); |
|
45
|
1 |
|
$anomaly->setParent($parent); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
2 |
|
if ($dataObject !== null) { |
|
49
|
1 |
|
$json = json_encode($dataObject, JSON_THROW_ON_ERROR); |
|
50
|
1 |
|
$anomaly->setData($json); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
2 |
|
if ($location !== null) { |
|
54
|
|
|
|
|
55
|
2 |
|
StuLogger::log(sprintf('created %s at %s', $type->name, $location->getSectorString()), LogTypeEnum::ANOMALY); |
|
|
|
|
|
|
56
|
|
|
|
|
57
|
2 |
|
$location->addAnomaly($anomaly); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
2 |
|
$this->anomalyRepository->save($anomaly); |
|
61
|
|
|
|
|
62
|
2 |
|
return $anomaly; |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths