Passed
Push — master ( 0171d8...f6fed5 )
by Nicolas
05:33
created

FollowProfileController   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 9
c 0
b 0
f 0
dl 0
loc 19
ccs 9
cts 9
cp 1
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __invoke() 0 8 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Controller\Profile;
6
7
use App\Entity\User;
8
use App\Security\UserResolver;
9
use Doctrine\ORM\EntityManagerInterface;
10
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
11
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
12
use Symfony\Component\Routing\Annotation\Route;
13
14
/**
15
 * @Route("/api/profiles/{username}/follow", methods={"POST"}, name="api_profiles_follow")
16
 *
17
 * @Security("is_granted('ROLE_USER')")
18
 */
19
final class FollowProfileController extends AbstractController
20
{
21
    private UserResolver $userResolver;
22
    private EntityManagerInterface $entityManager;
23
24 2
    public function __construct(UserResolver $userResolver, EntityManagerInterface $entityManager)
25
    {
26 2
        $this->userResolver = $userResolver;
27 2
        $this->entityManager = $entityManager;
28 2
    }
29
30 1
    public function __invoke(User $profile): array
31
    {
32 1
        $user = $this->userResolver->getCurrentUser();
33 1
        $user->follow($profile);
34
35 1
        $this->entityManager->flush();
36
37 1
        return ['profile' => $profile];
38
    }
39
}
40