ThreadRepository   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 55
ccs 21
cts 21
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A createNew() 0 9 1
A findThreadById() 0 4 1
A findThreadsByIds() 0 12 1
A findThread() 0 4 1
A delete() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of Sulu.
5
 *
6
 * (c) MASSIVE ART WebServices GmbH
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Sulu\Bundle\CommentBundle\Entity;
13
14
use Doctrine\ORM\EntityRepository;
15
16
/**
17
 * Repository for querying comments.
18
 */
19
class ThreadRepository extends EntityRepository implements ThreadRepositoryInterface
20
{
21
    /**
22
     * {@inheritdoc}
23
     */
24 5
    public function createNew($type, $entityId)
25
    {
26 5
        $className = $this->getClassName();
27
28 5
        $thread = new $className($type, $entityId);
29 5
        $this->getEntityManager()->persist($thread);
30
31 5
        return $thread;
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37 2
    public function findThreadById($id)
38
    {
39 2
        return $this->find($id);
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45 2
    public function findThreadsByIds($ids)
46
    {
47 2
        $query = $this->createQueryBuilder('t')
48 2
            ->leftJoin('t.comments', 'c')
49 2
            ->leftJoin('t.creator', 'creator')
50 2
            ->leftJoin('t.changer', 'changer')
51 2
            ->where('t.id IN (:ids)')
52 2
            ->setParameter('ids', $ids)
53 2
            ->getQuery();
54
55 2
        return $query->getResult();
56
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61 5
    public function findThread($type, $entityId)
62
    {
63 5
        return $this->findOneBy(['type' => $type, 'entityId' => $entityId]);
64
    }
65
66
    /**
67
     * {@inheritdoc}
68
     */
69 2
    public function delete(ThreadInterface $thread)
70
    {
71 2
        $this->getEntityManager()->remove($thread);
72 2
    }
73
}
74