Passed
Push — master ( 528c5a...0afffa )
by Sylvain
07:58
created

SubscribeNewsletter   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 85.71%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
dl 0
loc 28
ccs 12
cts 14
cp 0.8571
rs 10
c 1
b 0
f 0
wmc 2

1 Method

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