| Conditions | 5 |
| Paths | 6 |
| Total Lines | 72 |
| Code Lines | 40 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 57 | private function addWhere(QueryBuilder $qb, string $resourceClass): void |
||
| 58 | { |
||
| 59 | if (CCalendarEvent::class !== $resourceClass) { |
||
| 60 | return; |
||
| 61 | } |
||
| 62 | |||
| 63 | /*if ($this->security->isGranted('ROLE_ADMIN')) { |
||
| 64 | return; |
||
| 65 | }*/ |
||
| 66 | |||
| 67 | /** @var User $user */ |
||
| 68 | $user = $this->security->getUser(); |
||
| 69 | $alias = $qb->getRootAliases()[0]; |
||
| 70 | |||
| 71 | $qb |
||
| 72 | ->innerJoin("$alias.resourceNode", 'node') |
||
| 73 | ->leftJoin('node.resourceLinks', 'links') |
||
| 74 | ; |
||
| 75 | |||
| 76 | $request = $this->requestStack->getCurrentRequest(); |
||
| 77 | $courseId = $request->query->get('cid'); |
||
| 78 | $sessionId = $request->query->get('sid'); |
||
| 79 | $groupId = $request->query->get('gid'); |
||
| 80 | |||
| 81 | $startDate = $request->query->get('startDate'); |
||
| 82 | $endDate = $request->query->get('endDate'); |
||
| 83 | |||
| 84 | $qb->andWhere( |
||
| 85 | " |
||
| 86 | $alias.startDate BETWEEN :start AND :end OR |
||
| 87 | $alias.endDate BETWEEN :start AND :end |
||
| 88 | " |
||
| 89 | ); |
||
| 90 | |||
| 91 | /*OR |
||
| 92 | ( |
||
| 93 | $alias.startDate IS NOT NULL AND $alias.endDate IS NOT NULL AND |
||
| 94 | YEAR($alias.startDate) = YEAR($alias.endDate) AND |
||
| 95 | MONTH(':start') BETWEEN MONTH($alias.startDate) AND MONTH($alias.endDate) |
||
| 96 | )*/ |
||
| 97 | |||
| 98 | $qb |
||
| 99 | ->setParameter('start', $startDate) |
||
| 100 | ->setParameter('end', $endDate) |
||
| 101 | ; |
||
| 102 | |||
| 103 | if (empty($courseId)) { |
||
| 104 | $qb |
||
| 105 | ->andWhere('links.user = :user OR node.creator = :user') |
||
| 106 | ->setParameter('user', $user) |
||
| 107 | ; |
||
| 108 | } else { |
||
| 109 | $qb |
||
| 110 | ->andWhere('links.course = :course') |
||
| 111 | ->setParameter('course', $courseId) |
||
| 112 | ; |
||
| 113 | |||
| 114 | if (empty($sessionId)) { |
||
| 115 | $qb->andWhere('links.session IS NULL'); |
||
| 116 | } else { |
||
| 117 | $qb |
||
| 118 | ->andWhere('links.session = :session') |
||
| 119 | ->setParameter('session', $sessionId) |
||
| 120 | ; |
||
| 121 | } |
||
| 122 | |||
| 123 | if (empty($groupId)) { |
||
| 124 | $qb->andWhere('links.group IS NULL'); |
||
| 125 | } else { |
||
| 126 | $qb |
||
| 127 | ->andWhere('links.group = :group') |
||
| 128 | ->setParameter('group', $groupId) |
||
| 129 | ; |
||
| 163 |