1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Stu\Lib\ShipManagement\Manager; |
6
|
|
|
|
7
|
|
|
use Override; |
|
|
|
|
8
|
|
|
use RuntimeException; |
9
|
|
|
use Stu\Lib\ShipManagement\Provider\ManagerProviderInterface; |
10
|
|
|
use Stu\Component\Player\Relation\PlayerRelationDeterminatorInterface; |
11
|
|
|
use Stu\Module\Commodity\Lib\CommodityCacheInterface; |
12
|
|
|
use Stu\Module\Ship\Lib\ReactorUtilInterface; |
13
|
|
|
use Stu\Module\Ship\Lib\ReactorWrapperInterface; |
14
|
|
|
use Stu\Module\Ship\Lib\ShipWrapperInterface; |
15
|
|
|
use Stu\Orm\Entity\ShipInterface; |
16
|
|
|
|
17
|
|
|
class ManageReactor implements ManagerInterface |
18
|
|
|
{ |
19
|
8 |
|
public function __construct(private ReactorUtilInterface $reactorUtil, private CommodityCacheInterface $commodityCache, private PlayerRelationDeterminatorInterface $playerRelationDeterminator) {} |
20
|
|
|
|
21
|
8 |
|
#[Override] |
22
|
|
|
public function manage(ShipWrapperInterface $wrapper, array $values, ManagerProviderInterface $managerProvider): array |
23
|
|
|
{ |
24
|
8 |
|
$values = $values['reactor'] ?? null; |
25
|
8 |
|
if ($values === null) { |
26
|
1 |
|
throw new RuntimeException('value array not existent'); |
27
|
|
|
} |
28
|
|
|
|
29
|
7 |
|
$ship = $wrapper->get(); |
30
|
|
|
|
31
|
7 |
|
if (!array_key_exists($ship->getId(), $values)) { |
32
|
1 |
|
return []; |
33
|
|
|
} |
34
|
|
|
|
35
|
6 |
|
if ($values[$ship->getId()] < 1) { |
36
|
1 |
|
return []; |
37
|
|
|
} |
38
|
|
|
|
39
|
5 |
|
$reactor = $wrapper->getReactorWrapper(); |
40
|
5 |
|
if ($reactor === null) { |
41
|
1 |
|
return []; |
42
|
|
|
} |
43
|
|
|
|
44
|
4 |
|
if ($ship->getShieldState() && !$this->playerRelationDeterminator->isFriend($ship->getUser(), $managerProvider->getUser())) { |
45
|
1 |
|
$msg[] = sprintf( |
|
|
|
|
46
|
1 |
|
_('%s: Warpkern konnte wegen aktivierter Schilde nicht aufgeladen werden.'), |
47
|
1 |
|
$ship->getName() |
48
|
1 |
|
); |
49
|
1 |
|
return $msg; |
50
|
|
|
} |
51
|
|
|
|
52
|
3 |
|
$storage = $managerProvider->getStorage(); |
53
|
|
|
|
54
|
3 |
|
if ($this->reactorUtil->storageContainsNeededCommodities($storage, $reactor)) { |
55
|
2 |
|
$load = $values[$ship->getId()] == 'm' ? PHP_INT_MAX : (int)$values[$ship->getId()]; |
56
|
2 |
|
$loadMessage = $this->reactorUtil->loadReactor($ship, $load, $managerProvider, $reactor); |
57
|
|
|
|
58
|
2 |
|
if ($loadMessage !== null) { |
59
|
2 |
|
return [$loadMessage]; |
60
|
|
|
} |
61
|
|
|
} else { |
62
|
1 |
|
return $this->createMissingCommoditiesMessage($ship, $reactor); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
return []; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @return array<string> |
70
|
|
|
*/ |
71
|
1 |
|
private function createMissingCommoditiesMessage(ShipInterface $ship, ReactorWrapperInterface $reactor): array |
72
|
|
|
{ |
73
|
1 |
|
$msg = []; |
74
|
|
|
|
75
|
1 |
|
$msg[] = sprintf( |
76
|
1 |
|
_('%s: Es werden mindestens folgende Waren zum Aufladen des %ss benötigt:'), |
77
|
1 |
|
$ship->getName(), |
78
|
1 |
|
$reactor->get()->getSystemType()->getDescription() |
79
|
1 |
|
); |
80
|
|
|
|
81
|
1 |
|
foreach ($reactor->get()->getLoadCost() as $commodityId => $loadCost) { |
82
|
1 |
|
$commodity = $this->commodityCache->get($commodityId); |
83
|
1 |
|
$msg[] = sprintf(_('%d %s'), $loadCost, $commodity->getName()); |
84
|
|
|
} |
85
|
|
|
|
86
|
1 |
|
return $msg; |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
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