Skip to content

Commit 4fdebeb

Browse files
authored
Merge pull request #109 from systopia/fix-phpstan-errors
Fix phpstan errors
2 parents 2024c40 + bed925a commit 4fdebeb

File tree

4 files changed

+10
-5
lines changed

4 files changed

+10
-5
lines changed

phpstan.neon.dist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ parameters:
2222
ignoreErrors:
2323
# Note paths are prefixed with ""*/" to wirk with inspections in PHPStorm because of:
2424
# https://youtrack.jetbrains.com/issue/WI-63891/PHPStan-ignoreErrors-configuration-isnt-working-with-inspections
25+
# Happens in classes implementing ContainerInjectionInterface::create()
26+
- '/ constructor expects [^\s]+, object(\|null)? given.$/'
2527
# Wrong phpdoc type hint in Drupal
2628
- '/^Parameter #1 \$key of method Drupal\\Core\\Form\\FormStateInterface::hasTemporaryValue\(\) expects string, array<int\|string> given.$/'
2729
-

src/Form/AbstractJsonFormsForm.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,11 @@ abstract class AbstractJsonFormsForm extends FormBase {
6262
* @return static
6363
*/
6464
public static function create(ContainerInterface $container) {
65-
return new static($container->get(FormArrayFactoryInterface::class),
66-
$container->get(FormValidatorInterface::class), $container->get(FormValidationMapperInterface::class));
65+
return new static(
66+
$container->get(FormArrayFactoryInterface::class),
67+
$container->get(FormValidatorInterface::class),
68+
$container->get(FormValidationMapperInterface::class)
69+
);
6770
}
6871

6972
public function __construct(
@@ -260,7 +263,7 @@ protected function doGetSubmittedData(FormStateInterface $formState): array {
260263
*
261264
* phpcs:disable Generic.Files.LineLength.TooLong
262265
*/
263-
private function determineLimitValidationErrors(FormStateInterface &$formState): ?array {
266+
private function determineLimitValidationErrors(FormStateInterface $formState): ?array {
264267
// While this element is being validated, it may be desired that some
265268
// calls to \Drupal\Core\Form\FormStateInterface::setErrorByName() be
266269
// suppressed and not result in a form error, so that a button that
@@ -284,7 +287,7 @@ private function determineLimitValidationErrors(FormStateInterface &$formState):
284287
// setting the #limit_validation_errors property. For button element
285288
// types, #limit_validation_errors defaults to FALSE, so that full
286289
// validation is their default behavior.
287-
elseif ($triggering_element && !isset($triggering_element['#limit_validation_errors']) && !$formState->isSubmitted()) {
290+
elseif (NULL !== $triggering_element && !isset($triggering_element['#limit_validation_errors']) && !$formState->isSubmitted()) {
288291
return [];
289292
}
290293
// As an extra security measure, explicitly turn off error suppression if

src/Form/Control/Callbacks/ArrayCallbacks.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ public static function removeItem(array &$form, FormStateInterface $formState):
188188
private static function &getArrayForm(array &$form, array $triggeringElement): array {
189189
$arrayParents = $triggeringElement['#array_parents'];
190190
Assertion::isArray($arrayParents);
191+
/** @var list<int|string> $arrayParents */
191192
$propertyPath = $triggeringElement['#_controlPropertyPath'];
192193
Assertion::isArray($propertyPath);
193194

src/Form/Control/SelectArrayFactory.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ public function createFormArray(
6161
if (!$definition->isRequired()) {
6262
$form['#empty_value'] = '';
6363
}
64-
// @phpstan-ignore offsetAccess.nonOffsetAccessible
6564
if (isset($form['#options']['']) && '' !== $form['#options']['']) {
6665
$form['#empty_option'] = $form['#options'][''];
6766
}

0 commit comments

Comments
 (0)