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();
/** @var NodeInterface[] */
/** @var DailyEmail[] */
$nodes = $nodeStorage->loadMultiple($nodeIds);
return DailyEmails::fromEmails($nodes);

View file

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

View file

@ -36,8 +36,12 @@ final class CallToActionTest extends ExistingSiteBase {
$email->set('title', 'Updated');
$email->save();
$value = $email->get('field_daily_email_cta')->getValue();
assert(is_array($value));
assert(isset($value[0]['target_id']));
$this->assertSame(
actual: $email->get('field_daily_email_cta')->getValue()[0]['target_id'],
actual: $value[0]['target_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 {
$this->createDailyEmailNode(
isPublished: TRUE,
title: $this->randomString(),
title: 'a',
);
$this->createDailyEmailNode(
isPublished: FALSE,
title: $this->randomString(),
title: 'b',
);
$this->createDailyEmailNode(
isPublished: TRUE,
title: $this->randomString(),
title: 'c',
);
$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 strval($this->first()->getName());
return strval($this->first()?->getName());
}
public function count(): int {
@ -48,7 +48,7 @@ final class Guests implements \Countable, \IteratorAggregate, \Stringable {
Assert::allIsInstanceOf($guests, Guest::class);
}
private function get(int $offset): ?Guest {
private function get(int $offset): Guest {
return $this->guests[$offset];
}

View file

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

View file

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

View file

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