freakimkaefig/Music-XML-Analyzer

View on GitHub
app/controllers/ResultController.php

Summary

Maintainability
F
2 wks
Test Coverage

Function generateResultExtract has a Cognitive Complexity of 147 (exceeds 5 allowed). Consider refactoring.
Open

    private function generateResultExtract($upload_id, $part_id, $voice, $startMeasure, $start, $endMeasure, $end) {
        set_time_limit(300);
        $upload = Upload::find($upload_id);

        $doc = new DOMDocument();
Severity: Minor
Found in app/controllers/ResultController.php - About 2 days 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 generateResultExtract has 188 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    private function generateResultExtract($upload_id, $part_id, $voice, $startMeasure, $start, $endMeasure, $end) {
        set_time_limit(300);
        $upload = Upload::find($upload_id);

        $doc = new DOMDocument();
Severity: Major
Found in app/controllers/ResultController.php - About 7 hrs to fix

    Function _getKey has a Cognitive Complexity of 35 (exceeds 5 allowed). Consider refactoring.
    Open

        public static function _getKey($id){
            $xml = simplexml_load_string(Upload::find($id)->content);
            $keys = $xml->xpath("//key");
            $key = $keys[0];
    
    
    Severity: Minor
    Found in app/controllers/ResultController.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

    File ResultController.php has 345 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    <?php
    
    /**
     * Controller to handle result requests
     * Generating result extracts for search results
    Severity: Minor
    Found in app/controllers/ResultController.php - About 4 hrs to fix

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

          private function getDurationType($durationFloat) {
              if ($durationFloat == 1){
                  return "whole";
              } elseif ($durationFloat == 0.75) {
                  return "whole";
      Severity: Minor
      Found in app/controllers/ResultController.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 _getKey has 42 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public static function _getKey($id){
              $xml = simplexml_load_string(Upload::find($id)->content);
              $keys = $xml->xpath("//key");
              $key = $keys[0];
      
      
      Severity: Minor
      Found in app/controllers/ResultController.php - About 1 hr to fix

        Method getDurationType has 31 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            private function getDurationType($durationFloat) {
                if ($durationFloat == 1){
                    return "whole";
                } elseif ($durationFloat == 0.75) {
                    return "whole";
        Severity: Minor
        Found in app/controllers/ResultController.php - About 1 hr to fix

          Method generateResultExtract has 7 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              private function generateResultExtract($upload_id, $part_id, $voice, $startMeasure, $start, $endMeasure, $end) {
          Severity: Major
          Found in app/controllers/ResultController.php - About 50 mins to fix

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

                public function getResultDetail($id, $page) {
                    if (Cache::has('results') && Cache::has('pattern')) {
                        $results = Cache::get('results');
                        foreach ($results as $item) {
                            if ($item->file_id == $id) {
            Severity: Minor
            Found in app/controllers/ResultController.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

            Consider simplifying this complex logical expression.
            Open

                                    if (($j == $startMeasure && $noteCounter >= $start) || ($j > $startMeasure && $j < $endMeasure) || ($j == $endMeasure && $noteCounter <= $end)) {
                                        // set color to red if note is between start and end of result
                                        $currentColor = "#b71c1c";
                                    }
            Severity: Major
            Found in app/controllers/ResultController.php - About 40 mins to fix

              Avoid too many return statements within this method.
              Open

                          return "16th";
              Severity: Major
              Found in app/controllers/ResultController.php - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                                case "5": return "G sharp minor"; break;
                Severity: Major
                Found in app/controllers/ResultController.php - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

                                  case "-5": return "D flat major"; break;
                  Severity: Major
                  Found in app/controllers/ResultController.php - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                                    case "-4": return "A flat major"; break;
                    Severity: Major
                    Found in app/controllers/ResultController.php - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                                      case "-1": return "D minor"; break;
                      Severity: Major
                      Found in app/controllers/ResultController.php - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

                                        case "6": return "F sharp major"; break;
                        Severity: Major
                        Found in app/controllers/ResultController.php - About 30 mins to fix

                          Avoid too many return statements within this method.
                          Open

                                          case "-7": return "C flat major"; break;
                          Severity: Major
                          Found in app/controllers/ResultController.php - About 30 mins to fix

                            Avoid too many return statements within this method.
                            Open

                                        return "quarter";
                            Severity: Major
                            Found in app/controllers/ResultController.php - About 30 mins to fix

                              Avoid too many return statements within this method.
                              Open

                                          return "32nd";
                              Severity: Major
                              Found in app/controllers/ResultController.php - About 30 mins to fix

                                Avoid too many return statements within this method.
                                Open

                                            return "64th";
                                Severity: Major
                                Found in app/controllers/ResultController.php - About 30 mins to fix

                                  Avoid too many return statements within this method.
                                  Open

                                              return "64th";    // set to lowest possible value
                                  Severity: Major
                                  Found in app/controllers/ResultController.php - About 30 mins to fix

                                    Avoid too many return statements within this method.
                                    Open

                                                    case "-2": return "B major"; break;
                                    Severity: Major
                                    Found in app/controllers/ResultController.php - About 30 mins to fix

                                      Avoid too many return statements within this method.
                                      Open

                                                      case "1": return "E minor"; break;
                                      Severity: Major
                                      Found in app/controllers/ResultController.php - About 30 mins to fix

                                        Avoid too many return statements within this method.
                                        Open

                                                        case "-2": return "G minor"; break;
                                        Severity: Major
                                        Found in app/controllers/ResultController.php - About 30 mins to fix

                                          Avoid too many return statements within this method.
                                          Open

                                                      return "64th";
                                          Severity: Major
                                          Found in app/controllers/ResultController.php - About 30 mins to fix

                                            Avoid too many return statements within this method.
                                            Open

                                                            case "-1": return "F major"; break;
                                            Severity: Major
                                            Found in app/controllers/ResultController.php - About 30 mins to fix

                                              Avoid too many return statements within this method.
                                              Open

                                                          return "eighth";
                                              Severity: Major
                                              Found in app/controllers/ResultController.php - About 30 mins to fix

                                                Avoid too many return statements within this method.
                                                Open

                                                                case "7": return "C sharp major"; break;
                                                Severity: Major
                                                Found in app/controllers/ResultController.php - About 30 mins to fix

                                                  Avoid too many return statements within this method.
                                                  Open

                                                                  case "-5": return "B minor"; break;
                                                  Severity: Major
                                                  Found in app/controllers/ResultController.php - About 30 mins to fix

                                                    Avoid too many return statements within this method.
                                                    Open

                                                                    case "3": return "F sharp minor"; break;
                                                    Severity: Major
                                                    Found in app/controllers/ResultController.php - About 30 mins to fix

                                                      Avoid too many return statements within this method.
                                                      Open

                                                                      case "0": return "A minor"; break;
                                                      Severity: Major
                                                      Found in app/controllers/ResultController.php - About 30 mins to fix

                                                        Avoid too many return statements within this method.
                                                        Open

                                                                    return "32nd";
                                                        Severity: Major
                                                        Found in app/controllers/ResultController.php - About 30 mins to fix

                                                          Avoid too many return statements within this method.
                                                          Open

                                                                          case "7": return "A sharp minor"; break;
                                                          Severity: Major
                                                          Found in app/controllers/ResultController.php - About 30 mins to fix

                                                            Avoid too many return statements within this method.
                                                            Open

                                                                        return "quarter";
                                                            Severity: Major
                                                            Found in app/controllers/ResultController.php - About 30 mins to fix

                                                              Avoid too many return statements within this method.
                                                              Open

                                                                              case "4": return "E major"; break;
                                                              Severity: Major
                                                              Found in app/controllers/ResultController.php - About 30 mins to fix

                                                                Avoid too many return statements within this method.
                                                                Open

                                                                                case "2": return "H minor"; break;
                                                                Severity: Major
                                                                Found in app/controllers/ResultController.php - About 30 mins to fix

                                                                  Avoid too many return statements within this method.
                                                                  Open

                                                                                  case "4": return "C sharp minor"; break;
                                                                  Severity: Major
                                                                  Found in app/controllers/ResultController.php - About 30 mins to fix

                                                                    Avoid too many return statements within this method.
                                                                    Open

                                                                                    case "6": return "D sharp minor"; break;
                                                                    Severity: Major
                                                                    Found in app/controllers/ResultController.php - About 30 mins to fix

                                                                      Avoid too many return statements within this method.
                                                                      Open

                                                                                      case "-3": return "C minor"; break;
                                                                      Severity: Major
                                                                      Found in app/controllers/ResultController.php - About 30 mins to fix

                                                                        Avoid too many return statements within this method.
                                                                        Open

                                                                                        case "-4": return "F minor"; break;
                                                                        Severity: Major
                                                                        Found in app/controllers/ResultController.php - About 30 mins to fix

                                                                          Avoid too many return statements within this method.
                                                                          Open

                                                                                          case "-7": return "A flat minor"; break;
                                                                          Severity: Major
                                                                          Found in app/controllers/ResultController.php - About 30 mins to fix

                                                                            Avoid too many return statements within this method.
                                                                            Open

                                                                                            case "-6": return "G flat major"; break;
                                                                            Severity: Major
                                                                            Found in app/controllers/ResultController.php - About 30 mins to fix

                                                                              Avoid too many return statements within this method.
                                                                              Open

                                                                                          return "16th";
                                                                              Severity: Major
                                                                              Found in app/controllers/ResultController.php - About 30 mins to fix

                                                                                Avoid too many return statements within this method.
                                                                                Open

                                                                                                case "-3": return "E flat major"; break;
                                                                                Severity: Major
                                                                                Found in app/controllers/ResultController.php - About 30 mins to fix

                                                                                  Avoid too many return statements within this method.
                                                                                  Open

                                                                                                  case "-6": return "E flat minor"; break;
                                                                                  Severity: Major
                                                                                  Found in app/controllers/ResultController.php - About 30 mins to fix

                                                                                    Avoid too many return statements within this method.
                                                                                    Open

                                                                                                return "eighth";
                                                                                    Severity: Major
                                                                                    Found in app/controllers/ResultController.php - About 30 mins to fix

                                                                                      Avoid too many return statements within this method.
                                                                                      Open

                                                                                                      case "5": return "H major"; break;
                                                                                      Severity: Major
                                                                                      Found in app/controllers/ResultController.php - About 30 mins to fix

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

                                                                                                            if ($pitch->length) {
                                                                                                                // it's a note
                                                                                                                $noteObject->type = "note";
                                                                                                                $noteObject->pitch = new stdClass();
                                                                                        
                                                                                        
                                                                                        Severity: Major
                                                                                        Found in app/controllers/ResultController.php and 1 other location - About 5 days to fix
                                                                                        app/controllers/ScoreController.php on lines 102..232

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

                                                                                        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

                                                                                            private function getDurationType($durationFloat) {
                                                                                                if ($durationFloat == 1){
                                                                                                    return "whole";
                                                                                                } elseif ($durationFloat == 0.75) {
                                                                                                    return "whole";
                                                                                        Severity: Major
                                                                                        Found in app/controllers/ResultController.php and 1 other location - About 4 hrs to fix
                                                                                        app/controllers/ScoreController.php on lines 256..289

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

                                                                                        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($fifths != null && $mode === "major"){
                                                                                                    switch($fifths) {
                                                                                                        case "0": return "C major"; break;
                                                                                                        case "1": return "G major"; break;
                                                                                                        case "2": return "D major"; break;
                                                                                        Severity: Major
                                                                                        Found in app/controllers/ResultController.php and 1 other location - About 2 hrs to fix
                                                                                        app/controllers/ResultController.php on lines 506..524

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

                                                                                        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

                                                                                                } elseif($fifths != null && $mode === "minor") {
                                                                                                    switch($fifths) {
                                                                                                        case "0": return "A minor"; break;
                                                                                                        case "1": return "E minor"; break;
                                                                                                        case "2": return "H minor"; break;
                                                                                        Severity: Major
                                                                                        Found in app/controllers/ResultController.php and 1 other location - About 2 hrs to fix
                                                                                        app/controllers/ResultController.php on lines 488..524

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

                                                                                        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

                                                                                        There are no issues that match your filters.

                                                                                        Category
                                                                                        Status