Refactor
Try a different way of naming and grouping classes.
This commit is contained in:
parent
52c1b33711
commit
6b6b362a49
15 changed files with 111 additions and 59 deletions
|
@ -4,7 +4,7 @@ declare(strict_types=1);
|
|||
|
||||
use Drupal\Core\Render\BubbleableMetadata;
|
||||
use Drupal\Core\StringTranslation\TranslatableMarkup;
|
||||
use Drupal\opd_daily_emails\Repository\DailyEmailNodeRepository;
|
||||
use Drupal\opd_daily_emails\DailyEmailNodeRepository;
|
||||
|
||||
/**
|
||||
* Implements hook_token_info().
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
services:
|
||||
Drupal\opd_daily_emails\Repository\DailyEmailNodeRepository:
|
||||
Drupal\opd_daily_emails\DailyEmailNodeRepository:
|
||||
autowire: true
|
||||
|
|
|
@ -2,11 +2,10 @@
|
|||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Drupal\opd_daily_emails\Repository;
|
||||
namespace Drupal\opd_daily_emails;
|
||||
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\node\NodeInterface;
|
||||
use Drupal\opd_daily_emails\Collection\DailyEmailCollection;
|
||||
|
||||
final class DailyEmailNodeRepository implements DailyEmailRepositoryInterface {
|
||||
|
||||
|
@ -15,7 +14,7 @@ final class DailyEmailNodeRepository implements DailyEmailRepositoryInterface {
|
|||
) {
|
||||
}
|
||||
|
||||
public function getAll(): DailyEmailCollection {
|
||||
public function getAll(): DailyEmails {
|
||||
$nodeStorage = $this->entityTypeManager
|
||||
->getStorage('node');
|
||||
|
||||
|
@ -31,7 +30,7 @@ final class DailyEmailNodeRepository implements DailyEmailRepositoryInterface {
|
|||
/** @var NodeInterface[] */
|
||||
$nodes = $nodeStorage->loadMultiple($nodeIds);
|
||||
|
||||
return new DailyEmailCollection($nodes);
|
||||
return DailyEmails::new($nodes);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Drupal\opd_daily_emails;
|
||||
|
||||
interface DailyEmailRepositoryInterface {
|
||||
|
||||
public function getAll(): DailyEmails;
|
||||
|
||||
}
|
|
@ -2,16 +2,16 @@
|
|||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Drupal\opd_daily_emails\Collection;
|
||||
namespace Drupal\opd_daily_emails;
|
||||
|
||||
use Drupal\node\NodeInterface;
|
||||
|
||||
final class DailyEmailCollection implements \Countable {
|
||||
final class DailyEmails implements \Countable {
|
||||
|
||||
/**
|
||||
* @param array<positive-int, NodeInterface> $emails
|
||||
*/
|
||||
public function __construct(
|
||||
private function __construct(
|
||||
private array $emails,
|
||||
) {
|
||||
}
|
||||
|
@ -24,4 +24,8 @@ final class DailyEmailCollection implements \Countable {
|
|||
return array_values($this->emails)[0];
|
||||
}
|
||||
|
||||
public static function new(array $emails): self {
|
||||
return new self($emails);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Drupal\opd_daily_emails\Repository;
|
||||
|
||||
use Drupal\opd_daily_emails\Collection\DailyEmailCollection;
|
||||
|
||||
interface DailyEmailRepositoryInterface {
|
||||
|
||||
public function getAll(): DailyEmailCollection;
|
||||
|
||||
}
|
|
@ -2,14 +2,14 @@
|
|||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Drupal\Tests\opd_daily_emails\Kernel\Repository;
|
||||
namespace Drupal\Tests\opd_daily_emails\Kernel;
|
||||
|
||||
use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
|
||||
use Drupal\Tests\node\Traits\NodeCreationTrait;
|
||||
use Drupal\Tests\opd_daily_emails\Traits\DailyEmailTestTrait;
|
||||
use Drupal\node\NodeInterface;
|
||||
use Drupal\opd_daily_emails\Repository\DailyEmailNodeRepository;
|
||||
use Drupal\opd_daily_emails\Repository\DailyEmailRepositoryInterface;
|
||||
use Drupal\opd_daily_emails\DailyEmailNodeRepository;
|
||||
use Drupal\opd_daily_emails\DailyEmailRepositoryInterface;
|
||||
|
||||
final class DailyEmailNodeRepositoryTest extends EntityKernelTestBase {
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue