Passed
Push — master ( 6f8b91...26ffea )
by Julito
10:53
created

CToolRepository::getResources()   A

Complexity

Conditions 5
Paths 12

Size

Total Lines 52
Code Lines 32

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 32
nc 12
nop 5
dl 0
loc 52
rs 9.0968
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
declare(strict_types=1);
4
5
/* For licensing terms, see /license.txt */
6
7
namespace Chamilo\CourseBundle\Repository;
8
9
use Chamilo\CoreBundle\Entity\Course;
10
use Chamilo\CoreBundle\Entity\ResourceLink;
11
use Chamilo\CoreBundle\Entity\ResourceNode;
12
use Chamilo\CoreBundle\Entity\Session;
13
use Chamilo\CoreBundle\Entity\User;
14
use Chamilo\CoreBundle\Repository\ResourceRepository;
15
use Chamilo\CourseBundle\Entity\CGroup;
16
use Chamilo\CourseBundle\Entity\CTool;
17
use Doctrine\ORM\QueryBuilder;
18
use Doctrine\Persistence\ManagerRegistry;
19
20
final class CToolRepository extends ResourceRepository
21
{
22
    public function __construct(ManagerRegistry $registry)
23
    {
24
        parent::__construct($registry, CTool::class);
25
    }
26
27
    /*public function getResources(User $user, ResourceNode $parentNode, Course $course = null, Session $session = null, CGroup $group = null): QueryBuilder
28
    {
29
        $checker = $this->getAuthorizationChecker();
30
        $reflectionClass = $this->getClassMetadata()->getReflectionClass();
31
32
        // Check if this resource type requires to load the base course resources when using a session
33
        $loadBaseSessionContent = $reflectionClass->hasProperty('loadCourseResourcesInSession');
34
        //$loadBaseSessionContent = true;
35
        //$classes = class_implements($this);
36
37
        $resourceTypeName = $this->getResourceTypeName();
38
        $qb = $this->createQueryBuilder('resource')
39
            ->select('resource')
40
            ->innerJoin(
41
                'resource.resourceNode',
42
                'node'
43
            )
44
            ->innerJoin('node.resourceLinks', 'links')
45
            ->innerJoin('node.resourceType', 'type')
46
            ->where('type.name = :type')
47
            ->setParameter('type', $resourceTypeName)
48
            ->andWhere('links.course = :course')
49
            ->setParameter('course', $course)
50
        ;
51
52
        $isAdmin = $checker->isGranted('ROLE_ADMIN') || $checker->isGranted('ROLE_CURRENT_COURSE_TEACHER');
53
54
        if (!$isAdmin) {
55
            $qb
56
                ->andWhere('links.visibility = :visibility')
57
                ->setParameter('visibility', ResourceLink::VISIBILITY_PUBLISHED)
58
            ;
59
        }
60
61
        if (null === $session) {
62
            $qb->andWhere('links.session IS NULL');
63
        } elseif ($loadBaseSessionContent) {
64
            // Load course base content.
65
            $qb->andWhere('links.session = :session OR links.session IS NULL');
66
            $qb->setParameter('session', $session);
67
        } else {
68
            // Load only session resources.
69
            $qb->andWhere('links.session = :session');
70
            $qb->setParameter('session', $session);
71
        }
72
73
        $qb->andWhere('node.parent = :parentNode');
74
        $qb->setParameter('parentNode', $parentNode);
75
76
        $qb->andWhere('links.group IS NULL');
77
78
        return $qb;
79
    }*/
80
}
81