shawnrice/alphred

View on GitHub

Showing 55 of 55 total issues

Function fuzzy_ago has a Cognitive Complexity of 47 (exceeds 5 allowed). Consider refactoring.
Open

    public function fuzzy_ago( $seconds, $dictionary = 'english' ) {

        if ( $seconds < 0 ) {
            return false;
        }
Severity: Minor
Found in classes/Date.php - About 7 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 Filter has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
Open

    public static function Filter( $haystack, $needle, $key = false, $options = [] ) {
        // Set the defaults if not already set
        $max             = ( isset( $options['max_results'] ) ) ? $options['max_results'] : false;
        $fold_diacritics = ( isset( $options['fold'] ) ) ? $options['fold'] : true;
        $match_type      = ( isset( $options['match_type'] ) ) ? $options['match_type'] : MATCH_ALL;
Severity: Minor
Found in classes/Filter.php - About 4 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 convert_number_to_words has 99 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function convert_number_to_words( $number, $dictionary = 'english' ) {
        // This is a complex function, but I'm not sure if it can be simplified.
        // adapted from http://www.karlrixon.co.uk/writing/convert-numbers-to-words-with-php/
        $hyphen      = '-';
        $conjunction = ' and ';
Severity: Major
Found in classes/Date.php - About 3 hrs to fix

    Function create_request has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
    Open

        private function create_request( $url, $options, $cache_ttl, $cache_bin, $type ) {
    
            if ( $cache_ttl > 0 ) {
                // Create an object with caching on
                $request = new Alphred\Request( $url, [ 'cache' => true,
    Severity: Minor
    Found in classes/Alphred.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 fuzzy_ago has 93 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function fuzzy_ago( $seconds, $dictionary = 'english' ) {
    
            if ( $seconds < 0 ) {
                return false;
            }
    Severity: Major
    Found in classes/Date.php - About 3 hrs to fix

      Alphred has 30 functions (exceeds 20 allowed). Consider refactoring.
      Open

      class Alphred {
      
          /**
           * Initializes the wrapper object
           *
      Severity: Minor
      Found in classes/Alphred.php - About 3 hrs to fix

        Function execute has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
        Open

            public function execute( $code = false ) {
        
                // Set a preliminary HTTP response code of 0 (not defined)
                $this->code = 0;
        
        
        Severity: Minor
        Found in classes/Request.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

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

             private static function filter_item( $value, $query, $match_on, $fold_diacritics ) {
                 $query = strtolower( $query );
        
                 if ( $fold_diacritics ) {
                     $value = self::convert( $value );
        Severity: Minor
        Found in classes/Filter.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

        Request has 24 functions (exceeds 20 allowed). Consider refactoring.
        Open

        class Request {
        
            /**
             * The internal cURL handler
             * @var Resource
        Severity: Minor
        Found in classes/Request.php - About 2 hrs to fix

          Method filter_item has 65 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

               private static function filter_item( $value, $query, $match_on, $fold_diacritics ) {
                   $query = strtolower( $query );
          
                   if ( $fold_diacritics ) {
                       $value = self::convert( $value );
          Severity: Major
          Found in classes/Filter.php - About 2 hrs to fix

            Function write_item has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
            Open

                private function write_item( $item ) {
                    // The information we need is stored in the sub variable, so let's just get that
                    $item = $item->data;
                    // These go in the 'item' part as an attribute
                    $attributes = [ 'uid', 'arg', 'autocomplete' ];
            Severity: Minor
            Found in classes/ScriptFilter.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

            File Date.php has 272 lines of code (exceeds 250 allowed). Consider refactoring.
            Open

            <?php
            /**
             * Contains Date class for Alphred
             *
             * PHP version 5
            Severity: Minor
            Found in classes/Date.php - About 2 hrs to fix

              Function create has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
              Open

                  private function create( $start, $options, $selections ) {
              
                      // The beginning of the script
                      $script = "osascript -e '{$start}";
              
              
              Severity: Minor
              Found in classes/Choose.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 convert_number_to_words has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
              Open

                  public function convert_number_to_words( $number, $dictionary = 'english' ) {
                      // This is a complex function, but I'm not sure if it can be simplified.
                      // adapted from http://www.karlrixon.co.uk/writing/convert-numbers-to-words-with-php/
                      $hyphen      = '-';
                      $conjunction = ' and ';
              Severity: Minor
              Found in classes/Date.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

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

              <?php
              /**
               * Include file for when using Alphred through the cli-server SAPI
               *
               * If you write your workflow so that it takes advatage of the cli-server
              Severity: Major
              Found in scripts/server.php and 1 other location - About 2 hrs to fix
              example/server-scripts/server.php on lines 1..62

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

              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

              <?php
              /**
               * Include file for when using Alphred through the cli-server SAPI
               *
               * If you write your workflow so that it takes advatage of the cli-server
              Severity: Major
              Found in example/server-scripts/server.php and 1 other location - About 2 hrs to fix
              scripts/server.php on lines 1..62

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

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

                  public function __call( $called, $arguments ) {
                      // Make sure that the method is supposed to exist
                      if ( 0 !== strpos( $called, 'set_' ) ) {
                          // We should raise an exception here instead.
                          return false;
              Severity: Minor
              Found in classes/ScriptFilter.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 Filter has 51 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  public static function Filter( $haystack, $needle, $key = false, $options = [] ) {
                      // Set the defaults if not already set
                      $max             = ( isset( $options['max_results'] ) ) ? $options['max_results'] : false;
                      $fold_diacritics = ( isset( $options['fold'] ) ) ? $options['fold'] : true;
                      $match_type      = ( isset( $options['match_type'] ) ) ? $options['match_type'] : MATCH_ALL;
              Severity: Major
              Found in classes/Filter.php - About 2 hrs to fix

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

                    public function execute( $code = false ) {
                
                        // Set a preliminary HTTP response code of 0 (not defined)
                        $this->code = 0;
                
                
                Severity: Minor
                Found in classes/Request.php - About 1 hr to fix

                  Function flatten_array has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
                  Open

                      private static function flatten_array( $array, $prefix = '' ) {
                              if ( ! is_array( $array ) ) {
                                  return $array;
                              }
                              if ( ! self::is_assoc( $array ) ) {
                  Severity: Minor
                  Found in classes/Ini.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

                  Severity
                  Category
                  Status
                  Source
                  Language