Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
| Total | |
92.31% |
12 / 13 |
|
75.00% |
3 / 4 |
|
66.67% |
2 / 3 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| ContactNotificationPropsBuilder | |
92.31% |
12 / 13 |
|
75.00% |
3 / 4 |
|
66.67% |
2 / 3 |
|
50.00% |
1 / 2 |
3.33 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| buildProps | |
91.67% |
11 / 12 |
|
66.67% |
2 / 3 |
|
50.00% |
1 / 2 |
|
0.00% |
0 / 1 |
2.50 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Service\Notification\Factory; |
| 4 | |
| 5 | use App\Entity\Contact; |
| 6 | use App\Enum\NotificationType; |
| 7 | use Symfony\Component\DependencyInjection\Attribute\AsTaggedItem; |
| 8 | use Symfony\Component\DependencyInjection\Attribute\Autowire; |
| 9 | |
| 10 | /** |
| 11 | * @author Wilhelm Zwertvaegher |
| 12 | */ |
| 13 | #[AsTaggedItem(index: Contact::class)] |
| 14 | readonly class ContactNotificationPropsBuilder implements NotificationPropsBuilder |
| 15 | { |
| 16 | public function __construct( |
| 17 | #[Autowire('%recipient.admin%')] |
| 18 | private string $adminEmail, |
| 19 | ) { |
| 20 | } |
| 21 | |
| 22 | public function buildProps(object $source): NotificationProps |
| 23 | { |
| 24 | if (!is_a($source, Contact::class)) { |
| 25 | throw new \InvalidArgumentException('$source must be a Contact'); |
| 26 | } |
| 27 | |
| 28 | return new NotificationProps( |
| 29 | NotificationType::CONTACT, |
| 30 | $this->adminEmail, |
| 31 | 'Site contact', |
| 32 | sprintf( |
| 33 | "A contact form has been submitted to you :from: %s\ncontent : %s", |
| 34 | $source->getSenderEmail(), |
| 35 | $source->getContent() |
| 36 | ), |
| 37 | ); |
| 38 | } |
| 39 | } |