learningworks/moodle-block_lw_courses

View on GitHub

Showing 31 of 169 total issues

Function lw_courses has a Cognitive Complexity of 61 (exceeds 5 allowed). Consider refactoring.
Open

    public function lw_courses($courses) {
        global $CFG, $PAGE, $DB, $OUTPUT;
        $html = '';
        // LearningWorks.
        $PAGE->requires->js(new moodle_url($CFG->wwwroot.'/blocks/lw_courses/js/custom.js'));
Severity: Minor
Found in renderer.php - About 1 day 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 lw_courses has 167 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function lw_courses($courses) {
        global $CFG, $PAGE, $DB, $OUTPUT;
        $html = '';
        // LearningWorks.
        $PAGE->requires->js(new moodle_url($CFG->wwwroot.'/blocks/lw_courses/js/custom.js'));
Severity: Major
Found in renderer.php - About 6 hrs to fix

    File renderer.php has 359 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    <?php
    // This file is part of Moodle - http://moodle.org/
    //
    // Moodle is free software: you can redistribute it and/or modify
    // it under the terms of the GNU General Public License as published by
    Severity: Minor
    Found in renderer.php - About 4 hrs to fix

      The class block_lw_courses_renderer has an overall complexity of 72 which is very high. The configured complexity threshold is 50.
      Open

      class block_lw_courses_renderer extends plugin_renderer_base {
      
          /**
           * Construct contents of lw_courses block
           *
      Severity: Minor
      Found in renderer.php by phpmd

      Function add_handles has 74 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      M.block_lw_courses.add_handles = function(Y) {
          M.block_lw_courses.Y = Y;
          var MOVEICON = {
              pix: "i/move_2d",
              component: 'moodle'
      Severity: Major
      Found in module.js - About 2 hrs to fix

        Function block_lw_courses_get_sorted_courses has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
        Open

        function block_lw_courses_get_sorted_courses($showallcourses = false) {
            global $USER;
        
            $limit = block_lw_courses_get_max_user_courses($showallcourses);
        
        
        Severity: Minor
        Found in locallib.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 course_image has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
        Open

            public function course_image($course) {
                global $CFG;
        
                $course = new core_course_list_element($course);
                // Check to see if a file has been set on the course level.
        Severity: Minor
        Found in renderer.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 block_lw_courses_get_sorted_courses has 45 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        function block_lw_courses_get_sorted_courses($showallcourses = false) {
            global $USER;
        
            $limit = block_lw_courses_get_max_user_courses($showallcourses);
        
        
        Severity: Minor
        Found in locallib.php - About 1 hr to fix

          Function CollapsibleRegion has 36 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          M.block_lw_courses.CollapsibleRegion = function(Y, id, userpref, strtooltip) {
              // Record the pref name.
              this.userpref = userpref;
          
              // Find the divs in the document.
          Severity: Minor
          Found in module.js - About 1 hr to fix

            Method get_content has 32 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function get_content() {
                    global $USER, $CFG;
                    require_once($CFG->dirroot.'/user/profile/lib.php');
            
                    if ($this->content !== null) {
            Severity: Minor
            Found in block_lw_courses.php - About 1 hr to fix

              Method block_lw_courses_get_child_shortnames has 30 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              function block_lw_courses_get_child_shortnames($courseid) {
                  global $DB;
                  $ctxselect = context_helper::get_preload_record_columns_sql('ctx');
                  $sql = "SELECT c.id, c.shortname, $ctxselect
                          FROM {enrol} e
              Severity: Minor
              Found in locallib.php - About 1 hr to fix

                Function truncate_html has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                Open

                    public function truncate_html($s, $l, $e = '&hellip;') {
                        $s = trim($s);
                        $e = (strlen(strip_tags($s)) > $l) ? $e : '';
                        $i = 0;
                        $tags = array();
                Severity: Minor
                Found in renderer.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 block_lw_courses_get_overviews has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                Open

                function block_lw_courses_get_overviews($courses) {
                    $htmlarray = array();
                    if ($modules = get_plugin_list_with_function('mod', 'print_overview')) {
                        // Split courses list into batches with no more than MAX_MODINFO_CACHE_SIZE courses in one batch.
                        // Otherwise we exceed the cache limit in get_fast_modinfo() and rebuild it too often.
                Severity: Minor
                Found in locallib.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 course_image has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    public function course_image($course) {
                        global $CFG;
                
                        $course = new core_course_list_element($course);
                        // Check to see if a file has been set on the course level.
                Severity: Minor
                Found in renderer.php - About 1 hr to fix

                  Function block_lw_courses_get_child_shortnames has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                  Open

                  function block_lw_courses_get_child_shortnames($courseid) {
                      global $DB;
                      $ctxselect = context_helper::get_preload_record_columns_sql('ctx');
                      $sql = "SELECT c.id, c.shortname, $ctxselect
                              FROM {enrol} e
                  Severity: Minor
                  Found in locallib.php - About 55 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 block_lw_courses_pluginfile has 7 arguments (exceeds 4 allowed). Consider refactoring.
                  Open

                  function block_lw_courses_pluginfile($course, $birecord, $context, $filearea, $args, $forcedownload, array $options = array()) {
                  Severity: Major
                  Found in lib.php - About 50 mins to fix

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

                        protected function collapsible_region($contents, $classes, $id, $caption, $userpref = '', $default = false) {
                    Severity: Minor
                    Found in renderer.php - About 45 mins to fix

                      Method collapsible_region_start has 5 arguments (exceeds 4 allowed). Consider refactoring.
                      Open

                          protected function collapsible_region_start($classes, $id, $caption, $userpref = '', $default = false) {
                      Severity: Minor
                      Found in renderer.php - About 35 mins to fix

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

                            public function welcome_area($msgcount) {
                                global $CFG, $USER;
                                $output = $this->output->box_start('welcome_area');
                        
                                $picture = $this->output->user_picture($USER, array('size' => 75, 'class' => 'welcome_userpicture'));
                        Severity: Minor
                        Found in renderer.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 get_content has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                        Open

                            public function get_content() {
                                global $USER, $CFG;
                                require_once($CFG->dirroot.'/user/profile/lib.php');
                        
                                if ($this->content !== null) {
                        Severity: Minor
                        Found in block_lw_courses.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

                        Severity
                        Category
                        Status
                        Source
                        Language