OpenSRP/opensrp-client-anc

View on GitHub

Showing 436 of 436 total issues

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

        if (actionBar != null) {
            actionBar.setDisplayShowHomeEnabled(true);
            actionBar.setDisplayHomeAsUpEnabled(true);
            actionBar.setHomeAsUpIndicator(getResources().getDrawable(R.drawable.ic_back));
            actionBar.setTitle(getResources().getString(R.string.previous_contacts_tests_header));
opensrp-anc/src/main/java/org/smartregister/anc/library/activity/PreviousContactsDetailsActivity.java on lines 68..73

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

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

            if (window != null) {
                WindowManager.LayoutParams param = window.getAttributes();
                param.gravity = Gravity.TOP | Gravity.CENTER_HORIZONTAL;
                window.setAttributes(param);
                window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
opensrp-anc/src/main/java/org/smartregister/anc/library/activity/BaseContactActivity.java on lines 222..227

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

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

Avoid deeply nested control flow statements.
Open

                        if (isRequiredField && ((fieldObject.has(JsonFormConstants.VALUE) && TextUtils.isEmpty(
                                fieldObject.getString(JsonFormConstants.VALUE))) || !fieldObject.has(JsonFormConstants.VALUE))) {
                            //TO DO Remove/ Alter logical condition
                            return true;
                        }
Severity: Major
Found in opensrp-anc/src/main/java/org/smartregister/anc/library/util/Utils.java - About 45 mins to fix

    Method startForm has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

        @Override
        public void startForm(Object tag) {
            try {
                if (!(tag instanceof Contact) && getView() == null) {
                    return;

    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

    Avoid deeply nested control flow statements.
    Open

                            if (fieldObject.has(JsonFormConstants.CONTENT_FORM)) {
                                processRequiredStepsExpansionPanelValues(facts, fieldObject);
                            }

      Avoid deeply nested control flow statements.
      Open

                              if (fieldObject.has(JsonFormConstants.IS_VISIBLE) && !fieldObject.getBoolean(JsonFormConstants.IS_VISIBLE)) {
                                  isRequiredField = false;
                              }
      Severity: Major
      Found in opensrp-anc/src/main/java/org/smartregister/anc/library/util/Utils.java - About 45 mins to fix

        Method addOtherRuleObjects has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

            private void addOtherRuleObjects(Facts facts) throws IOException {
                Iterable<Object> ruleObjects = utils.loadRulesFiles(FilePathUtils.FileUtils.PROFILE_LAST_CONTACT);
        
                for (Object ruleObject : ruleObjects) {
                    List<YamlConfigWrapper> yamlConfigList = new ArrayList<>();

        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

        Avoid deeply nested control flow statements.
        Open

                                    if (selectedValue.contains(JsonFormConstants.AncRadioButtonOptionTypesUtils.ORDERED) || selectedValue.contains(JsonFormConstants.AncRadioButtonOptionTypesUtils.NOT_DONE)) {
                                        isComplete = false;
                                    }

          Avoid deeply nested control flow statements.
          Open

                                  if (fieldKey != null && fieldObject.has(JsonFormConstants.VALUE) && fieldObject.has(JsonFormConstants.TYPE)
                                          && !JsonFormConstants.EXPANSION_PANEL.equals(fieldObject.getString(JsonFormConstants.TYPE))) {
                                      if (JsonFormConstants.CHECK_BOX.equals(fieldObject.optString(JsonFormConstants.TYPE, ""))) {
                                          String value = Utils.getProperties(context).getProperty(ConstantsUtils.Properties.WIDGET_VALUE_TRANSLATED, "false");
                                          if (StringUtils.isNotBlank(value) && Boolean.parseBoolean(value)) {

            Avoid deeply nested control flow statements.
            Open

                                    if (optionsToFilter == null) {
                                        String itemKey = removeKeyPrefix(keyGlobal, ConstantsUtils.PREVIOUS);
                                        newOptionsList.add(optionsMap.get(itemKey));
                                    } else {
                                        for (int itemIndex = 0; itemIndex < optionsToFilter.length(); itemIndex++) {

              Method onCreateLoader has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

                  @Override
                  public Loader<Cursor> onCreateLoader(int id, Bundle args) {
                      final AdvancedMatrixCursor matrixCursor = ((RegisterFragmentPresenter) presenter).getMatrixCursor();
                      if (!globalQrSearch || matrixCursor == null) {
                          if (id == LOADER_ID) {

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

                  private AdvancedMatrixCursor getRemoteLocalMatrixCursor(AdvancedMatrixCursor matrixCursor) {
                      String query = getView().filterAndSortQuery();
                      Cursor cursor = getView().getRawCustomQueryForAdapter(query);
                      if (cursor != null && cursor.getCount() > 0) {
                          AdvancedMatrixCursor remoteLocalCursor = new AdvancedMatrixCursor(

              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 init has 6 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                  public static void init(@NonNull Context context, int dbVersion, @NonNull ActivityConfiguration activityConfiguration, @Nullable SubscriberInfoIndex subscriberInfoIndex, @Nullable RegisterQueryProvider registerQueryProvider, @Nullable AncMetadata metadata) {
              Severity: Minor
              Found in opensrp-anc/src/main/java/org/smartregister/anc/library/AncLibrary.java - About 45 mins to fix

                Method loadSubFormFields has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                    private Map<String, JSONArray> loadSubFormFields(JSONObject taskValue, Context context) {
                        JSONArray fields = new JSONArray();
                        String mlsPropertyFile = "";
                        Map<String, JSONArray> stringJSONArrayMap = new HashMap<>();
                        try {

                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 checkBoxWriteValue has 6 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                    protected void checkBoxWriteValue(String stepName, String parentKey, String childObjectKey, String childKey,
                                                      String value, boolean popup) throws JSONException {

                  Avoid deeply nested control flow statements.
                  Open

                                              if (StringUtils.isNotBlank(value)) {
                                                  factsToUpdate.put(key, value);
                                              } else {
                                                  factsToUpdate.put(key, "");
                                              }

                    Avoid deeply nested control flow statements.
                    Open

                                            if (fieldObject.has(ConstantsUtils.KeyUtils.SECONDARY_VALUES) &&
                                                    fieldObject.getJSONArray(ConstantsUtils.KeyUtils.SECONDARY_VALUES).length() > 0) {
                                                JSONArray secondaryValues = fieldObject.getJSONArray(ConstantsUtils.KeyUtils.SECONDARY_VALUES);
                                                for (int count = 0; count < secondaryValues.length(); count++) {
                                                    JSONObject secondaryValuesJSONObject = secondaryValues.getJSONObject(count);

                      Avoid deeply nested control flow statements.
                      Open

                                              if (accordionObject.getString(JsonFormConstants.KEY).equals(accordion)) {
                                                  JSONArray value = accordionObject.optJSONArray(JsonFormConstants.VALUE);
                                                  if (value == null) {
                                                      return result;
                                                  }

                        Avoid deeply nested control flow statements.
                        Open

                                                if (fieldObject.has(JsonFormConstants.VALUE) &&
                                                        !TextUtils.isEmpty(fieldObject.getString(JsonFormConstants.VALUE)) &&
                                                        !isCheckboxValueEmpty(fieldObject)) {
                        
                                                    fieldObject.put(PreviousContactRepository.CONTACT_NO, contactNo);

                          Method getViewsFromJson has 6 arguments (exceeds 4 allowed). Consider refactoring.
                          Open

                              public List<View> getViewsFromJson(String stepName, Context context, JsonFormFragment formFragment,
                                                                 JSONObject jsonObject, CommonListener listener, boolean popup) throws Exception {
                            Severity
                            Category
                            Status
                            Source
                            Language