| Conditions | 8 |
| Total Lines | 52 |
| Code Lines | 40 |
| 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 | package unicon.matthews.oneroster.service; |
||
| 39 | public Course save(final String tenantId, final String orgId, Course course) { |
||
| 40 | if (StringUtils.isBlank(tenantId) |
||
| 41 | || StringUtils.isBlank(orgId) |
||
| 42 | || course == null |
||
| 43 | || StringUtils.isBlank(course.getSourcedId())) { |
||
| 44 | throw new IllegalArgumentException(); |
||
| 45 | } |
||
| 46 | |||
| 47 | MongoCourse mongoCourse |
||
| 48 | = mongoCourseRepository |
||
| 49 | .findByTenantIdAndOrgIdAndCourseSourcedId(tenantId, orgId, course.getSourcedId()); |
||
| 50 | |||
| 51 | if (mongoCourse == null) { |
||
| 52 | mongoCourse |
||
| 53 | = new MongoCourse.Builder() |
||
| 54 | .withCourseSourcedId(course.getSourcedId()) |
||
| 55 | .withOrgId(orgId) |
||
| 56 | .withTenantId(tenantId) |
||
| 57 | .withCourse(course) |
||
| 58 | .build(); |
||
| 59 | } |
||
| 60 | else { |
||
| 61 | mongoCourse |
||
| 62 | = new MongoCourse.Builder() |
||
| 63 | .withId(mongoCourse.getId()) |
||
| 64 | .withCourseSourcedId(mongoCourse.getCourseSourcedId()) |
||
| 65 | .withOrgId(mongoCourse.getOrgId()) |
||
| 66 | .withTenantId(mongoCourse.getTenantId()) |
||
| 67 | .withCourse(course) |
||
| 68 | .build(); |
||
| 69 | } |
||
| 70 | |||
| 71 | MongoCourse saved = mongoCourseRepository.save(mongoCourse); |
||
| 72 | |||
| 73 | Collection<Class> classes = classService.findClassesForCourse(tenantId, orgId, saved.getCourseSourcedId()); |
||
| 74 | |||
| 75 | if (classes != null) { |
||
| 76 | for (Class cls : classes) { |
||
| 77 | Class updatedClass |
||
| 78 | = new Class.Builder() |
||
| 79 | .withCourse(saved.getCourse()) |
||
| 80 | .withMetadata(cls.getMetadata()) |
||
| 81 | .withSourcedId(cls.getSourcedId()) |
||
| 82 | .withStatus(cls.getStatus()) |
||
| 83 | .withTitle(cls.getTitle()) |
||
| 84 | .build(); |
||
| 85 | |||
| 86 | classService.save(tenantId, orgId, updatedClass); |
||
| 87 | } |
||
| 88 | } |
||
| 89 | |||
| 90 | return saved.getCourse(); |
||
| 91 | |||
| 95 |