Showing 370 of 370 total issues

File view.js has 261 lines of code (exceeds 250 allowed). Consider refactoring.
Open

"use strict";
define(function(require) {
    var $ = require('jquery'),
        _ = require('underscore'),
        Backbone = require('backbone'),
Severity: Minor
Found in htdocs/assets/js/view.js - About 2 hrs to fix

    Function run has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

        public function run() {
            switch($this->obj['target_id']) {
            case static::I_HOURLY:
                $type = Search::NT_HOURLY;
                $range = 1 * 60 * 60;
    Severity: Minor
    Found in phplib/Job/Rollup.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

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

            readForm: function() {
                var data = SearchView.SearchView.prototype.readForm.call(this);
                if('threatexchange_type' in data) {
                    data.query_data.threatexchange_type = data.threatexchange_type;
                    delete data.threatexchange_type;
    Severity: Major
    Found in htdocs/assets/js/views/searches/search/threatexchange.js and 1 other location - About 2 hrs to fix
    htdocs/assets/js/views/searches/search/ping.js on lines 14..23

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

    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

            readForm: function() {
                var data = SearchView.SearchView.prototype.readForm.call(this);
    
                if("host" in data) {
                    data.query_data.host = data.host;
    Severity: Major
    Found in htdocs/assets/js/views/searches/search/ping.js and 1 other location - About 2 hrs to fix
    htdocs/assets/js/views/searches/search/threatexchange.js on lines 12..20

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

    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

            whitelist: function(data, options) {
                return Backbone.ajax(_.extend({
                    url: this.prototype.getUrl() + '/whitelist',
                    method: 'post',
                    contentType: 'application/json; charset=utf-8',
    Severity: Major
    Found in htdocs/assets/js/collections/alert.js and 1 other location - About 2 hrs to fix
    htdocs/assets/js/collections/alert.js on lines 74..81

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

    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

            send: function(data, options) {
                return Backbone.ajax(_.extend({
                    url: this.prototype.getUrl() + '/send',
                    method: 'post',
                    contentType: 'application/json; charset=utf-8',
    Severity: Major
    Found in htdocs/assets/js/collections/alert.js and 1 other location - About 2 hrs to fix
    htdocs/assets/js/collections/alert.js on lines 63..70

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

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

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

          public function route() {
              $ret = self::format();
              try {
                  $this->checkAuthorization();
      
      
      Severity: Minor
      Found in phplib/REST.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 stats has 52 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function stats($data) {
              if(!$this->allowRead()) {
                  throw new ForbiddenException;
              }
      
      
      Severity: Major
      Found in phplib/REST/Searches.php - About 2 hrs to fix

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

                    if(query.from) {
                        var from_moment = Moment.utc(query.from, TIME_FMT);
                        if(from_moment.isValid()) {
                            query.from = from_moment.unix();
                        }
        Severity: Major
        Found in htdocs/assets/js/views/alerts/alerts.js and 1 other location - About 2 hrs to fix
        htdocs/assets/js/views/alerts/alerts.js on lines 243..250

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

        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

                    if(query.to) {
                        var to_moment = Moment.utc(query.to, TIME_FMT);
                        if(to_moment.isValid()) {
                            query.to = to_moment.unix();
                        }
        Severity: Major
        Found in htdocs/assets/js/views/alerts/alerts.js and 1 other location - About 2 hrs to fix
        htdocs/assets/js/views/alerts/alerts.js on lines 235..242

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

        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

        Function updateSelection has 49 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

                updateSelection: function() {
                    var data = {esc: 0, assign: 0, state: 0};
                    var elements = this.$('.alerts-table .alert-checkbox');
                    if(elements.length === 0) {
                        return;
        Severity: Minor
        Found in htdocs/assets/js/views/alerts/alertgroup.js - About 1 hr to fix

          Function initAssigneeSelect has 48 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              var initAssigneeSelect = function(elems, users, groups, search, options) {
                  options = options || {};
          
                  var assignee_search = function(q) {
                      var term = q.term.toLowerCase();
          Severity: Minor
          Found in htdocs/assets/js/util.js - About 1 hr to fix

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

                public static function query($query, array $params=[], $ret_type=self::ALL) {
                    self::keepAlive();
                    list($query) = Hook::call('db.query', [$query]);
            
                    $stmt = self::$dbh->prepare($query);
            Severity: Minor
            Found in phplib/DB.php - About 1 hr to fix

              Function POST has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
              Open

                  public function POST(array $get, array $data) {
                      $errors = [];
              
                      // Loop over each object we need to process.
                      foreach($data as &$obj) {
              Severity: Minor
              Found in phplib/REST/Enrich.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 backfill has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
              Open

                  public function backfill($start_date, $end_date, $max_jobs=5) {
                      Logger::info('Scheduler backfill run', ['start' => $start_date, 'end' => $end_date], self::LOG_NAMESPACE);
                      cli_set_process_title('411] Backfill');
                      print "[+] Backfill: $start_date to $end_date\n";
                      $timer = new Timer();
              Severity: Minor
              Found in phplib/Scheduler.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

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

                  public function validate(array $get, array $data) {
                      $type = Util::get($data, 'type');
              
                      $target = Target::newTarget($type);
                      if(!is_null($target)) {
              Severity: Major
              Found in phplib/REST/Targets.php and 1 other location - About 1 hr to fix
              phplib/REST/Filters.php on lines 76..86

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

              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

                  public function validate(array $get, array $data) {
                      $type = Util::get($data, 'type');
              
                      $filter = Filter::newFilter($type);
                      if(!is_null($filter)) {
              Severity: Major
              Found in phplib/REST/Filters.php and 1 other location - About 1 hr to fix
              phplib/REST/Targets.php on lines 76..86

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

              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

                      processSave: function() {
                          var data = this.readForm();
              
                          if(!this.model.isNew()) {
                              this.collection.save();
              Severity: Major
              Found in htdocs/assets/js/views/reports/report.js and 1 other location - About 1 hr to fix
              htdocs/assets/js/views/groups/group.js on lines 160..168

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

              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