Conditions | 5 |
Paths | 12 |
Total Lines | 52 |
Code Lines | 32 |
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 |
||
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 | }*/ |
||
81 |