OpenSRP/opensrp-client-anc

View on GitHub

Showing 436 of 436 total issues

Method getButtonAlertStatus has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

    public static ButtonAlertStatus getButtonAlertStatus
            (Map<String, String> details, Context context, boolean isProfile) {
        String contactStatus = details.get(DBConstantsUtils.KeyUtils.CONTACT_STATUS);

        String nextContactDate = details.get(DBConstantsUtils.KeyUtils.NEXT_CONTACT_DATE);

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 processRequiredStepsExpansionPanelValues has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

    private static void processRequiredStepsExpansionPanelValues(Facts facts, JSONObject fieldObject) throws Exception {
        if (fieldObject.has(JsonFormConstants.TYPE) &&
                JsonFormConstants.EXPANSION_PANEL.equals(fieldObject.getString(JsonFormConstants.TYPE)) &&
                fieldObject.has(JsonFormConstants.VALUE)) {
            JSONArray expansionPanelValue = fieldObject.getJSONArray(JsonFormConstants.VALUE);

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 getSecondaryValueKeyPair has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

    private static void getSecondaryValueKeyPair(JSONArray values, int valueLength, List<String> keyList, List<String> valueList) throws JSONException {
        for (int k = 0; k < valueLength; k++) {
            String valuesString = values.getString(k);
            String keyString = "";
            if (TextUtils.isEmpty(keyString) && valuesString.contains(":")) {

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 onCreate has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getViewLayoutId());
        actionBar = getSupportActionBar();

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 savePartialContact has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

    public void savePartialContact(PartialContact partialContact) {
        if (partialContact == null) return;
        else if (partialContact.getUpdatedAt() == null) {
            partialContact.setUpdatedAt(Calendar.getInstance().getTimeInMillis());
        }

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 processTasks has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

    private void processTasks(JSONObject formObject) {
        try {
            String encounterType = formObject.getString(ConstantsUtils.JsonFormKeyUtils.ENCOUNTER_TYPE);
            if (formObject.has(ConstantsUtils.JsonFormKeyUtils.ENCOUNTER_TYPE) && StringUtils.isNotBlank(encounterType) && ConstantsUtils.JsonFormUtils.ANC_TEST_ENCOUNTER_TYPE.equals(encounterType)) {
                JSONObject dueStep = formObject.optJSONObject(JsonFormConstants.STEP1);

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 updateEventAndRequiredStepsField has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

    private void updateEventAndRequiredStepsField(String baseEntityId, PartialContactRepository partialContactRepository,
                                                  List<PartialContact> partialContactList, Facts facts, List<String> formSubmissionIDs) throws Exception {
        if (partialContactList != null) {
            Collections.sort(partialContactList, (firstPartialContact, secondPartialContact) -> firstPartialContact.getSortOrder().compareTo(secondPartialContact.getSortOrder()));

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 buildRepeatingGroupValues has 27 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public static HashMap<String, HashMap<String, String>> buildRepeatingGroupValues(@NonNull JSONArray fields, @NonNull String fieldName) throws JSONException {
        ArrayList<String> keysArrayList = new ArrayList<>();
        JSONObject jsonObject = JsonFormUtils.getFieldJSONObject(fields, fieldName);
        HashMap<String, HashMap<String, String>> repeatingGroupMap = new LinkedHashMap<>();
        if (jsonObject != null) {

    Method processRegistrationForm has 27 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public static Pair<Client, Event> processRegistrationForm(AllSharedPreferences allSharedPreferences, String jsonString) {
            try {
                Triple<Boolean, JSONObject, JSONArray> registrationFormParams = validateParameters(jsonString);
    
                if (!registrationFormParams.getLeft()) {

      Method getFilteredItemsWithoutFilteredSource has 27 lines of code (exceeds 25 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++) {

        Method getAutoPopulatedJsonEditRegisterFormString has 27 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public static String getAutoPopulatedJsonEditRegisterFormString(Context context, Map<String, String> womanClient) {
                try {
                    JSONObject form = FormUtils.getInstance(context).getFormJson(ConstantsUtils.JsonFormUtils.ANC_REGISTER);
                    LocationPickerView lpv = createLocationPickerView(context);
                    if (lpv != null) {

          Method getDisplayTemplate has 27 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              private static String getDisplayTemplate(Context context, String alertStatus,
                                                       boolean isProfile) {
                  String displayTemplate;
                  if (StringUtils.isNotBlank(alertStatus) && !isProfile) {
                      switch (alertStatus) {

            Method defaultRegisterConfiguration has 27 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public static RegisterConfiguration defaultRegisterConfiguration(Context context) {
                    if (context == null) {
                        return null;
                    }
            
            

              Method onBindViewHolder has 27 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  @Override
                  public void onBindViewHolder(@NonNull ViewHolder viewHolder, int position) {
                      if (lastContactDetailsList.size() > 0) {
                          LastContactDetailsWrapper lastContactDetails = lastContactDetailsList.get(position);
                          Facts facts = lastContactDetails.getFacts();

                Identical blocks of code found in 2 locations. Consider refactoring.
                Open

                        else if (!isPermissionGranted() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.R)
                        {
                            Intent intent = new Intent();
                            intent.setAction(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION);
                            Uri uri = Uri.fromParts("package", this.getPackageName(), null);
                opensrp-anc/src/main/java/org/smartregister/anc/library/activity/ContactSummaryFinishActivity.java on lines 113..120

                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 74.

                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

                Further Reading

                Identical blocks of code found in 2 locations. Consider refactoring.
                Open

                        else if(!isPermissionGranted() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.R)
                        {
                            Intent intent = new Intent();
                            intent.setAction(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION);
                            Uri uri = Uri.fromParts("package", this.getPackageName(), null);
                opensrp-anc/src/main/java/org/smartregister/anc/library/activity/ContactSummaryFinishActivity.java on lines 255..262

                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 74.

                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

                Further Reading

                Identical blocks of code found in 2 locations. Consider refactoring.
                Open

                                    case BOTH:
                                        CreateRemoteLocalCursorUtils createRemoteLocalCursorUtils = new CreateRemoteLocalCursorUtils(matrixCursor, true);
                                        remoteLocalCursor.addRow(new Object[]{createRemoteLocalCursorUtils.getId(),
                                                createRemoteLocalCursorUtils.getRelationalId(), createRemoteLocalCursorUtils.getFirstName(),
                                                createRemoteLocalCursorUtils.getLastName(), createRemoteLocalCursorUtils.getDob(),
                opensrp-anc/src/main/java/org/smartregister/anc/library/presenter/AdvancedSearchPresenter.java on lines 125..135

                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 74.

                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

                Further Reading

                Identical blocks of code found in 2 locations. Consider refactoring.
                Open

                                    case RIGHT:
                                        CreateRemoteLocalCursorUtils localCreateRemoteLocalCursorUtils = new CreateRemoteLocalCursorUtils(cursor, false);
                                        remoteLocalCursor.addRow(new Object[]{localCreateRemoteLocalCursorUtils.getId(),
                                                localCreateRemoteLocalCursorUtils.getRelationalId(), localCreateRemoteLocalCursorUtils.getFirstName(),
                                                localCreateRemoteLocalCursorUtils.getLastName(), localCreateRemoteLocalCursorUtils.getDob(),
                opensrp-anc/src/main/java/org/smartregister/anc/library/presenter/AdvancedSearchPresenter.java on lines 112..124

                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 74.

                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

                Further Reading

                Similar blocks of code found in 2 locations. Consider refactoring.
                Open

                    private void showDialog() {
                        ((ContactSummaryFinishActivity) context).showProgressDialog(R.string.please_wait_message);
                        ((ContactSummaryFinishActivity) context).getProgressDialog().setMessage(String.format(context.getString(R.string.summarizing_contact_number), intent.getExtras().getInt(ConstantsUtils.IntentKeyUtils.CONTACT_NO)) + " data");
                        ((ContactSummaryFinishActivity) context).getProgressDialog().show();
                    }
                opensrp-anc/src/main/java/org/smartregister/anc/library/task/FinalizeContactTask.java on lines 50..56

                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 73.

                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

                Further Reading

                Identical blocks of code found in 2 locations. Consider refactoring.
                Open

                    @NotNull
                    private Task getTask(JSONObject field, String key, String baseEntityId) {
                        Task task = new Task();
                        task.setBaseEntityId(baseEntityId);
                        task.setKey(key);
                opensrp-anc/src/main/java/org/smartregister/anc/library/model/ContactVisit.java on lines 379..389

                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 73.

                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

                Further Reading

                Severity
                Category
                Status
                Source
                Language