SubscriptionRepository   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 88.89%

Importance

Changes 0
Metric Value
wmc 3
c 0
b 0
f 0
lcom 0
cbo 5
dl 0
loc 41
ccs 8
cts 9
cp 0.8889
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 0 4 1
A getUserSubscribersCountById() 0 11 1
A removeSubscribers() 0 12 1
1
<?php
2
3
namespace Skobkin\Bundle\PointToolsBundle\Repository;
4
5
use Doctrine\ORM\EntityRepository;
6
use Skobkin\Bundle\PointToolsBundle\Entity\Subscription;
7
use Skobkin\Bundle\PointToolsBundle\Entity\User;
8
9
class SubscriptionRepository extends EntityRepository
10
{
11
    public function add(Subscription $entity): void
12
    {
13
        $this->getEntityManager()->persist($entity);
14
    }
15 4
16
    /**
17 4
     * @param int $id
18
     *
19
     * @return int
20
     */
21 4
    public function getUserSubscribersCountById(int $id): int
22
    {
23 4
        $qb = $this->createQueryBuilder('s');
24 4
        return $qb
25 4
            ->select('COUNT(s.subscriber)')
26 4
            ->innerJoin('s.author', 'sa')
27 4
            ->where('sa.id = :id')
28
            ->setParameter('id', $id)
29
            ->getQuery()->getSingleScalarResult()
30
        ;
31
    }
32
33
    /**
34
     * @param User $user
35
     * @param User[] $subscribers
36
     */
37
    public function removeSubscribers(User $user, array $subscribers): void
38
    {
39
        $qb = $this->createQueryBuilder('s');
40
        $qb
41
            ->delete()
42
            ->where('s.author = :author')
43
            ->andWhere('s.subscriber IN (:subscribers)')
44
            ->setParameter('author', $user->getId())
45
            ->setParameter('subscribers', $subscribers)
46
            ->getQuery()->execute();
47
        ;
48
    }
49
}