symphonycms/symphony-2

View on GitHub
symphony/lib/toolkit/class.general.php

Summary

Maintainability
F
1 wk
Test Coverage

File class.general.php has 791 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * @package toolkit
 */
/**
Severity: Major
Found in symphony/lib/toolkit/class.general.php - About 1 day to fix

    General has 53 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class General
    {
        /**
         * Convert any special characters into their entity equivalents. Since
         * Symphony 2.3, this function assumes UTF-8 and will not double
    Severity: Major
    Found in symphony/lib/toolkit/class.general.php - About 7 hrs to fix

      Function listStructure has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
      Open

          public static function listStructure($dir = ".", $filters = array(), $recurse = true, $sort = "asc", $strip_root = null, $exclude = array(), $ignore_hidden = true)
          {
              if (!is_dir($dir)) {
                  return null;
              }
      Severity: Minor
      Found in symphony/lib/toolkit/class.general.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

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

          public static function processFilePostData($filedata)
          {
              $result = array();
      
              foreach ($filedata as $key => $data) {
      Severity: Minor
      Found in symphony/lib/toolkit/class.general.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 array_to_xml has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
      Open

          public static function array_to_xml(XMLElement $parent, array $data, $validate = false)
          {
              foreach ($data as $element_name => $value) {
                  if (!is_numeric($value) && empty($value)) {
                      continue;
      Severity: Minor
      Found in symphony/lib/toolkit/class.general.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 listDirStructure has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

          public static function listDirStructure($dir = '.', $filter = null, $recurse = true, $strip_root = null, $exclude = array(), $ignore_hidden = true)
          {
              if (!is_dir($dir)) {
                  return null;
              }
      Severity: Minor
      Found in symphony/lib/toolkit/class.general.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 listStructure has 48 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public static function listStructure($dir = ".", $filters = array(), $recurse = true, $sort = "asc", $strip_root = null, $exclude = array(), $ignore_hidden = true)
          {
              if (!is_dir($dir)) {
                  return null;
              }
      Severity: Minor
      Found in symphony/lib/toolkit/class.general.php - About 1 hr to fix

        Method getMimeType has 44 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public static function getMimeType($file)
            {
                if (!empty($file)) {
                    // in PHP 5.3 we can use 'finfo'
                    if (PHP_VERSION_ID >= 50300 && function_exists('finfo_open')) {
        Severity: Minor
        Found in symphony/lib/toolkit/class.general.php - About 1 hr to fix

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

              public static function ensureType(array $params)
              {
                  foreach ($params as $name => $param) {
                      if (isset($param['optional']) && ($param['optional'] === true)) {
                          if (empty($param['var'])) {
          Severity: Minor
          Found in symphony/lib/toolkit/class.general.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 validateString has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
          Open

              public static function validateString($string, $rule)
              {
                  if (!is_array($rule) && ($rule == '' || $rule == null)) {
                      return true;
                  }
          Severity: Minor
          Found in symphony/lib/toolkit/class.general.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 in_array_multi has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
          Open

              public static function in_array_multi($needle, $haystack)
              {
                  if ($needle == $haystack) {
                      return true;
                  }
          Severity: Minor
          Found in symphony/lib/toolkit/class.general.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 deleteDirectory has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

              public static function deleteDirectory($dir, $silent = true)
              {
                  try {
                      if (!@file_exists($dir)) {
                          return true;
          Severity: Minor
          Found in symphony/lib/toolkit/class.general.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 getPostData has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

              public static function getPostData()
              {
                  $files = array(
                      'name'      => array(),
                      'type'      => array(),
          Severity: Minor
          Found in symphony/lib/toolkit/class.general.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 createHandle has 31 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public static function createHandle($string, $max_length = 255, $delim = '-', $uriencode = false, $additional_rule_set = null)
              {
                  // If empty, bail out quick
                  if (empty(trim($string))) {
                      return '';
          Severity: Minor
          Found in symphony/lib/toolkit/class.general.php - About 1 hr to fix

            Method validateXML has 27 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public static function validateXML($data, &$errors, $isFile = true, $xsltProcessor = null, $encoding = 'UTF-8')
                {
                    $_data = ($isFile) ? file_get_contents($data) : $data;
                    $_data = preg_replace('/<!DOCTYPE[-.:"\'\/\\w\\s]+>/', null, $_data);
            
            
            Severity: Minor
            Found in symphony/lib/toolkit/class.general.php - About 1 hr to fix

              Consider simplifying this complex logical expression.
              Open

                          if (
                              ($file == '.' || $file == '..')
                              || ($ignore_hidden && $file{0} == '.')
                              || !is_dir("$dir/$file")
                              || in_array($file, $exclude)
              Severity: Major
              Found in symphony/lib/toolkit/class.general.php - About 1 hr to fix

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

                    public static function flattenArray(array &$source, &$output = null, $path = null)
                    {
                        if (is_null($output)) {
                            $output = array();
                        }
                Severity: Minor
                Found in symphony/lib/toolkit/class.general.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

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

                    public static function getMimeType($file)
                    {
                        if (!empty($file)) {
                            // in PHP 5.3 we can use 'finfo'
                            if (PHP_VERSION_ID >= 50300 && function_exists('finfo_open')) {
                Severity: Minor
                Found in symphony/lib/toolkit/class.general.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

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

                    public static function createHandle($string, $max_length = 255, $delim = '-', $uriencode = false, $additional_rule_set = null)
                    {
                        // If empty, bail out quick
                        if (empty(trim($string))) {
                            return '';
                Severity: Minor
                Found in symphony/lib/toolkit/class.general.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 listStructure has 7 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                    public static function listStructure($dir = ".", $filters = array(), $recurse = true, $sort = "asc", $strip_root = null, $exclude = array(), $ignore_hidden = true)
                Severity: Major
                Found in symphony/lib/toolkit/class.general.php - About 50 mins to fix

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

                      public static function listDirStructure($dir = '.', $filter = null, $recurse = true, $strip_root = null, $exclude = array(), $ignore_hidden = true)
                  Severity: Minor
                  Found in symphony/lib/toolkit/class.general.php - About 45 mins to fix

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

                        public static function uploadFile($dest_path, $dest_name, $tmp_name, $perm = 0644)
                        {
                            // Upload the file
                            if (@is_uploaded_file($tmp_name)) {
                                $dest_path = rtrim($dest_path, '/') . '/';
                    Severity: Minor
                    Found in symphony/lib/toolkit/class.general.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 (
                                    ($file == '.' || $file === '..')
                                    || ($ignore_hidden && $file{0} === '.')
                                    || in_array($file, $exclude)
                                    || in_array("$dir/$file", $exclude)
                    Severity: Major
                    Found in symphony/lib/toolkit/class.general.php - About 40 mins to fix

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

                          public static function createHandle($string, $max_length = 255, $delim = '-', $uriencode = false, $additional_rule_set = null)
                      Severity: Minor
                      Found in symphony/lib/toolkit/class.general.php - About 35 mins to fix

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

                            public static function validateXML($data, &$errors, $isFile = true, $xsltProcessor = null, $encoding = 'UTF-8')
                        Severity: Minor
                        Found in symphony/lib/toolkit/class.general.php - About 35 mins to fix

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

                              public static function createXMLDateObject($timestamp, $element = 'date', $date_format = 'Y-m-d', $time_format = 'H:i', $namespace = null)
                          Severity: Minor
                          Found in symphony/lib/toolkit/class.general.php - About 35 mins to fix

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

                                public static function writeFile($file, $data, $perm = 0644, $mode = 'w', $trim = false)
                            Severity: Minor
                            Found in symphony/lib/toolkit/class.general.php - About 35 mins to fix

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

                                  public static function validateXML($data, &$errors, $isFile = true, $xsltProcessor = null, $encoding = 'UTF-8')
                                  {
                                      $_data = ($isFile) ? file_get_contents($data) : $data;
                                      $_data = preg_replace('/<!DOCTYPE[-.:"\'\/\\w\\s]+>/', null, $_data);
                              
                              
                              Severity: Minor
                              Found in symphony/lib/toolkit/class.general.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

                              Avoid too many return statements within this method.
                              Open

                                      return true;
                              Severity: Major
                              Found in symphony/lib/toolkit/class.general.php - About 30 mins to fix

                                Avoid too many return statements within this method.
                                Open

                                            return false;
                                Severity: Major
                                Found in symphony/lib/toolkit/class.general.php - About 30 mins to fix

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

                                      public static function writeFile($file, $data, $perm = 0644, $mode = 'w', $trim = false)
                                      {
                                          if (static::checkFileWritable($file) === false) {
                                              return false;
                                          }
                                  Severity: Minor
                                  Found in symphony/lib/toolkit/class.general.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 limitWords has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                  Open

                                      public static function limitWords($string, $maxChars = 200, $appendHellip = false)
                                      {
                                          if ($appendHellip) {
                                              $maxChars -= 1;
                                          }
                                  Severity: Minor
                                  Found in symphony/lib/toolkit/class.general.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 mergeFilePostData has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                  Open

                                      protected static function mergeFilePostData($type, array $file, array &$post)
                                      {
                                          foreach ($file as $key => $value) {
                                              if (!isset($post[$key])) {
                                                  $post[$key] = array();
                                  Severity: Minor
                                  Found in symphony/lib/toolkit/class.general.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

                                  There are no issues that match your filters.

                                  Category
                                  Status