Skip to content

Commit fe7954d

Browse files
ohmyfelixf3l1x
authored andcommitted
Fix PHPStan issues with current dependencies
1 parent 90f4b2d commit fe7954d

5 files changed

Lines changed: 24 additions & 13 deletions

File tree

src/Filter/FilterMultiSelect.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,7 @@ protected function addControl(
5252
array $options
5353
): BaseControl
5454
{
55-
/**
56-
* Set some translated texts
57-
*/
55+
/** @var Form $form */
5856
$form = $container->lookup(Form::class);
5957

6058
$translator = $form->getTranslator();

src/Filter/FilterSelect.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public function __construct(
3636

3737
public function addToFormContainer(Container $container): void
3838
{
39+
/** @var Form $form */
3940
$form = $container->lookup(Form::class);
4041

4142
$translator = $form->getTranslator();

src/GroupAction/GroupActionCollection.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,15 @@ public function submitted(NetteForm $form): void
164164
return;
165165
}
166166

167-
/** @var array $httpIds */
168167
$httpIds = $form->getHttpData(
169168
Form::DataLine | Form::DataKeys,
170169
strtolower($this->datagrid->getFullName()) . '_group_action_item[]'
171170
);
172171

172+
if (!is_array($httpIds)) {
173+
$httpIds = [];
174+
}
175+
173176
$ids = array_keys($httpIds);
174177

175178
if ($submitter->getName() === 'submit') {

src/InlineEdit/InlineEdit.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
use Contributte\Datagrid\Traits\TButtonTitle;
1111
use Contributte\Datagrid\Traits\TButtonTryAddIcon;
1212
use Nette\Forms\Container;
13+
use Nette\Forms\Controls\BaseControl;
14+
use Nette\Forms\Controls\SubmitButton;
1315
use Nette\SmartObject;
1416
use Nette\Utils\ArrayHash;
1517
use Nette\Utils\Html;
@@ -178,20 +180,24 @@ public function addControlsClasses(Container $container): void
178180
foreach ($container->getControls() as $key => $control) {
179181
switch ($key) {
180182
case 'submit':
181-
$control->setValidationScope([$container]);
182-
$control->setAttribute('class', 'btn btn-xs btn-primary');
183+
if ($control instanceof SubmitButton) {
184+
$control->setValidationScope([$container]);
185+
$control->setHtmlAttribute('class', 'btn btn-xs btn-primary');
186+
}
183187

184188
break;
185189

186190
case 'cancel':
187-
$control->setValidationScope([]);
188-
$control->setAttribute('class', 'btn btn-xs btn-danger');
191+
if ($control instanceof SubmitButton) {
192+
$control->setValidationScope([]);
193+
$control->setHtmlAttribute('class', 'btn btn-xs btn-danger');
194+
}
189195

190196
break;
191197

192198
default:
193-
if ($control->getControlPrototype()->getAttribute('class') === null) {
194-
$control->setAttribute('class', 'form-control form-control-sm');
199+
if ($control instanceof BaseControl && $control->getControlPrototype()->getAttribute('class') === null) {
200+
$control->setHtmlAttribute('class', 'form-control form-control-sm');
195201
}
196202

197203
break;

src/Utils/ItemDetailForm.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ final class ItemDetailForm extends Container
1515
/** @var callable */
1616
private $callableSetContainer;
1717

18-
/** @var ?array */
19-
private ?array $httpPost = null;
18+
private mixed $httpPost = null;
2019

2120
/** @var array<bool> */
2221
private array $containerSetByName = [];
@@ -62,8 +61,12 @@ private function getHttpData(): mixed
6261

6362
$path = explode(self::NameSeparator, $lookupPath);
6463

65-
/** @var array $httpData */
6664
$httpData = $form->getHttpData();
65+
66+
if (!is_array($httpData)) {
67+
$httpData = [];
68+
}
69+
6770
$this->httpPost = Arrays::get($httpData, $path, null);
6871
}
6972

0 commit comments

Comments
 (0)