efureev/u.php

View on GitHub
src/uFile.php

Summary

Maintainability
B
5 hrs
Test Coverage

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

class uFile
{

    /**
     * Return File Extension
Severity: Minor
Found in src/uFile.php by phpmd

Method perms has 33 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public static function perms($file, $perms = null)
    {
        if (null === $perms) {
            if (!file_exists($file)) {
                return false;
Severity: Minor
Found in src/uFile.php - About 1 hr to fix

    Function perms has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

        public static function perms($file, $perms = null)
        {
            if (null === $perms) {
                if (!file_exists($file)) {
                    return false;
    Severity: Minor
    Found in src/uFile.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 normalizePath has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

        public static function normalizePath($path, $slash = DIRECTORY_SEPARATOR)
        {
            $path = rtrim(strtr($path, '/\\', $slash . $slash), $slash);
            if (strpos($slash . $path, "{$slash}.") === false && strpos($path, "{$slash}{$slash}") === false) {
                return $path;
    Severity: Minor
    Found in src/uFile.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 sizeFormat has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        public static function sizeFormat($bytes, $decimals = 0)
        {
            $bytes = floatval($bytes);
    
            if ($bytes < 1024) {
    Severity: Minor
    Found in src/uFile.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 number_format($bytes / pow(1024, 5), $decimals, '.', '') . ' PiB';
    Severity: Major
    Found in src/uFile.php - About 30 mins to fix

      Avoid too many return statements within this method.
      Open

                  return number_format($bytes / pow(1024, 4), $decimals, '.', '') . ' TiB';
      Severity: Major
      Found in src/uFile.php - About 30 mins to fix

        Avoid too many return statements within this method.
        Open

                    return number_format($bytes / pow(1024, 5), $decimals, '.', '') . ' PiB';
        Severity: Major
        Found in src/uFile.php - About 30 mins to fix

          The method perms() has an NPath complexity of 331776. The configured NPath complexity threshold is 200.
          Open

              public static function perms($file, $perms = null)
              {
                  if (null === $perms) {
                      if (!file_exists($file)) {
                          return false;
          Severity: Minor
          Found in src/uFile.php by phpmd

          NPathComplexity

          Since: 0.1

          The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.

          Example

          class Foo {
              function bar() {
                  // lots of complicated code
              }
          }

          Source https://phpmd.org/rules/codesize.html#npathcomplexity

          The method perms() has a Cyclomatic Complexity of 25. The configured cyclomatic complexity threshold is 10.
          Open

              public static function perms($file, $perms = null)
              {
                  if (null === $perms) {
                      if (!file_exists($file)) {
                          return false;
          Severity: Minor
          Found in src/uFile.php by phpmd

          CyclomaticComplexity

          Since: 0.1

          Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

          Example

          // Cyclomatic Complexity = 11
          class Foo {
          1   public function example() {
          2       if ($a == $b) {
          3           if ($a1 == $b1) {
                          fiddle();
          4           } elseif ($a2 == $b2) {
                          fiddle();
                      } else {
                          fiddle();
                      }
          5       } elseif ($c == $d) {
          6           while ($c == $d) {
                          fiddle();
                      }
          7        } elseif ($e == $f) {
          8           for ($n = 0; $n < $h; $n++) {
                          fiddle();
                      }
                  } else {
                      switch ($z) {
          9               case 1:
                              fiddle();
                              break;
          10              case 2:
                              fiddle();
                              break;
          11              case 3:
                              fiddle();
                              break;
                          default:
                              fiddle();
                              break;
                      }
                  }
              }
          }

          Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity

          The method normalizePath() has a Cyclomatic Complexity of 11. The configured cyclomatic complexity threshold is 10.
          Open

              public static function normalizePath($path, $slash = DIRECTORY_SEPARATOR)
              {
                  $path = rtrim(strtr($path, '/\\', $slash . $slash), $slash);
                  if (strpos($slash . $path, "{$slash}.") === false && strpos($path, "{$slash}{$slash}") === false) {
                      return $path;
          Severity: Minor
          Found in src/uFile.php by phpmd

          CyclomaticComplexity

          Since: 0.1

          Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

          Example

          // Cyclomatic Complexity = 11
          class Foo {
          1   public function example() {
          2       if ($a == $b) {
          3           if ($a1 == $b1) {
                          fiddle();
          4           } elseif ($a2 == $b2) {
                          fiddle();
                      } else {
                          fiddle();
                      }
          5       } elseif ($c == $d) {
          6           while ($c == $d) {
                          fiddle();
                      }
          7        } elseif ($e == $f) {
          8           for ($n = 0; $n < $h; $n++) {
                          fiddle();
                      }
                  } else {
                      switch ($z) {
          9               case 1:
                              fiddle();
                              break;
          10              case 2:
                              fiddle();
                              break;
          11              case 3:
                              fiddle();
                              break;
                          default:
                              fiddle();
                              break;
                      }
                  }
              }
          }

          Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity

          Missing class import via use statement (line '250', column '28').
          Open

                  $dirIterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir, $flags));
          Severity: Minor
          Found in src/uFile.php by phpmd

          MissingImport

          Since: 2.7.0

          Importing all external classes in a file through use statements makes them clearly visible.

          Example

          function make() {
              return new \stdClass();
          }

          Source http://phpmd.org/rules/cleancode.html#MissingImport

          Missing class import via use statement (line '96', column '23').
          Open

                      throw new \Exception('File missing: ' . $file);
          Severity: Minor
          Found in src/uFile.php by phpmd

          MissingImport

          Since: 2.7.0

          Importing all external classes in a file through use statements makes them clearly visible.

          Example

          function make() {
              return new \stdClass();
          }

          Source http://phpmd.org/rules/cleancode.html#MissingImport

          Missing class import via use statement (line '250', column '59').
          Open

                  $dirIterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir, $flags));
          Severity: Minor
          Found in src/uFile.php by phpmd

          MissingImport

          Since: 2.7.0

          Importing all external classes in a file through use statements makes them clearly visible.

          Example

          function make() {
              return new \stdClass();
          }

          Source http://phpmd.org/rules/cleancode.html#MissingImport

          The method size has a boolean flag argument $format, which is a certain sign of a Single Responsibility Principle violation.
          Open

              public static function size($file, $format = true)
          Severity: Minor
          Found in src/uFile.php by phpmd

          BooleanArgumentFlag

          Since: 1.4.0

          A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

          Example

          class Foo {
              public function bar($flag = true) {
              }
          }

          Source https://phpmd.org/rules/cleancode.html#booleanargumentflag

          Missing class import via use statement (line '229', column '24').
          Open

                  $dirIter = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir, $flags));
          Severity: Minor
          Found in src/uFile.php by phpmd

          MissingImport

          Since: 2.7.0

          Importing all external classes in a file through use statements makes them clearly visible.

          Example

          function make() {
              return new \stdClass();
          }

          Source http://phpmd.org/rules/cleancode.html#MissingImport

          Missing class import via use statement (line '229', column '55').
          Open

                  $dirIter = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir, $flags));
          Severity: Minor
          Found in src/uFile.php by phpmd

          MissingImport

          Since: 2.7.0

          Importing all external classes in a file through use statements makes them clearly visible.

          Example

          function make() {
              return new \stdClass();
          }

          Source http://phpmd.org/rules/cleancode.html#MissingImport

          Avoid unused local variables such as '$fi'.
          Open

                  foreach ($dirIter as $path => $fi) {
          Severity: Minor
          Found in src/uFile.php by phpmd

          UnusedLocalVariable

          Since: 0.2

          Detects when a local variable is declared and/or assigned, but not used.

          Example

          class Foo {
              public function doSomething()
              {
                  $i = 5; // Unused
              }
          }

          Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable

          Avoid using short method names like uFile::ls(). The configured minimum method name length is 3.
          Open

              public static function ls($dir)
              {
                  $contents = [];
                  $flags = \FilesystemIterator::KEY_AS_PATHNAME
                      | \FilesystemIterator::CURRENT_AS_FILEINFO
          Severity: Minor
          Found in src/uFile.php by phpmd

          ShortMethodName

          Since: 0.2

          Detects when very short method names are used.

          Example

          class ShortMethod {
              public function a( $index ) { // Violation
              }
          }

          Source https://phpmd.org/rules/naming.html#shortmethodname

          The class uFile is not named in CamelCase.
          Open

          class uFile
          {
          
              /**
               * Return File Extension
          Severity: Minor
          Found in src/uFile.php by phpmd

          CamelCaseClassName

          Since: 0.2

          It is considered best practice to use the CamelCase notation to name classes.

          Example

          class class_name {
          }

          Source

          The closing brace for the class must go on the next line after the body
          Open

          }
          Severity: Minor
          Found in src/uFile.php by phpcodesniffer

          Inline control structures are not allowed
          Open

                  if (!file_exists($file))
          Severity: Minor
          Found in src/uFile.php by phpcodesniffer

          Class name "uFile" is not in camel caps format
          Open

          class uFile
          Severity: Minor
          Found in src/uFile.php by phpcodesniffer

          There are no issues that match your filters.

          Category
          Status