Showing 436 of 436 total issues
Method saveRemovedFromANCRegister
has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring. Open
public static Triple<Boolean, Event, Event> saveRemovedFromANCRegister(AllSharedPreferences allSharedPreferences, String jsonString, String providerId) {
try {
boolean isDeath = false;
Triple<Boolean, JSONObject, JSONArray> registrationFormParams = validateParameters(jsonString);
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method process
has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring. Open
private void process(String[] mainContactForms) {
//Fetch and load previously saved values
try {
if (contactNo > 1 && !PatientRepository.isFirstVisit(baseEntityId)) {
for (String formEventType : new ArrayList<>(Arrays.asList(mainContactForms))) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method processCheckBoxSpecialWidget
has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring. Open
private static void processCheckBoxSpecialWidget(JSONObject widget, List<String> keyList, List<String> valueList)
throws Exception {
//Clear previous selected values from the widget first
if (widget.has(JsonFormConstants.VALUE)) {
widget.remove(JsonFormConstants.VALUE);
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method quickCheckDangerSignsSelectionHandler
has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring. Open
public void quickCheckDangerSignsSelectionHandler(JSONArray fields) throws JSONException {
boolean none = false;
boolean other = false;
Fragment fragment = getVisibleFragment();
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
File PreviousContactRepository.java
has 332 lines of code (exceeds 250 allowed). Consider refactoring. Open
package org.smartregister.anc.library.repository;
import android.content.ContentValues;
import android.text.TextUtils;
import android.util.Log;
Method getFilteredItemsWithoutFilteredSource
has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring. Open
private static boolean getFilteredItemsWithoutFilteredSource(JSONObject mainJsonObject, JSONObject checkBoxField, ArrayList<JSONObject> newOptionsList, Map<String, JSONObject> optionsMap) throws JSONException {
if (checkBoxField.has(ConstantsUtils.FILTER_OPTIONS)) {
JSONArray filterOptions = checkBoxField.getJSONArray(ConstantsUtils.FILTER_OPTIONS);
if (filterOptions.length() > 0) {
for (int count = 0; count < filterOptions.length(); count++) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
File ProfileActivity.java
has 329 lines of code (exceeds 250 allowed). Consider refactoring. Open
package org.smartregister.anc.library.activity;
import android.Manifest;
import android.app.Activity;
import android.app.AlertDialog;
Method getPreviousContactFacts
has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring. Open
public Facts getPreviousContactFacts(String baseEntityId, String contactNo, boolean checkNegative) {
Cursor mCursor = null;
String selection = "";
String orderBy = "MAX("+ ID + ") DESC";
String[] selectionArgs = null;
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
File ContactVisit.java
has 320 lines of code (exceeds 250 allowed). Consider refactoring. Open
package org.smartregister.anc.library.model;
import android.text.TextUtils;
import com.vijay.jsonwizard.constants.JsonFormConstants;
Consider simplifying this complex logical expression. Open
if ((key.equals(ConstantsUtils.PrescriptionUtils.NAUSEA_PHARMA) || key.equals(ConstantsUtils.PrescriptionUtils.ANTACID) || key.equals(ConstantsUtils.PrescriptionUtils.PENICILLIN) || key.equals(ConstantsUtils.PrescriptionUtils.ANTIBIOTIC) || key.equals(ConstantsUtils.PrescriptionUtils.IFA_MEDICATION) || key.equals(ConstantsUtils.PrescriptionUtils.VITA)
|| key.equals(ConstantsUtils.PrescriptionUtils.MAG_CALC) || key.equals(ConstantsUtils.PrescriptionUtils.ALBEN_MEBEN) || key.equals(ConstantsUtils.PrescriptionUtils.PREP) || key.equals(ConstantsUtils.PrescriptionUtils.SP) || key.equals(ConstantsUtils.PrescriptionUtils.IFA) || key.equals(ConstantsUtils.PrescriptionUtils.ASPIRIN) || key.equals(ConstantsUtils.PrescriptionUtils.CALCIUM)) && (value != null && value.equals("0"))) {
Context context = AncLibrary.getInstance().getApplicationContext();
String translationIsOn = Utils.getProperties(context).getProperty(ConstantsUtils.Properties.WIDGET_VALUE_TRANSLATED, "false");
if (StringUtils.isNotBlank(value) && Boolean.parseBoolean(translationIsOn)) {
File ProfileContactsFragment.java
has 313 lines of code (exceeds 250 allowed). Consider refactoring. Open
package org.smartregister.anc.library.fragment;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
Similar blocks of code found in 2 locations. Consider refactoring. Open
public List<Task> getOpenTasks(String baseEntityId) {
String orderBy = ID + " DESC ";
Cursor mCursor = null;
String selection = "";
String[] selectionArgs = new String[]{};
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 220.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
public List<Task> getClosedTasks(String baseEntityId) {
String orderBy = ID + " DESC ";
Cursor mCursor = null;
String selection = "";
String[] selectionArgs = new String[]{};
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 220.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Method hasPendingRequiredFields
has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring. Open
public static boolean hasPendingRequiredFields(JSONObject object) throws Exception {
if (object != null) {
Iterator<String> keys = object.keys();
while (keys.hasNext()) {
String key = keys.next();
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
ContactSummaryFinishActivity
has 28 methods (exceeds 20 allowed). Consider refactoring. Open
public class ContactSummaryFinishActivity extends BaseProfileActivity implements ProfileContract.View {
public MenuItem saveFinishMenuItem;
private TextView nameView;
private TextView ageView;
private TextView gestationAgeView;
Method cleanValue
has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring. Open
@SuppressLint("NewApi")
static String cleanValue(String value) {
String returnValue = "";
try {
if (value.trim().length() > 0 && value.trim().charAt(0) == '[') {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
File AncLibrary.java
has 296 lines of code (exceeds 250 allowed). Consider refactoring. Open
package org.smartregister.anc.library;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Method processRequiredStepsField
has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring. Open
private void processRequiredStepsField(JSONObject object) throws Exception {
if (object != null && object.has(ConstantsUtils.JsonFormKeyUtils.ENCOUNTER_TYPE)) {
//initialize required fields map
String encounterType = object.getString(ConstantsUtils.JsonFormKeyUtils.ENCOUNTER_TYPE);
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method createMatrixCursor
has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring. Open
@Override
public AdvancedMatrixCursor createMatrixCursor(Response<String> response) {
String[] columns = new String[]{"_id", "relationalid", DBConstantsUtils.KeyUtils.FIRST_NAME, DBConstantsUtils.KeyUtils.LAST_NAME,
DBConstantsUtils.KeyUtils.DOB,DBConstantsUtils.KeyUtils.EDD, DBConstantsUtils.KeyUtils.ANC_ID, DBConstantsUtils.KeyUtils.PHONE_NUMBER, DBConstantsUtils.KeyUtils.ALT_NAME,DBConstantsUtils.KeyUtils.NEXT_CONTACT,DBConstantsUtils.KeyUtils.NEXT_CONTACT_DATE};
AdvancedMatrixCursor matrixCursor = new AdvancedMatrixCursor(columns);
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
File ContactWizardJsonFormFragment.java
has 294 lines of code (exceeds 250 allowed). Consider refactoring. Open
package org.smartregister.anc.library.fragment;
import android.app.AlertDialog;
import android.app.Dialog;
import android.os.Bundle;