SubscribeNewsletter   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 86.67%

Importance

Changes 0
Metric Value
wmc 2
eloc 15
dl 0
loc 25
ccs 13
cts 15
cp 0.8667
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A build() 0 23 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Application\Api\Field\Mutation;
6
7
use Application\Service\MessageQueuer;
8
use Ecodev\Felix\Api\Field\FieldInterface;
9
use Ecodev\Felix\Api\Scalar\EmailType;
10
use Ecodev\Felix\Service\Mailer;
11
use GraphQL\Type\Definition\Type;
12
use Mezzio\Session\SessionInterface;
13
14
abstract class SubscribeNewsletter implements FieldInterface
15
{
16 1
    public static function build(): iterable
17
    {
18 1
        yield 'subscribeNewsletter' => fn () => [
19 1
            'type' => Type::nonNull(Type::boolean()),
20 1
            'description' => 'Subscribe to newsletter.',
21 1
            'args' => [
22 1
                'email' => Type::nonNull(_types()->get(EmailType::class)),
23 1
            ],
24 1
            'resolve' => function ($root, array $args, SessionInterface $session): bool {
25 1
                $email = $args['email'];
26
                global $container;
27
                /** @var Mailer $mailer */
28 1
                $mailer = $container->get(Mailer::class);
29
30
                /** @var MessageQueuer $messageQueuer */
31 1
                $messageQueuer = $container->get(MessageQueuer::class);
32
33 1
                foreach ($messageQueuer->getAllEmailsToNotify() as $adminEmail) {
34
                    $message = $messageQueuer->queueNewsletterSubscription($adminEmail, $email);
35
                    $mailer->sendMessageAsync($message);
36
                }
37
38 1
                return true;
39 1
            },
40 1
        ];
41
    }
42
}
43