mambax7/tdmdownloads

View on GitHub
class/Utility.php

Summary

Maintainability
F
3 days
Test Coverage

File Utility.php has 363 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

declare(strict_types=1);

namespace XoopsModules\Tdmdownloads;
Severity: Minor
Found in class/Utility.php - About 4 hrs to fix

    Function getPathTreeUrl has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
    Open

        public static function getPathTreeUrl($mytree, $key, $category_array, $title, $prefix = '', $link = false, $order = 'ASC', $lasturl = false)
        {
            global $xoopsModule;
            $categoryParent = $mytree->getAllParent($key);
            if ('ASC' === $order) {
    Severity: Minor
    Found in class/Utility.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 getStatusImage has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

        public function getStatusImage($time, $status)
        {
            global $xoopsModuleConfig;
            $moduleDirName = \basename(\dirname(__DIR__));
            $helper        = Helper::getInstance();
    Severity: Minor
    Found in class/Utility.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 getPathTreeUrl has 41 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public static function getPathTreeUrl($mytree, $key, $category_array, $title, $prefix = '', $link = false, $order = 'ASC', $lasturl = false)
        {
            global $xoopsModule;
            $categoryParent = $mytree->getAllParent($key);
            if ('ASC' === $order) {
    Severity: Minor
    Found in class/Utility.php - About 1 hr to fix

      Function convertSizeToString has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

          public static function convertSizeToString($sizeString)
          {
              $mysizeString = '';
              if ('' != $sizeString) {
                  $size_value_arr = \explode(' ', $sizeString);
      Severity: Minor
      Found in class/Utility.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 getNumbersOfEntries has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

          public function getNumbersOfEntries($mytree, $categories, $entries, $cid)
          {
              $count     = 0;
              $child_arr = [];
              if (\in_array($cid, $categories)) {
      Severity: Minor
      Found in class/Utility.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 getStatusImage has 30 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function getStatusImage($time, $status)
          {
              global $xoopsModuleConfig;
              $moduleDirName = \basename(\dirname(__DIR__));
              $helper        = Helper::getInstance();
      Severity: Minor
      Found in class/Utility.php - About 1 hr to fix

        Method convertSizeToString has 28 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public static function convertSizeToString($sizeString)
            {
                $mysizeString = '';
                if ('' != $sizeString) {
                    $size_value_arr = \explode(' ', $sizeString);
        Severity: Minor
        Found in class/Utility.php - About 1 hr to fix

          Method getPathTreeUrl has 8 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              public static function getPathTreeUrl($mytree, $key, $category_array, $title, $prefix = '', $link = false, $order = 'ASC', $lasturl = false)
          Severity: Major
          Found in class/Utility.php - About 1 hr to fix

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

                public static function openCollapsableBar($tablename = '', $iconname = '', $tabletitle = '', $tabledsc = '', $open = true)
            Severity: Minor
            Found in class/Utility.php - About 35 mins to fix

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

                  public static function getPathTree($mytree, $key, $category_array, $title, $prefix = '')
              Severity: Minor
              Found in class/Utility.php - About 35 mins to fix

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

                    public static function getFileSize($url)
                    {
                        if (\function_exists('curl_init') && false !== ($curlHandle = \curl_init($url))) {
                            \curl_setopt($curlHandle, \CURLOPT_RETURNTRANSFER, true);
                            \curl_setopt($curlHandle, \CURLOPT_HEADER, true);
                Severity: Minor
                Found in class/Utility.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 convertFileSize has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                    public static function convertFileSize($size)
                    {
                        if ($size > 0) {
                            $kb = 1024;
                            $mb = 1024 * 1024;
                Severity: Minor
                Found in class/Utility.php - About 25 mins to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

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

                    public static function convertStringToSize($stringSize)
                    {
                        if ('' != $stringSize) {
                            $kb             = 1024;
                            $mb             = 1024 * 1024;
                Severity: Minor
                Found in class/Utility.php - About 25 mins to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

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

                    public function getPopularImage($hits)
                    {
                        global $xoopsModuleConfig;
                        $moduleDirName = \basename(\dirname(__DIR__));
                        $pop           = '';
                Severity: Minor
                Found in class/Utility.php - About 25 mins to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

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

                                if (1 == $status) {
                                    if (\is_readable($img_path . 'new.png')) {
                                        $new = '&nbsp;<img src="' . $img_url . 'new.png" alt="' . _MD_TDMDOWNLOADS_INDEX_NEWTHISWEEK . '" title="' . _MD_TDMDOWNLOADS_INDEX_NEWTHISWEEK . '">';
                                    } else {
                                        $new = '&nbsp;<img src="' . XOOPS_URL . '/modules/' . $moduleDirName . '/language/english/new.png" alt="' . _MD_TDMDOWNLOADS_INDEX_NEWTHISWEEK . '" title="' . _MD_TDMDOWNLOADS_INDEX_NEWTHISWEEK . '">';
                Severity: Major
                Found in class/Utility.php and 1 other location - About 7 hrs to fix
                class/Utilities.php on lines 105..117

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

                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 ('ASC' === $order) {
                            if (\array_key_exists($key, $category_array)) {
                                if ($lasturl) {
                                    $firstCategory = '<a href="viewcat.php?cid=' . $category_array[$key]->getVar('cat_cid') . '">' . $category_array[$key]->getVar($title) . '</a>';
                                } else {
                Severity: Major
                Found in class/Utility.php and 1 other location - About 3 hrs to fix
                class/Utilities.php on lines 272..287

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

                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