Completed
Branch develop (7f369c)
by Nicolas
04:28
created

ProfilesFollowController   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

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