Fix phpstan errors

This commit is contained in:
Oliver Davies 2025-06-15 17:22:37 +01:00
parent af83b3c431
commit 229cc62b03
8 changed files with 16 additions and 17 deletions

View file

@ -27,7 +27,7 @@ final class DailyEmailNodeRepository implements DailyEmailRepositoryInterface {
$nodeIds = $query->execute(); $nodeIds = $query->execute();
/** @var NodeInterface[] */ /** @var DailyEmail[] */
$nodes = $nodeStorage->loadMultiple($nodeIds); $nodes = $nodeStorage->loadMultiple($nodeIds);
return DailyEmails::fromEmails($nodes); return DailyEmails::fromEmails($nodes);

View file

@ -17,12 +17,15 @@ final class DailyEmails implements \Countable {
return array_values($this->emails)[0]; return array_values($this->emails)[0];
} }
/**
* @param DailyEmail[] $emails
*/
public static function fromEmails(array $emails): self { public static function fromEmails(array $emails): self {
return new self($emails); return new self($emails);
} }
/** /**
* @param array<positive-int, NodeInterface> $emails * @param array<positive-int, DailyEmail> $emails
*/ */
private function __construct( private function __construct(
private array $emails, private array $emails,

View file

@ -36,8 +36,12 @@ final class CallToActionTest extends ExistingSiteBase {
$email->set('title', 'Updated'); $email->set('title', 'Updated');
$email->save(); $email->save();
$value = $email->get('field_daily_email_cta')->getValue();
assert(is_array($value));
assert(isset($value[0]['target_id']));
$this->assertSame( $this->assertSame(
actual: $email->get('field_daily_email_cta')->getValue()[0]['target_id'], actual: $value[0]['target_id'],
expected: $cta->id(), expected: $cta->id(),
); );
} }

View file

@ -23,17 +23,17 @@ class DailyEmailTokenTest extends BrowserTestBase {
public function test_the_token_returns_the_number_of_published_daily_emails(): void { public function test_the_token_returns_the_number_of_published_daily_emails(): void {
$this->createDailyEmailNode( $this->createDailyEmailNode(
isPublished: TRUE, isPublished: TRUE,
title: $this->randomString(), title: 'a',
); );
$this->createDailyEmailNode( $this->createDailyEmailNode(
isPublished: FALSE, isPublished: FALSE,
title: $this->randomString(), title: 'b',
); );
$this->createDailyEmailNode( $this->createDailyEmailNode(
isPublished: TRUE, isPublished: TRUE,
title: $this->randomString(), title: 'c',
); );
$this->assertToken( $this->assertToken(

View file

@ -19,7 +19,7 @@ final class Guests implements \Countable, \IteratorAggregate, \Stringable {
return sprintf('%s %s %s', $this->first()->getName(), t('and'), $this->get(1)->getName()); return sprintf('%s %s %s', $this->first()->getName(), t('and'), $this->get(1)->getName());
} }
return strval($this->first()->getName()); return strval($this->first()?->getName());
} }
public function count(): int { public function count(): int {
@ -48,7 +48,7 @@ final class Guests implements \Countable, \IteratorAggregate, \Stringable {
Assert::allIsInstanceOf($guests, Guest::class); Assert::allIsInstanceOf($guests, Guest::class);
} }
private function get(int $offset): ?Guest { private function get(int $offset): Guest {
return $this->guests[$offset]; return $this->guests[$offset];
} }

View file

@ -35,9 +35,6 @@ readonly final class Events implements \Countable, \IteratorAggregate {
->filter(fn (Event $event): bool => $event->isPast()); ->filter(fn (Event $event): bool => $event->isPast());
} }
/**
* @param non-empty-string[] $dates
*/
public static function fromDateStrings(string ...$dates): self { public static function fromDateStrings(string ...$dates): self {
$events = array_map( $events = array_map(
array: $dates, array: $dates,

View file

@ -9,8 +9,6 @@ use Drupal\node\NodeInterface;
final class PresentationCounter { final class PresentationCounter {
private array $presentations;
public function __construct(private EntityTypeManagerInterface $entityTypeManager) { public function __construct(private EntityTypeManagerInterface $entityTypeManager) {
} }
@ -24,6 +22,7 @@ final class PresentationCounter {
$nodeIds = $query->execute(); $nodeIds = $query->execute();
/** @var Presentation[] */
$presentations = $nodeStorage->loadMultiple($nodeIds); $presentations = $nodeStorage->loadMultiple($nodeIds);
return array_reduce( return array_reduce(

View file

@ -16,10 +16,6 @@ trait PresentationCreationTrait {
use EntityCreationTrait; use EntityCreationTrait;
use NodeCreationTrait; use NodeCreationTrait;
/**
* @param Event[] $events
* @param bool $isPublished
*/
private function createPresentation(Events $events, bool $isPublished = TRUE): Presentation { private function createPresentation(Events $events, bool $isPublished = TRUE): Presentation {
$presentation = $this->createNode([ $presentation = $this->createNode([
'field_events' => $events->toEvents(), 'field_events' => $events->toEvents(),