Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
| Total | |
100.00% |
9 / 9 |
|
100.00% |
3 / 3 |
|
100.00% |
3 / 3 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| ContactService | |
100.00% |
9 / 9 |
|
100.00% |
3 / 3 |
|
100.00% |
3 / 3 |
|
100.00% |
3 / 3 |
3 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| save | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| create | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Service\Data; |
| 4 | |
| 5 | use App\Dto\Command\CreateContactCommand; |
| 6 | use App\Entity\Contact; |
| 7 | use Doctrine\ORM\EntityManagerInterface; |
| 8 | use Psr\Clock\ClockInterface; |
| 9 | |
| 10 | /** |
| 11 | * @author Wilhelm Zwertvaegher |
| 12 | */ |
| 13 | readonly class ContactService implements ContactServiceInterface |
| 14 | { |
| 15 | public function __construct( |
| 16 | private EntityManagerInterface $entityManager, |
| 17 | private ClockInterface $clock, |
| 18 | ) { |
| 19 | } |
| 20 | |
| 21 | public function save(Contact $contact): void |
| 22 | { |
| 23 | $this->entityManager->persist($contact); |
| 24 | } |
| 25 | |
| 26 | public function create(CreateContactCommand $command): Contact |
| 27 | { |
| 28 | $contact = new Contact( |
| 29 | senderEmail: $command->getSenderEmail(), |
| 30 | content: $command->getContent(), |
| 31 | createdAt: $this->clock->now() |
| 32 | ); |
| 33 | |
| 34 | $this->save($contact); |
| 35 | |
| 36 | return $contact; |
| 37 | } |
| 38 | } |