Skip to content

Commit 6cfa8b8

Browse files
committed
wip2
1 parent 3d5d302 commit 6cfa8b8

8 files changed

+36
-231
lines changed

Diff for: application/forms/Command/CommandForm.php

+12-5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Icinga\Module\Icingadb\Forms\Command;
66

77
use ArrayIterator;
8+
use Countable;
89
use Exception;
910
use Icinga\Application\Logger;
1011
use Icinga\Module\Icingadb\Command\IcingaCommand;
@@ -16,6 +17,7 @@
1617
use ipl\Orm\Model;
1718
use ipl\Web\Common\CsrfCounterMeasure;
1819
use Iterator;
20+
use IteratorIterator;
1921
use Traversable;
2022

2123
abstract class CommandForm extends Form
@@ -25,7 +27,7 @@ abstract class CommandForm extends Form
2527

2628
protected $defaultAttributes = ['class' => 'icinga-form icinga-controls'];
2729

28-
/** @var mixed */
30+
/** @var (Traversable<Model>&Countable)|array<Model> */
2931
protected $objects;
3032

3133
/** @var bool */
@@ -43,7 +45,7 @@ abstract class CommandForm extends Form
4345
/**
4446
* Set the objects to issue the command for
4547
*
46-
* @param mixed $objects A traversable that is also countable
48+
* @param (Traversable<Model>&Countable)|array<Model> $objects A traversable that is also countable
4749
*
4850
* @return $this
4951
*/
@@ -57,7 +59,7 @@ public function setObjects($objects): self
5759
/**
5860
* Get the objects to issue the command for
5961
*
60-
* @return mixed
62+
* @return (Traversable<Model>&Countable)|array<Model>
6163
*/
6264
public function getObjects()
6365
{
@@ -123,10 +125,15 @@ protected function assemble()
123125

124126
protected function onSuccess()
125127
{
126-
$errors = [];
127128
$objects = $this->getObjects();
129+
if (is_array($objects)) {
130+
$objects = new ArrayIterator($objects);
131+
} else {
132+
$objects = new IteratorIterator($objects);
133+
}
128134

129-
foreach ($this->getCommands(is_array($objects) ? new ArrayIterator($objects) : $objects) as $command) {
135+
$errors = [];
136+
foreach ($this->getCommands($objects) as $command) {
130137
try {
131138
$this->sendCommand($command);
132139
} catch (Exception $e) {

Diff for: application/forms/Command/Object/AcknowledgeProblemForm.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use ipl\Html\Attributes;
1515
use ipl\Html\HtmlElement;
1616
use ipl\Html\Text;
17+
use ipl\Orm\Model;
1718
use ipl\Stdlib\CallbackFilterIterator;
1819
use ipl\Validator\CallbackValidator;
1920
use ipl\Web\FormDecorator\IcingaFormDecorator;
@@ -190,7 +191,7 @@ protected function assembleSubmitButton()
190191

191192
protected function getCommands(Iterator $objects): Traversable
192193
{
193-
$granted = new CallbackFilterIterator($objects, function ($object) {
194+
$granted = new CallbackFilterIterator($objects, function (Model $object): bool {
194195
return $this->isGrantedOn('icingadb/command/acknowledge-problem', $object);
195196
});
196197

Diff for: application/forms/Command/Object/ToggleObjectFeaturesForm.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ protected function getCommands(Iterator $objects): Traversable
171171
continue;
172172
}
173173

174-
$granted = new CallbackFilterIterator($objects, function ($object) use ($spec) {
174+
$granted = new CallbackFilterIterator($objects, function (Model $object) use ($spec): bool {
175175
return $this->isGrantedOn($spec['permission'], $object);
176176
});
177177

Diff for: library/Icingadb/Common/CommandActions.php

+10-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Icinga\Module\Icingadb\Common;
66

7+
use Icinga\Exception\Http\HttpNotFoundException;
78
use Icinga\Module\Icingadb\Forms\Command\CommandForm;
89
use Icinga\Module\Icingadb\Forms\Command\Object\AcknowledgeProblemForm;
910
use Icinga\Module\Icingadb\Forms\Command\Object\AddCommentForm;
@@ -26,7 +27,7 @@
2627
*/
2728
trait CommandActions
2829
{
29-
/** @var Query $commandTargets */
30+
/** @var Query|array<int, Model>|null $commandTargets */
3031
protected $commandTargets;
3132

3233
/** @var Model $commandTargetModel */
@@ -51,14 +52,14 @@ protected function getFeatureStatus()
5152
/**
5253
* Fetch command targets
5354
*
54-
* @return Query|Model[]
55+
* @return Query|array<int, Model>
5556
*/
5657
abstract protected function fetchCommandTargets();
5758

5859
/**
5960
* Get command targets
6061
*
61-
* @return Query|Model[]
62+
* @return Query|array<int, Model>
6263
*/
6364
protected function getCommandTargets()
6465
{
@@ -73,12 +74,17 @@ protected function getCommandTargets()
7374
* Get the model of the command targets
7475
*
7576
* @return Model
77+
* @throws HttpNotFoundException If no command targets were found
7678
*/
7779
protected function getCommandTargetModel(): Model
7880
{
7981
if (! isset($this->commandTargetModel)) {
8082
$commandTargets = $this->getCommandTargets();
81-
if (is_array($commandTargets) && !empty($commandTargets)) {
83+
if (is_array($commandTargets)) {
84+
if (empty($commandTargets)) {
85+
throw new HttpNotFoundException('No command targets found');
86+
}
87+
8288
$this->commandTargetModel = $commandTargets[0];
8389
} else {
8490
$this->commandTargetModel = $commandTargets->getModel();

Diff for: library/Icingadb/Widget/Detail/MultiselectQuickActions.php

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ protected function assemble()
6767
) {
6868
$removeAckForm = (new RemoveAcknowledgementForm())
6969
->setAction($this->getLink('removeAcknowledgement'))
70+
// TODO: This is a hack as for the button label the count of objects is used. setCount? setMultiple?
7071
->setObjects(array_fill(0, $this->summary->$acks, null));
7172

7273
$this->add(Html::tag('li', $removeAckForm));

Diff for: phpstan-baseline-7x.neon

+5-55
Original file line numberDiff line numberDiff line change
@@ -5,61 +5,6 @@ parameters:
55
count: 1
66
path: application/controllers/EventController.php
77

8-
-
9-
message: "#^Parameter \\#1 \\$var of function count expects array\\|Countable, mixed given\\.$#"
10-
count: 2
11-
path: application/forms/Command/Object/AcknowledgeProblemForm.php
12-
13-
-
14-
message: "#^Parameter \\#1 \\$var of function count expects array\\|Countable, mixed given\\.$#"
15-
count: 2
16-
path: application/forms/Command/Object/AddCommentForm.php
17-
18-
-
19-
message: "#^Parameter \\#1 \\$var of function count expects array\\|Countable, mixed given\\.$#"
20-
count: 1
21-
path: application/forms/Command/Object/CheckNowForm.php
22-
23-
-
24-
message: "#^Parameter \\#1 \\$var of function count expects array\\|Countable, mixed given\\.$#"
25-
count: 2
26-
path: application/forms/Command/Object/DeleteCommentForm.php
27-
28-
-
29-
message: "#^Parameter \\#1 \\$var of function count expects array\\|Countable, mixed given\\.$#"
30-
count: 2
31-
path: application/forms/Command/Object/DeleteDowntimeForm.php
32-
33-
-
34-
message: "#^Parameter \\#1 \\$var of function count expects array\\|Countable, mixed given\\.$#"
35-
count: 2
36-
path: application/forms/Command/Object/ProcessCheckResultForm.php
37-
38-
-
39-
message: "#^Parameter \\#1 \\$var of function count expects array\\|Countable, mixed given\\.$#"
40-
count: 2
41-
path: application/forms/Command/Object/RemoveAcknowledgementForm.php
42-
43-
-
44-
message: "#^Parameter \\#1 \\$var of function count expects array\\|Countable, mixed given\\.$#"
45-
count: 2
46-
path: application/forms/Command/Object/ScheduleCheckForm.php
47-
48-
-
49-
message: "#^Parameter \\#1 \\$var of function count expects array\\|Countable, mixed given\\.$#"
50-
count: 1
51-
path: application/forms/Command/Object/ScheduleHostDowntimeForm.php
52-
53-
-
54-
message: "#^Parameter \\#1 \\$var of function count expects array\\|Countable, mixed given\\.$#"
55-
count: 2
56-
path: application/forms/Command/Object/ScheduleServiceDowntimeForm.php
57-
58-
-
59-
message: "#^Parameter \\#1 \\$var of function count expects array\\|Countable, mixed given\\.$#"
60-
count: 2
61-
path: application/forms/Command/Object/SendCustomNotificationForm.php
62-
638
-
649
message: "#^Parameter \\#1 \\$str of function md5 expects string, mixed given\\.$#"
6510
count: 1
@@ -164,3 +109,8 @@ parameters:
164109
message: "#^Parameter \\#2 \\$str of function explode expects string, mixed given\\.$#"
165110
count: 1
166111
path: library/Icingadb/Web/Controller.php
112+
113+
-
114+
message: "#^Parameter \\#1 \\$objects of method Icinga\\\\Module\\\\Icingadb\\\\Forms\\\\Command\\\\CommandForm\\:\\:setObjects\\(\\) expects array\\<ipl\\\\Orm\\\\Model\\>\\|\\(Countable&Traversable\\<mixed, ipl\\\\Orm\\\\Model\\>\\), array\\<int, null\\>\\|false given\\.$#"
115+
count: 1
116+
path: library/Icingadb/Widget/Detail/MultiselectQuickActions.php

Diff for: phpstan-baseline-8x.neon

+5-55
Original file line numberDiff line numberDiff line change
@@ -5,61 +5,6 @@ parameters:
55
count: 1
66
path: application/controllers/EventController.php
77

8-
-
9-
message: "#^Parameter \\#1 \\$value of function count expects array\\|Countable, mixed given\\.$#"
10-
count: 2
11-
path: application/forms/Command/Object/AcknowledgeProblemForm.php
12-
13-
-
14-
message: "#^Parameter \\#1 \\$value of function count expects array\\|Countable, mixed given\\.$#"
15-
count: 2
16-
path: application/forms/Command/Object/AddCommentForm.php
17-
18-
-
19-
message: "#^Parameter \\#1 \\$value of function count expects array\\|Countable, mixed given\\.$#"
20-
count: 1
21-
path: application/forms/Command/Object/CheckNowForm.php
22-
23-
-
24-
message: "#^Parameter \\#1 \\$value of function count expects array\\|Countable, mixed given\\.$#"
25-
count: 2
26-
path: application/forms/Command/Object/DeleteCommentForm.php
27-
28-
-
29-
message: "#^Parameter \\#1 \\$value of function count expects array\\|Countable, mixed given\\.$#"
30-
count: 2
31-
path: application/forms/Command/Object/DeleteDowntimeForm.php
32-
33-
-
34-
message: "#^Parameter \\#1 \\$value of function count expects array\\|Countable, mixed given\\.$#"
35-
count: 2
36-
path: application/forms/Command/Object/ProcessCheckResultForm.php
37-
38-
-
39-
message: "#^Parameter \\#1 \\$value of function count expects array\\|Countable, mixed given\\.$#"
40-
count: 2
41-
path: application/forms/Command/Object/RemoveAcknowledgementForm.php
42-
43-
-
44-
message: "#^Parameter \\#1 \\$value of function count expects array\\|Countable, mixed given\\.$#"
45-
count: 2
46-
path: application/forms/Command/Object/ScheduleCheckForm.php
47-
48-
-
49-
message: "#^Parameter \\#1 \\$value of function count expects array\\|Countable, mixed given\\.$#"
50-
count: 1
51-
path: application/forms/Command/Object/ScheduleHostDowntimeForm.php
52-
53-
-
54-
message: "#^Parameter \\#1 \\$value of function count expects array\\|Countable, mixed given\\.$#"
55-
count: 2
56-
path: application/forms/Command/Object/ScheduleServiceDowntimeForm.php
57-
58-
-
59-
message: "#^Parameter \\#1 \\$value of function count expects array\\|Countable, mixed given\\.$#"
60-
count: 2
61-
path: application/forms/Command/Object/SendCustomNotificationForm.php
62-
638
-
649
message: "#^Parameter \\#1 \\$string of function md5 expects string, mixed given\\.$#"
6510
count: 1
@@ -159,3 +104,8 @@ parameters:
159104
message: "#^Parameter \\#2 \\$string of function explode expects string, mixed given\\.$#"
160105
count: 1
161106
path: library/Icingadb/Web/Controller.php
107+
108+
-
109+
message: "#^Parameter \\#1 \\$objects of method Icinga\\\\Module\\\\Icingadb\\\\Forms\\\\Command\\\\CommandForm\\:\\:setObjects\\(\\) expects array\\<ipl\\\\Orm\\\\Model\\>\\|\\(Countable&Traversable\\<mixed, ipl\\\\Orm\\\\Model\\>\\), array\\<int, null\\> given\\.$#"
110+
count: 1
111+
path: library/Icingadb/Widget/Detail/MultiselectQuickActions.php

0 commit comments

Comments
 (0)