Conditions | 7 |
Paths | 18 |
Total Lines | 65 |
Code Lines | 37 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
35 | private function addWhere(QueryBuilder $queryBuilder, string $resourceClass): void |
||
36 | { |
||
37 | if (CToolIntro::class !== $resourceClass) { |
||
38 | return; |
||
39 | } |
||
40 | |||
41 | /*if ($this->security->isGranted('ROLE_ADMIN')) { |
||
42 | return; |
||
43 | }*/ |
||
44 | |||
45 | if (null === $user = $this->security->getUser()) { |
||
46 | throw new AccessDeniedException('Access Denied.'); |
||
47 | } |
||
48 | |||
49 | $request = $this->requestStack->getCurrentRequest(); |
||
50 | |||
51 | $courseId = $request->query->get('cid'); |
||
52 | $sessionId = $request->query->get('sid'); |
||
53 | $groupId = $request->query->get('gid'); |
||
54 | |||
55 | $rootAlias = $queryBuilder->getRootAliases()[0]; |
||
56 | |||
57 | $queryBuilder |
||
58 | ->innerJoin("$rootAlias.resourceNode", 'node') |
||
59 | ->innerJoin('node.resourceLinks', 'links') |
||
60 | ; |
||
61 | |||
62 | // Do not show deleted resources. |
||
63 | $queryBuilder |
||
64 | ->andWhere('links.visibility != :visibilityDeleted') |
||
65 | ->setParameter('visibilityDeleted', ResourceLink::VISIBILITY_DELETED) |
||
66 | ; |
||
67 | |||
68 | $allowDraft = |
||
69 | $this->security->isGranted('ROLE_ADMIN') || |
||
70 | $this->security->isGranted('ROLE_CURRENT_COURSE_TEACHER') |
||
71 | ; |
||
72 | |||
73 | if (!$allowDraft) { |
||
74 | $queryBuilder |
||
75 | ->andWhere('links.visibility != :visibilityDraft') |
||
76 | ->setParameter('visibilityDraft', ResourceLink::VISIBILITY_DRAFT) |
||
77 | ; |
||
78 | } |
||
79 | |||
80 | $queryBuilder |
||
81 | ->andWhere('links.course = :course') |
||
82 | ->setParameter('course', $courseId) |
||
83 | ; |
||
84 | |||
85 | if (empty($sessionId)) { |
||
86 | $queryBuilder->andWhere('links.session IS NULL'); |
||
87 | } else { |
||
88 | $queryBuilder |
||
89 | ->andWhere('links.session = :session') |
||
90 | ->setParameter('session', $sessionId) |
||
91 | ; |
||
92 | } |
||
93 | |||
94 | if (empty($groupId)) { |
||
95 | $queryBuilder->andWhere('links.group IS NULL'); |
||
96 | } else { |
||
97 | $queryBuilder |
||
98 | ->andWhere('links.group = :group') |
||
99 | ->setParameter('group', $groupId) |
||
100 | ; |
||
104 |