Passed
Pull Request — master (#5143)
by Angel Fernando Quiroz
13:34 queued 06:28
created

ResourceLinkRepository::remove()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
nc 1
nop 1
dl 0
loc 11
rs 10
c 1
b 0
f 0
1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
declare(strict_types=1);
6
7
namespace Chamilo\CoreBundle\Repository;
8
9
use Chamilo\CoreBundle\Entity\ResourceLink;
10
use Doctrine\ORM\EntityManagerInterface;
11
use Gedmo\Sortable\Entity\Repository\SortableRepository;
12
13
class ResourceLinkRepository extends SortableRepository
14
{
15
    public function __construct(EntityManagerInterface $em)
16
    {
17
        parent::__construct($em, $em->getClassMetadata(ResourceLink::class));
18
    }
19
20
    public function remove(ResourceLink $resourceLink): void
21
    {
22
        $em = $this->getEntityManager();
23
24
        // To move the resource link at the end to reorder the list
25
        $resourceLink->setDisplayOrder(-1);
26
27
        $em->flush();
28
        // soft delete handled by Gedmo\SoftDeleteable
29
        $em->remove($resourceLink);
30
        $em->flush();
31
    }
32
}
33