Passed
Push — master ( 719760...59ab2e )
by Angel Fernando Quiroz
18:35
created

CToolIntroExtension::addWhere()   B

Complexity

Conditions 7
Paths 18

Size

Total Lines 65
Code Lines 37

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 37
c 0
b 0
f 0
nc 18
nop 2
dl 0
loc 65
rs 8.3946

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
/* For licensing terms, see /license.txt */
4
5
declare(strict_types=1);
6
7
namespace Chamilo\CoreBundle\DataProvider\Extension;
8
9
use ApiPlatform\Doctrine\Orm\Extension\QueryCollectionExtensionInterface;
10
use ApiPlatform\Doctrine\Orm\Util\QueryNameGeneratorInterface;
11
use ApiPlatform\Metadata\Operation;
12
use Chamilo\CourseBundle\Entity\CToolIntro;
13
use Doctrine\ORM\QueryBuilder;
14
use Symfony\Component\HttpFoundation\RequestStack;
15
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
16
use Symfony\Component\Security\Core\Security;
17
18
// use ApiPlatform\Core\Bridge\Doctrine\Orm\Extension\QueryItemExtensionInterface;
19
20
final class CToolIntroExtension implements QueryCollectionExtensionInterface
21
{
22
    use CourseLinkExtensionTrait;
23
24
    public function __construct(
25
        private readonly Security $security,
26
        private readonly RequestStack $requestStack
27
    ) {}
28
29
    public function applyToCollection(
30
        QueryBuilder $queryBuilder,
31
        QueryNameGeneratorInterface $queryNameGenerator,
32
        string $resourceClass,
33
        Operation $operation = null,
34
        array $context = []
35
    ): void {
36
        if (CToolIntro::class !== $resourceClass) {
37
            return;
38
        }
39
40
        if (null === $user = $this->security->getUser()) {
41
            throw new AccessDeniedException('Access Denied.');
42
        }
43
44
        $request = $this->requestStack->getCurrentRequest();
45
46
        $courseId = $request->query->getInt('cid');
47
        $sessionId = $request->query->getInt('sid');
48
        $groupId = $request->query->getInt('gid');
49
50
        $this->addCourseLinkWithVisibilityConditions($queryBuilder, true, $courseId, $sessionId, $groupId);
51
    }
52
}
53