Conditions | 8 |
Total Lines | 67 |
Code Lines | 63 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 com.osomapps.pt.tokenemail; |
||
69 | TokenEmailResponseDTO createOrReadNewToken( |
||
70 | TokenEmailRequestDTO tokenRequest, String remoteAddr) { |
||
71 | final Pair<Boolean, InUserEmail> inUserEmailData = readOrCreateInUserEmail(tokenRequest); |
||
72 | final boolean isNewLogin = inUserEmailData.getFirst(); |
||
73 | final InUserEmail inUserEmail = inUserEmailData.getSecond(); |
||
74 | final InUserLogin inUserLogin; |
||
75 | if (isNewLogin) { |
||
76 | inUserLogin = new InUserLogin(); |
||
77 | } else { |
||
78 | inUserLogin = |
||
79 | inUserEmail |
||
80 | .getInUser() |
||
81 | .getInUserLogins() |
||
82 | .get(inUserEmail.getInUser().getInUserLogins().size() - 1); |
||
83 | } |
||
84 | final InUser inUser = inUserEmail.getInUser(); |
||
85 | inUser.getInUserEmails().add(inUserEmail); |
||
86 | inUser.getInUserLogins().add(inUserLogin); |
||
87 | final InUser savedInUser = inUserRepository.save(inUser); |
||
88 | inUserLogin.setInUser(savedInUser); |
||
89 | inUserLogin.setIp_address(remoteAddr); |
||
90 | inUserLoginRepository.saveAndFlush(inUserLogin); |
||
91 | inUserEmail.setInUser(savedInUser); |
||
92 | inUserEmailRepository.save(inUserEmail); |
||
93 | final TokenEmailResponseDTO tokenEmailResponseDTO = new TokenEmailResponseDTO(); |
||
94 | tokenEmailResponseDTO.setToken(inUserLogin.getToken()); |
||
95 | final UserSignupResponseDTO user = new UserSignupResponseDTO(); |
||
96 | user.setId(inUserEmail.getInUser().getId()); |
||
97 | user.setName(inUserEmail.getUser_name()); |
||
98 | user.setEmail(inUserEmail.getLogin()); |
||
99 | user.setGender(inUserEmail.getInUser().getD_sex()); |
||
100 | user.setAge( |
||
101 | inUserEmail.getInUser().getAge() == null |
||
102 | ? null |
||
103 | : inUserEmail.getInUser().getAge().intValue()); |
||
104 | user.setBirthday(inUserEmail.getInUser().getBirthday()); |
||
105 | user.setAvatar_dataurl(inUserEmail.getInUser().getAvatar_dataurl()); |
||
106 | if (inUser.getD_level() != null) { |
||
107 | user.setLevel(UserLevel.of(Integer.parseInt(inUser.getD_level()))); |
||
108 | } |
||
109 | user.setGoals( |
||
110 | inUser.getInUserGoals().stream() |
||
111 | .map( |
||
112 | inUserGoal -> { |
||
113 | Map<String, Integer> map = null; |
||
114 | try { |
||
115 | map = |
||
116 | inUserGoal.getGoal_value() == null |
||
117 | ? null |
||
118 | : new ObjectMapper() |
||
119 | .readValue( |
||
120 | inUserGoal.getGoal_value(), |
||
121 | new TypeReference< |
||
122 | Map< |
||
123 | String, |
||
124 | Integer>>() {}); |
||
125 | } catch (IOException ex) { |
||
|
|||
126 | } |
||
127 | return new UserGoalResponseDTO() |
||
128 | .setId(inUserGoal.getGoalId()) |
||
129 | .setValues(map); |
||
130 | }) |
||
131 | .collect(Collectors.toList())); |
||
132 | user.setHeight(inUser.getHeight() == null ? null : inUser.getHeight().longValue()); |
||
133 | user.setWeight(inUser.getWeight() == null ? null : inUser.getWeight().longValue()); |
||
134 | tokenEmailResponseDTO.setUser(user); |
||
135 | return tokenEmailResponseDTO; |
||
136 | } |
||
155 |