Skip to content

Commit

Permalink
Fix more errors after PHPStan update
Browse files Browse the repository at this point in the history
  • Loading branch information
darrenoh committed Mar 7, 2024
1 parent 9f40f63 commit 464fe7f
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 5 deletions.
4 changes: 2 additions & 2 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -531,12 +531,12 @@ parameters:
path: src/Routing/HookMenuRoutes.php

-
message: "#^Cannot access offset '\\#title' on mixed\\.$#"
message: "#^Cannot access offset '\\#id' on mixed\\.$#"
count: 1
path: src/Theme/HookPreprocess.php

-
message: "#^Offset '\\#id' might not exist on array\\<int\\|string, mixed\\>\\|string\\.$#"
message: "#^Cannot access offset '\\#title' on mixed\\.$#"
count: 1
path: src/Theme/HookPreprocess.php

Expand Down
1 change: 1 addition & 0 deletions src/Form/FormBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class FormBuilder extends CoreFormBuilder
{
/**
* @param FormStateInterface|mixed[] $form_state
* @param-out FormStateInterface $form_state
* @return mixed[]
*/
public function buildForm(mixed $form_arg, FormStateInterface|array &$form_state): array
Expand Down
2 changes: 1 addition & 1 deletion src/Theme/HookPreprocess.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Retrofit\Drupal\Entity\WrappedConfigEntity;

/**
* @phpstan-type Variables array<string, string|array<int|string, mixed>>
* @phpstan-type Variables array<string, mixed>
* @phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
*/
final class HookPreprocess
Expand Down
2 changes: 2 additions & 0 deletions src/Theme/Registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ final class Registry extends CoreRegistry
{
/**
* @param RegistryData $cache
* @param-out array $cache
*/
protected function processExtension(array &$cache, $name, $type, $theme, $path): void
{
Expand Down Expand Up @@ -72,6 +73,7 @@ protected function processExtension(array &$cache, $name, $type, $theme, $path):

/**
* @param array<string, array{'preprocess functions': callable[]}> $cache
* @param-out array $cache
*/
protected function postProcessExtension(array &$cache, ActiveTheme $theme): void
{
Expand Down
8 changes: 7 additions & 1 deletion src/functions/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use Drupal\Component\Utility\UrlHelper;
use Drupal\Component\Utility\Xss;
use Drupal\Core\Asset\LibraryDiscoveryInterface;
use Drupal\Core\Database\Query\Merge;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\RevisionableInterface;
Expand Down Expand Up @@ -131,6 +130,7 @@ function entity_language(string $entity_type, EntityInterface $entity): ?string

/**
* @param array<string, mixed> $elements
* @param-out array $elements
* @return array<string, mixed>
*/
function element_children(array &$elements, bool $sort = false): array
Expand All @@ -147,6 +147,7 @@ function drupal_get_path(string $type, string $name): string

/**
* @param array<string, mixed> $element
* @param-out array $element
* @param string[]|null $children_keys
*/
function drupal_render_children(array &$element, array $children_keys = null): string
Expand All @@ -165,6 +166,7 @@ function drupal_render_children(array &$element, array $children_keys = null): s

/**
* @param array<string, mixed> $elements
* @param-out array $elements
* @phpstan-ignore-next-line
*/
function drupal_render(array &$elements): MarkupInterface|string
Expand Down Expand Up @@ -348,6 +350,7 @@ function drupal_clean_css_identifier(string $identifier, array $filter = [

/**
* @param array<int|string, mixed> $array
* @param-out array $array
* @param array<int, int|string> $parents
*/
function &drupal_array_get_nested_value(array &$array, array $parents, ?bool &$key_exists = null): mixed
Expand All @@ -357,6 +360,7 @@ function &drupal_array_get_nested_value(array &$array, array $parents, ?bool &$k

/**
* @param array<int|string, mixed> $array
* @param-out array $array
* @param array<int, int|string> $parents
*/
function drupal_array_set_nested_value(array &$array, array $parents, mixed $value, bool $force = false): void
Expand Down Expand Up @@ -402,6 +406,7 @@ function drupal_get_query_array(string $query): array
function drupal_goto(string $path = '', array $options = [], int $http_response_code = 302): void
{
\Drupal::moduleHandler()->alter('drupal_goto', $path, $options, $http_response_code);
assert(is_string($path) && is_array($options) && is_int($http_response_code));
$url = \Drupal::pathValidator()->getUrlIfValidWithoutAccessCheck($path);
if ($url !== false) {
$url->mergeOptions($options);
Expand All @@ -426,6 +431,7 @@ function drupal_json_encode(mixed $var): string

/**
* @param array<string, mixed>|object $record
* @param-out array|object $record
* @param string[] $primary_keys
*/
function drupal_write_record(string $table, array|object &$record, array|string $primary_keys = []): int|false
Expand Down
6 changes: 5 additions & 1 deletion src/functions/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@

use Drupal\Core\Form\FormStateInterface;
use Retrofit\Drupal\Form\DrupalGetForm;
use Retrofit\Drupal\Form\FormBuilder;

/**
* @param mixed[] $form_state
* @param-out FormStateInterface $form_state
* @return mixed[]
*/
function drupal_build_form(string $form_id, array &$form_state): array
{
$form_object = \Drupal::classResolver(DrupalGetForm::class);
$form_object->setFormId($form_id);
return \Drupal::formBuilder()->buildForm($form_object, $form_state);
$form_builder = \Drupal::formBuilder();
assert($form_builder instanceof FormBuilder);
return $form_builder->buildForm($form_object, $form_state);
}

function drupal_form_submit(string $form_id, FormStateInterface $form_state): void
Expand Down
2 changes: 2 additions & 0 deletions tests/src/Integration/Database/DrupalWriteRecordTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ public function testWritingRecord(): void
'timestamp' => time(),
];
$result = drupal_write_record('watchdog', $record);
assert(is_array($record));
self::assertEquals(1, $result);
self::assertArrayHasKey('wid', $record);
self::assertEquals(1, $record['wid']);
$record['message'] = 'test2';
$result = drupal_write_record('watchdog', $record, ['wid']);
assert(is_array($record));
self::assertEquals(2, $result);
self::assertArrayHasKey('wid', $record);
self::assertEquals(1, $record['wid']);
Expand Down

0 comments on commit 464fe7f

Please sign in to comment.