Conditions | 14 |
Paths | 1024 |
Total Lines | 70 |
Lines | 19 |
Ratio | 27.14 % |
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 |
||
95 | function get_my_profile_strength(){ |
||
96 | |||
97 | $userEnt = elgg_get_logged_in_user_entity(); |
||
98 | |||
99 | //avatar |
||
100 | View Code Duplication | if($userEnt->getIconURL() != elgg_get_site_url() . '_graphics/icons/user/defaultmedium.gif'){ |
|
101 | $avIcon = '<span class="fa fa-check text-primary"></span>'; |
||
102 | $avTotal = 100; |
||
103 | }else{ |
||
104 | $avIcon = '<span class="fa fa-exclamation-triangle text-danger"></span>'; |
||
105 | $avTotal = 0; |
||
106 | } |
||
107 | |||
108 | //About me |
||
109 | View Code Duplication | if($userEnt->description){ |
|
110 | $aboutIcon = '<span class="fa fa-check text-primary"></span>'; |
||
111 | $aboutTotal = 100; |
||
112 | }else{ |
||
113 | $aboutIcon = '<span class="fa fa-exclamation-triangle text-danger"></span>'; |
||
114 | $aboutTotal = 0; |
||
115 | } |
||
116 | |||
117 | //basic profile |
||
118 | $basicCount = 0; |
||
119 | |||
120 | if($userEnt->department){ |
||
121 | $basicCount += 20; |
||
122 | } |
||
123 | if($userEnt->job){ |
||
124 | $basicCount += 20; |
||
125 | } |
||
126 | if($userEnt->location || $userEnt->addressString || $userEnt->addressStringFr){ |
||
127 | $basicCount += 20; |
||
128 | } |
||
129 | if($userEnt->email){ |
||
130 | $basicCount += 20; |
||
131 | } |
||
132 | if($userEnt->phone || $userEnt->mobile){ |
||
133 | $basicCount += 20; |
||
134 | } |
||
135 | |||
136 | //education |
||
137 | if(count($userEnt->education) >= 1){ |
||
138 | $eduCount = 100; |
||
139 | } else { |
||
140 | $eduCount = 0; |
||
141 | } |
||
142 | |||
143 | //work experience |
||
144 | if(count($userEnt->work) >= 1){ |
||
145 | $workCount = 100; |
||
146 | } else { |
||
147 | $workCount = 0; |
||
148 | } |
||
149 | |||
150 | //skills |
||
151 | View Code Duplication | if(count($userEnt->gc_skills) >= 3){ |
|
152 | $skillCount = 100; |
||
153 | } else { |
||
154 | $skillCount = round(count($userEnt->gc_skills)/3*100); |
||
155 | } |
||
156 | |||
157 | //overall total |
||
158 | $complete = round(($skillCount + $workCount + $eduCount + $basicCount + $aboutTotal + $avTotal)/6); |
||
159 | |||
160 | //set up profile strength metadata |
||
161 | $userEnt->profilestrength = $complete; |
||
162 | |||
163 | return $userEnt->profilestrength; |
||
164 | } |
||
165 |
If you suppress an error, we recommend checking for the error condition explicitly: