MemberManager::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Manager\Community;
4
5
use Doctrine\ORM\EntityManagerInterface;
6
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
7
8
use App\Entity\Community\{
9
    Community,
10
    Member
11
};
12
use App\Entity\User\User;
13
14
use App\Event\Community\NewMemberEvent;
15
16
class MemberManager
17
{
18
    /** @var EntityManagerInterface **/
19
    protected $em;
20
    /** @var EventDispatcherInterface **/
21
    protected $eventDispatcher;
22
23
24 9
    public function __construct(EntityManagerInterface $em, EventDispatcherInterface $eventDispatcher)
25
    {
26 9
        $this->em = $em;
27 9
        $this->eventDispatcher = $eventDispatcher;
28 9
    }
29
    
30 1
    public function getCommunityMembers(Community $community): array
31
    {
32 1
        return $this->em->getRepository(Member::class)->findByCommunity($community);
0 ignored issues
show
Bug introduced by
The method findByCommunity() does not exist on Doctrine\Common\Persistence\ObjectRepository. Did you maybe mean findBy()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

32
        return $this->em->getRepository(Member::class)->/** @scrutinizer ignore-call */ findByCommunity($community);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
33
    }
34
    
35 2
    public function getMemberCommunities(User $user): array
36
    {
37 2
        return $this->em->getRepository(Member::class)->findByUser($user);
0 ignored issues
show
Bug introduced by
The method findByUser() does not exist on Doctrine\Common\Persistence\ObjectRepository. Did you maybe mean findBy()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

37
        return $this->em->getRepository(Member::class)->/** @scrutinizer ignore-call */ findByUser($user);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
38
    }
39
    
40 3
    public function createMembership(Community $community, User $user, bool $isLead = false, bool $isNews = true): Member
41
    {
42
        $membership =
43 3
            (new Member())
44 3
            ->setCommunity($community)
45 3
            ->setUser($user)
46 3
            ->setIsLead($isLead)
47
        ;
48 3
        $this->em->persist($membership);
49 3
        $this->em->flush($membership);
50 3
        if ($isNews === true) {
51 2
            $this->eventDispatcher->dispatch(NewMemberEvent::NAME, new NewMemberEvent($community, $user));
52
        }
53 3
        return $membership;
54
    }
55
}