app/resto/core/dbfunctions/FeaturesFunctions.php

Summary

Maintainability
F
4 days
Test Coverage

File FeaturesFunctions.php has 553 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/*
 * Copyright 2018 Jérôme Gasperi
 *
 * Licensed under the Apache License, version 2.0 (the "License");
Severity: Major
Found in app/resto/core/dbfunctions/FeaturesFunctions.php - About 1 day to fix

    Function featureArrayToKeysValues has a Cognitive Complexity of 36 (exceeds 5 allowed). Consider refactoring.
    Open

        private function featureArrayToKeysValues($collection, $featureArray, $protected, $updatabled)
        {
            // Initialize
            $keysAndValues = array(
                'links' => isset($featureArray['links']) ? json_encode($featureArray['links'], JSON_UNESCAPED_SLASHES) : null,
    Severity: Minor
    Found in app/resto/core/dbfunctions/FeaturesFunctions.php - About 5 hrs to fix

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

        public function search($context, $user, $model, $collections, $paramsWithOperation, $sorting)
        {
            /*
             * Check that mandatory filters are set
             */
    Severity: Major
    Found in app/resto/core/dbfunctions/FeaturesFunctions.php - About 3 hrs to fix

      Function search has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
      Open

          public function search($context, $user, $model, $collections, $paramsWithOperation, $sorting)
          {
              /*
               * Check that mandatory filters are set
               */
      Severity: Minor
      Found in app/resto/core/dbfunctions/FeaturesFunctions.php - About 3 hrs to fix

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

          private function featureArrayToKeysValues($collection, $featureArray, $protected, $updatabled)
          {
              // Initialize
              $keysAndValues = array(
                  'links' => isset($featureArray['links']) ? json_encode($featureArray['links'], JSON_UNESCAPED_SLASHES) : null,
      Severity: Major
      Found in app/resto/core/dbfunctions/FeaturesFunctions.php - About 2 hrs to fix

        Method updateFeature has 52 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function updateFeature($feature, $collection, $newFeatureArray)
            {
                if (!isset($feature)) {
                    RestoLogUtil::httpError(404);
                }
        Severity: Major
        Found in app/resto/core/dbfunctions/FeaturesFunctions.php - About 2 hrs to fix

          Method storeFeature has 50 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function storeFeature($id, $collection, $featureArray)
              {
                  $keysValues = $this->featureArrayToKeysValues(
                      $collection,
                      $featureArray,
          Severity: Minor
          Found in app/resto/core/dbfunctions/FeaturesFunctions.php - About 2 hrs to fix

            Function getSelectClause has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
            Open

                private function getSelectClause($featureTableName, $featureColumns, $user, $options)
                {
                    $sanitized = $this->sanitizeSQLColumns($featureColumns, isset($options['fields']) ? array_map('trim', explode(',', $options['fields'])) : array());
            
                    /*
            Severity: Minor
            Found in app/resto/core/dbfunctions/FeaturesFunctions.php - About 1 hr to fix

            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

            Function extractHashtagsFromText has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
            Open

                public function extractHashtagsFromText($text, $stringOnly)
                {
                    $matches = null;
                    if (isset($text)) {
                        preg_match_all("/#([^ ]+)/u", $text, $matches);
            Severity: Minor
            Found in app/resto/core/dbfunctions/FeaturesFunctions.php - About 1 hr to fix

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

                private function getSelectClause($featureTableName, $featureColumns, $user, $options)
                {
                    $sanitized = $this->sanitizeSQLColumns($featureColumns, isset($options['fields']) ? array_map('trim', explode(',', $options['fields'])) : array());
            
                    /*
            Severity: Minor
            Found in app/resto/core/dbfunctions/FeaturesFunctions.php - About 1 hr to fix

              Function sanitizeSQLColumns has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
              Open

                  private function sanitizeSQLColumns($featureColumns, $fields)
                  {
                      $discarded = array();
                      
                      /*
              Severity: Minor
              Found in app/resto/core/dbfunctions/FeaturesFunctions.php - About 1 hr to fix

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

                  public function updateFeatureDescription($feature, $description)
                  {
                      // Get hashtags to remove from feature before update
                      $hashtagsToRemove = $this->extractHashtagsFromText($feature->toArray()['properties']['description'], true);
                      $hashtagsToAdd = $this->extractHashtagsFromText($description, true);
              Severity: Minor
              Found in app/resto/core/dbfunctions/FeaturesFunctions.php - About 1 hr to fix

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

                    public function search($context, $user, $model, $collections, $paramsWithOperation, $sorting)
                Severity: Minor
                Found in app/resto/core/dbfunctions/FeaturesFunctions.php - About 45 mins to fix

                  Function checkMandatoryFilters has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                  Open

                      private function checkMandatoryFilters($searchFilters, $paramsWithOperation)
                      {
                          $missing = array();
                          foreach (array_keys($searchFilters) as $filterName) {
                              if (isset($searchFilters[$filterName])) {
                  Severity: Minor
                  Found in app/resto/core/dbfunctions/FeaturesFunctions.php - About 45 mins to fix

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

                      public function getFeatureDescription($context, $user, $featureId, $collection, $fields)
                  Severity: Minor
                  Found in app/resto/core/dbfunctions/FeaturesFunctions.php - About 35 mins to fix

                    There are no issues that match your filters.

                    Category
                    Status