OpenSRP/opensrp-client-anc

View on GitHub

Showing 436 of 436 total issues

Method initializeMainContactContainers has 74 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    private void initializeMainContactContainers() {

        try {

            requiredFieldsMap.clear();

    Method getValueFromAccordion has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
    Open

        public String getValueFromAccordion(String accordion, String widget) throws JSONException {
            String result = "";
            if (mJsonObject.length() > 0) {
                String[] splitWidget = widget.split("_");
                String step = splitWidget[0];

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

        @Override
        public void init(String json) {
            try {
                setmJSONObject(new JSONObject(json));
                if (!getmJSONObject().has(ConstantsUtils.JsonFormKeyUtils.ENCOUNTER_TYPE)) {

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

        private void populateFormViews(View view) {
            search = view.findViewById(R.id.search);
            search.setEnabled(false);
            search.setTextColor(getResources().getColor(R.color.contact_complete_grey_border));
    
    

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

              try {
                  SQLiteDatabase db = getWritableDatabase();
      
                  if (StringUtils.isNotBlank(baseEntityId)) {
                      if (keysList != null) {
      opensrp-anc/src/main/java/org/smartregister/anc/library/repository/ContactTasksRepository.java on lines 162..182

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

      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

              try {
                  SQLiteDatabase sqLiteDatabase = getReadableDatabase();
      
                  if (StringUtils.isNotBlank(baseEntityId)) {
                      if (keysList != null) {
      opensrp-anc/src/main/java/org/smartregister/anc/library/repository/PreviousContactRepository.java on lines 142..162

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

      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

      Method removeDueTests has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
      Open

          private JSONObject removeDueTests(JSONObject formObject, List<Task> taskList) {
              JSONObject form = new JSONObject();
              try {
                  Map<String, JSONObject> keys = taskHashMap(taskList);
                  if (formObject != null && taskList != null && taskList.size() > 0 && formObject.has(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 saveRemovedFromANCRegister has 68 lines of code (exceeds 25 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);
      
      

        Method finalizeContactForm has 68 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            @Override
            public HashMap<String, String> finalizeContactForm(final Map<String, String> details, Context context) {
                if (details != null) {
                    try {
                        String referral = details.get(ConstantsUtils.REFERRAL);

          Method processValue has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
          Open

              private static String processValue(String key, Facts facts) {
                  String value = "";
                  if (facts.get(key) instanceof String) {
                      value = facts.get(key);
                      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)

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

              public static boolean checkIfTaskIsComplete(JSONObject field) {
                  boolean isComplete = true;
                  try {
                      if (field != null && field.has(JsonFormConstants.VALUE)) {
                          JSONArray value = field.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 fetchUpcomingContacts has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
          Open

              @Override
              public void fetchUpcomingContacts(final String entityId, final String referralContactNo,
                                                final ContactSummarySendContract.InteractorCallback callback) {
          
                  Runnable runnable = () -> {

          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 a Cognitive Complexity of 18 (exceeds 5 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) {

          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

          WomanDetail has 22 methods (exceeds 20 allowed). Consider refactoring.
          Open

          public class WomanDetail {
              private Integer nextContact;
          
              private String baseEntityId;
              private String nextContactDate;

            Method processButtonAlertStatus has 58 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public static void processButtonAlertStatus(Context context, Button dueButton, TextView
                        contactTextView,
                                                            ButtonAlertStatus buttonAlertStatus) {
                    if (dueButton != null) {
                        dueButton.setVisibility(View.VISIBLE);

              Method getRemoteLocalMatrixCursor has 57 lines of code (exceeds 25 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(

                File ConstantsUtils.java has 261 lines of code (exceeds 250 allowed). Consider refactoring.
                Open

                package org.smartregister.anc.library.util;
                
                /**
                 * Created by ndegwamartin on 14/03/2018.
                 */

                  Method processLocationFields has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
                  Open

                      protected static void processLocationFields(@NonNull JSONArray fields) throws JSONException {
                          for (int i = 0; i < fields.length(); i++) {
                              if (fields.optJSONObject(i).has(JsonFormConstants.TYPE) &&
                                      fields.optJSONObject(i).optString(JsonFormConstants.TYPE).equals(JsonFormConstants.TREE))
                                  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 processButtonAlertStatus has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
                  Open

                      public static void processButtonAlertStatus(Context context, Button dueButton, TextView
                              contactTextView,
                                                                  ButtonAlertStatus buttonAlertStatus) {
                          if (dueButton != null) {
                              dueButton.setVisibility(View.VISIBLE);

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

                      private void preProcessDefaultValues(JSONObject object) {
                          try {
                              if (object != null) {
                                  Iterator<String> keys = object.keys();
                  
                  

                  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

                  Severity
                  Category
                  Status
                  Source
                  Language