Passed
Branch master (1fd71c)
by Nicolas
03:28
created

FollowProfileController   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

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