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

ProfilesFollowController::__invoke()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 8
ccs 4
cts 4
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
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