phplib/ESClient.php

Summary

Maintainability
D
3 days
Test Coverage

File ESClient.php has 456 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

namespace FOO;

/**
Severity: Minor
Found in phplib/ESClient.php - About 6 hrs to fix

    Method getActiveAlertCounts has 73 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function getActiveAlertCounts() {
            $client = self::getClient();
    
            $filter = [
                [
    Severity: Major
    Found in phplib/ESClient.php - About 2 hrs to fix

      Method query has 64 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          private function query($query, $fields=null, $from=null, $to=null, $scroll=false, $offset=null, $count=null) {
              $client = self::getClient();
      
              $filter = [];
              $conds = [];
      Severity: Major
      Found in phplib/ESClient.php - About 2 hrs to fix

        Method getAlertActivityCounts has 53 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function getAlertActivityCounts($range, $search_id=0) {
                $client = self::getClient();
        
                $filter = [
                    [
        Severity: Major
        Found in phplib/ESClient.php - About 2 hrs to fix

          Function getActiveAlertCounts has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
          Open

              public function getActiveAlertCounts() {
                  $client = self::getClient();
          
                  $filter = [
                      [
          Severity: Minor
          Found in phplib/ESClient.php - About 2 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 bootstrap has 45 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function bootstrap($query, $from=null, $to=null) {
                  $client = self::getClient();
          
                  $fields = ['escalated', 'assignee_type', 'assignee', 'search_id', 'state'];
                  $aggs = [];
          Severity: Minor
          Found in phplib/ESClient.php - About 1 hr to fix

            Method initializeIndex has 40 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function initializeIndex() {
                    // Create template.
                    if(!$this->client->indices()->existsTemplate(['name' => self::MAPPING_TEMPLATE])) {
                        $version = explode('.', $this->client->info()['version']['number'])[0];
                        $string_type = 'string';
            Severity: Minor
            Found in phplib/ESClient.php - About 1 hr to fix

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

                  private function query($query, $fields=null, $from=null, $to=null, $scroll=false, $offset=null, $count=null) {
                      $client = self::getClient();
              
                      $filter = [];
                      $conds = [];
              Severity: Minor
              Found in phplib/ESClient.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 query has 7 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                  private function query($query, $fields=null, $from=null, $to=null, $scroll=false, $offset=null, $count=null) {
              Severity: Major
              Found in phplib/ESClient.php - About 50 mins to fix

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

                    public static function getClient($config_name='alerts', $index=false) {
                        $escfg = Config::get('elasticsearch')[$config_name];
                        $cb = \Elasticsearch\ClientBuilder::create();
                        if($index && count($escfg['index_hosts']) > 0) {
                            $cb->setHosts($escfg['index_hosts']);
                Severity: Minor
                Found in phplib/ESClient.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 getAlerts has 5 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                    public function getAlerts($query, $from, $to, $offset, $count) {
                Severity: Minor
                Found in phplib/ESClient.php - About 35 mins to fix

                  Function send has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                  Open

                      private function send() {
                          if(count($this->list) == 0) {
                              return;
                          }
                  
                  
                  Severity: Minor
                  Found in phplib/ESClient.php - About 35 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

                  Function bootstrapRecurse has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                  Open

                      private function bootstrapRecurse($node, $data, $count, $fields) {
                          $ret = [];
                  
                          if(array_key_exists('agg', $data)) {
                              $key = array_pop($fields);
                  Severity: Minor
                  Found in phplib/ESClient.php - About 25 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

                  There are no issues that match your filters.

                  Category
                  Status