Assert class instances of collection items

This commit is contained in:
Oliver Davies 2025-06-12 02:10:09 +01:00
parent 5ac1a6d95a
commit c84e6ed25c
3 changed files with 10 additions and 0 deletions

View file

@ -5,6 +5,7 @@ declare(strict_types=1);
namespace Drupal\opd_daily_emails; namespace Drupal\opd_daily_emails;
use Drupal\node\NodeInterface; use Drupal\node\NodeInterface;
use Webmozart\Assert\Assert;
final class DailyEmails implements \Countable { final class DailyEmails implements \Countable {
@ -14,6 +15,7 @@ final class DailyEmails implements \Countable {
private function __construct( private function __construct(
private array $emails, private array $emails,
) { ) {
Assert::allIsInstanceOf($emails, NodeInterface::class);
} }
public function count(): int { public function count(): int {

View file

@ -4,6 +4,9 @@ declare(strict_types=1);
namespace Drupal\opd_podcast; namespace Drupal\opd_podcast;
use Webmozart\Assert\Assert;
/** /**
* @implements \IteratorAggregate<Guest> * @implements \IteratorAggregate<Guest>
*/ */
@ -13,6 +16,7 @@ final class Guests implements \Countable, \IteratorAggregate, \Stringable {
* @param Guest[] $guests * @param Guest[] $guests
*/ */
private function __construct(private array $guests) { private function __construct(private array $guests) {
Assert::allIsInstanceOf($guests, Guest::class);
} }
public function count(): int { public function count(): int {

View file

@ -4,6 +4,9 @@ declare(strict_types=1);
namespace Drupal\opd_presentations; namespace Drupal\opd_presentations;
use Webmozart\Assert\Assert;
/** /**
* @implements \IteratorAggregate<Event> * @implements \IteratorAggregate<Event>
*/ */
@ -13,6 +16,7 @@ readonly final class Events implements \IteratorAggregate {
* @param Event[] $events * @param Event[] $events
*/ */
private function __construct(private array $events) { private function __construct(private array $events) {
Assert::allIsInstanceOf($events, Event::class);
} }
public function filter(\Closure $callback): self { public function filter(\Closure $callback): self {