Passed
Pull Request — master (#6835)
by Angel Fernando Quiroz
10:09
created

PortfolioAttachmentRepository   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 36
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A findFromItem() 0 6 1
A removeFromComment() 0 6 2
A findFromComment() 0 6 1
A __construct() 0 3 1
1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
namespace Chamilo\CoreBundle\Repository;
6
7
use Chamilo\CoreBundle\Entity\Portfolio;
8
use Chamilo\CoreBundle\Entity\PortfolioAttachment;
9
use Chamilo\CoreBundle\Entity\PortfolioComment;
10
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
11
use Doctrine\Persistence\ManagerRegistry;
12
13
class PortfolioAttachmentRepository extends ServiceEntityRepository
14
{
15
    public function __construct(ManagerRegistry $registry)
16
    {
17
        parent::__construct($registry, PortfolioAttachment::class);
18
    }
19
20
    public function findFromItem(Portfolio $item): array
21
    {
22
        return $this->findBy(
23
            [
24
                'origin' => $item->getId(),
25
                'originType' => PortfolioAttachment::TYPE_ITEM,
26
            ]
27
        );
28
    }
29
30
    /**
31
     * @return array<int, PortfolioComment>
32
     */
33
    public function findFromComment(PortfolioComment $comment): array
34
    {
35
        return $this->findBy(
36
            [
37
                'origin' => $comment->getId(),
38
                'originType' => PortfolioAttachment::TYPE_COMMENT,
39
            ]
40
        );
41
    }
42
43
    public function removeFromComment(PortfolioComment $comment): void
44
    {
45
        $comments = $this->findFromComment($comment);
46
47
        foreach ($comments as $comment) {
48
            $this->_em->remove($comment);
49
        }
50
    }
51
}
52