Passed
Branch develop (7f369c)
by Nicolas
04:17
created

ProfilesUnfollowController   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 __construct() 0 3 1
A __invoke() 0 8 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
 * @Route("/api/profiles/{username}/follow", name="api_profiles_unfollow")
13
 * @Method("DELETE")
14
 */
15
class ProfilesUnfollowController
16
{
17
    /**
18
     * @var EntityManagerInterface
19
     */
20
    private $manager;
21
22
    /**
23
     * @param EntityManagerInterface $manager
24
     */
25 1
    public function __construct(EntityManagerInterface $manager)
26
    {
27 1
        $this->manager = $manager;
28 1
    }
29
30
    /**
31
     * @param UserInterface $user
32
     * @param User          $profile
33
     *
34
     * @return array
35
     */
36 1
    public function __invoke(UserInterface $user, User $profile)
37
    {
38
        /* @var User $user */
39
40 1
        $user->unfollow($profile);
41 1
        $this->manager->flush();
42
43 1
        return ['profile' => $profile];
44
    }
45
}
46