| Conditions | 7 |
| Paths | 7 |
| Total Lines | 61 |
| Code Lines | 36 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
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 |
||
| 44 | private function addWhere(QueryBuilder $queryBuilder, string $resourceClass): void |
||
| 45 | { |
||
| 46 | if (CDocument::class !== $resourceClass) { |
||
| 47 | return; |
||
| 48 | } |
||
| 49 | |||
| 50 | if ($this->security->isGranted('ROLE_ADMIN')) { |
||
| 51 | return; |
||
| 52 | } |
||
| 53 | |||
| 54 | if (null === $user = $this->security->getUser()) { |
||
| 55 | return; |
||
| 56 | } |
||
| 57 | |||
| 58 | $request = $this->requestStack->getCurrentRequest(); |
||
| 59 | |||
| 60 | // Listing documents must contain the resource node parent (resourceNode.parent) and the course (cid) |
||
| 61 | // At least the cid so the CourseListener can be called. |
||
| 62 | $resourceParentId = $request->query->get('resourceNode_parent'); |
||
| 63 | $courseId = $request->query->get('cid'); |
||
| 64 | $sessionId = $request->query->get('sid'); |
||
| 65 | $groupId = $request->query->get('gid'); |
||
| 66 | |||
| 67 | if (empty($resourceParentId)) { |
||
| 68 | throw new AccessDeniedException('resourceNode.parent is required'); |
||
| 69 | } |
||
| 70 | |||
| 71 | if (empty($courseId)) { |
||
| 72 | throw new AccessDeniedException('cid is required'); |
||
| 73 | } |
||
| 74 | |||
| 75 | error_log('addWhere'); |
||
| 76 | error_log('here!'); |
||
| 77 | $rootAlias = $queryBuilder->getRootAliases()[0]; |
||
| 78 | |||
| 79 | $queryBuilder |
||
| 80 | ->innerJoin("$rootAlias.resourceNode", 'node') |
||
| 81 | ->innerJoin('node.resourceLinks', 'links') |
||
| 82 | ; |
||
| 83 | |||
| 84 | $queryBuilder |
||
| 85 | ->andWhere('links.visibility != :visibilityDeleted') |
||
| 86 | ->setParameter('visibilityDeleted', ResourceLink::VISIBILITY_DELETED) |
||
| 87 | ; |
||
| 88 | |||
| 89 | $queryBuilder |
||
| 90 | ->andWhere('links.visibility != :visibilityDraft') |
||
| 91 | ->setParameter('visibilityDraft', ResourceLink::VISIBILITY_DRAFT) |
||
| 92 | ; |
||
| 93 | |||
| 94 | $queryBuilder |
||
| 95 | ->andWhere('links.course = :course') |
||
| 96 | ->setParameter('course', $courseId) |
||
| 97 | ; |
||
| 98 | |||
| 99 | if (empty($sessionId)) { |
||
| 100 | $queryBuilder->andWhere('links.session IS NULL'); |
||
| 101 | } else { |
||
| 102 | $queryBuilder |
||
| 103 | ->andWhere('links.session = :session') |
||
| 104 | ->setParameter('session', $sessionId); |
||
| 105 | } |
||
| 115 |