Admidio/admidio

View on GitHub
adm_program/system/classes/FileSystemUtils.php

Summary

Maintainability
F
5 days
Test Coverage

File FileSystemUtils.php has 745 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

use Admidio\Exception;

/**
Severity: Major
Found in adm_program/system/classes/FileSystemUtils.php - About 1 day to fix

    FileSystemUtils has 41 functions (exceeds 20 allowed). Consider refactoring.
    Open

    final class FileSystemUtils
    {
        public const CONTENT_TYPE_DIRECTORY = 'directory';
        public const CONTENT_TYPE_FILE      = 'file';
        public const CONTENT_TYPE_LINK      = 'link';
    Severity: Minor
    Found in adm_program/system/classes/FileSystemUtils.php - About 5 hrs to fix

      Function getDirectoryContent has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
      Open

          public static function getDirectoryContent(string $directoryPath, bool $recursive = false, bool $fullPath = true, array $includedContentTypes = array(self::CONTENT_TYPE_DIRECTORY, self::CONTENT_TYPE_FILE, self::CONTENT_TYPE_LINK)): array
          {
              self::checkIsInAllowedDirectories($directoryPath);
      
              if (!is_dir($directoryPath)) {
      Severity: Minor
      Found in adm_program/system/classes/FileSystemUtils.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 createDirectoryIfNotExists has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

          public static function createDirectoryIfNotExists(string $directoryPath, array $options = array()): bool
          {
              self::checkIsInAllowedDirectories($directoryPath);
      
              $defaultOptions = array('mode' => self::DEFAULT_MODE_DIRECTORY, 'modeParents' => self::DEFAULT_MODE_DIRECTORY, 'createDirectoryStructure' => true);
      Severity: Minor
      Found in adm_program/system/classes/FileSystemUtils.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 convertPermsToString has 41 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          private static function convertPermsToString(int $perms): string
          {
              switch ($perms & 0xF000) {
                  case 0xC000: // Socket
                      $info = 's';
      Severity: Minor
      Found in adm_program/system/classes/FileSystemUtils.php - About 1 hr to fix

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

            public static function deleteDirectoryContentIfExists(string $directoryPath): bool
            {
                self::checkIsInAllowedDirectories($directoryPath);
        
                if (!is_dir($directoryPath)) {
        Severity: Minor
        Found in adm_program/system/classes/FileSystemUtils.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 checkDirectoryContentTreeCollisions has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

            private static function checkDirectoryContentTreeCollisions(array $directoryContentTree1, array $directoryContentTree2, bool $considerDirectoryCollisions = false): bool
            {
                foreach ($directoryContentTree1 as $directoryContentName => $directoryContentType1) {
                    if (array_key_exists($directoryContentName, $directoryContentTree2)) {
                        if ($considerDirectoryCollisions) {
        Severity: Minor
        Found in adm_program/system/classes/FileSystemUtils.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 checkFilePreconditions has 38 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            private static function checkFilePreconditions(string $mode, string $oldFilePath, string $newFilePath, array $options = array()): bool
            {
                $defaultOptions = array('createDirectoryStructure' => true, 'overwrite' => false);
                $options = array_merge($defaultOptions, $options);
        
        
        Severity: Minor
        Found in adm_program/system/classes/FileSystemUtils.php - About 1 hr to fix

          Method createDirectoryIfNotExists has 36 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public static function createDirectoryIfNotExists(string $directoryPath, array $options = array()): bool
              {
                  self::checkIsInAllowedDirectories($directoryPath);
          
                  $defaultOptions = array('mode' => self::DEFAULT_MODE_DIRECTORY, 'modeParents' => self::DEFAULT_MODE_DIRECTORY, 'createDirectoryStructure' => true);
          Severity: Minor
          Found in adm_program/system/classes/FileSystemUtils.php - About 1 hr to fix

            Function checkFilePreconditions has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
            Open

                private static function checkFilePreconditions(string $mode, string $oldFilePath, string $newFilePath, array $options = array()): bool
                {
                    $defaultOptions = array('createDirectoryStructure' => true, 'overwrite' => false);
                    $options = array_merge($defaultOptions, $options);
            
            
            Severity: Minor
            Found in adm_program/system/classes/FileSystemUtils.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 getNormalizedPath has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
            Open

                public static function getNormalizedPath(string $path): string
                {
                    $path = str_replace('\\', '/', $path); // Replace back-slashes with forward-slashes
                    $path = preg_replace('/\/+/', '/', $path); // Combine multiple slashes into a single slash
            
            
            Severity: Minor
            Found in adm_program/system/classes/FileSystemUtils.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 checkDirectoryPreconditions has 33 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                private static function checkDirectoryPreconditions(string $oldDirectoryPath, string $newDirectoryPath, array $options = array()): bool
                {
                    self::checkIsInAllowedDirectories($oldDirectoryPath);
                    self::checkIsInAllowedDirectories($newDirectoryPath);
            
            
            Severity: Minor
            Found in adm_program/system/classes/FileSystemUtils.php - About 1 hr to fix

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

                  public static function getDirectoryContent(string $directoryPath, bool $recursive = false, bool $fullPath = true, array $includedContentTypes = array(self::CONTENT_TYPE_DIRECTORY, self::CONTENT_TYPE_FILE, self::CONTENT_TYPE_LINK)): array
                  {
                      self::checkIsInAllowedDirectories($directoryPath);
              
                      if (!is_dir($directoryPath)) {
              Severity: Minor
              Found in adm_program/system/classes/FileSystemUtils.php - About 1 hr to fix

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

                    public static function chmodDirectory(string $directoryPath, int $mode = self::DEFAULT_MODE_DIRECTORY, bool $recursive = false, bool $onlyDirectories = true)
                    {
                        if (!self::isUnixWithPosix()) {
                            throw new RuntimeException('"FileSystemUtils::chmodDirectory()" is only available on systems with POSIX support!');
                        }
                Severity: Minor
                Found in adm_program/system/classes/FileSystemUtils.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 deleteDirectoryContentIfExists has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    public static function deleteDirectoryContentIfExists(string $directoryPath): bool
                    {
                        self::checkIsInAllowedDirectories($directoryPath);
                
                        if (!is_dir($directoryPath)) {
                Severity: Minor
                Found in adm_program/system/classes/FileSystemUtils.php - About 1 hr to fix

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

                      public static function deleteDirectoryIfExists(string $directoryPath, bool $deleteWithContent = false): bool
                      {
                          self::checkIsInAllowedDirectories($directoryPath);
                  
                          if ($directoryPath === self::ROOT_FOLDER) {
                  Severity: Minor
                  Found in adm_program/system/classes/FileSystemUtils.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 writeFile has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                  Open

                      public static function writeFile(string $filePath, string $data, bool $append = false): int
                      {
                          self::checkIsInAllowedDirectories($filePath);
                  
                          $parentDirectoryPath = dirname($filePath);
                  Severity: Minor
                  Found in adm_program/system/classes/FileSystemUtils.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 checkDirectoryPreconditions has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                  Open

                      private static function checkDirectoryPreconditions(string $oldDirectoryPath, string $newDirectoryPath, array $options = array()): bool
                      {
                          self::checkIsInAllowedDirectories($oldDirectoryPath);
                          self::checkIsInAllowedDirectories($newDirectoryPath);
                  
                  
                  Severity: Minor
                  Found in adm_program/system/classes/FileSystemUtils.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 deleteDirectoryIfExists has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      public static function deleteDirectoryIfExists(string $directoryPath, bool $deleteWithContent = false): bool
                      {
                          self::checkIsInAllowedDirectories($directoryPath);
                  
                          if ($directoryPath === self::ROOT_FOLDER) {
                  Severity: Minor
                  Found in adm_program/system/classes/FileSystemUtils.php - About 1 hr to fix

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

                        private static function convertPermsToString(int $perms): string
                        {
                            switch ($perms & 0xF000) {
                                case 0xC000: // Socket
                                    $info = 's';
                    Severity: Minor
                    Found in adm_program/system/classes/FileSystemUtils.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

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

                        private static function doCopyDirectory(string $oldDirectoryPath, string $newDirectoryPath)
                        {
                            $oldDirectoryContent = self::getDirectoryContent($oldDirectoryPath, false, false);
                    
                            foreach ($oldDirectoryContent as $entry => $type) {
                    Severity: Minor
                    Found in adm_program/system/classes/FileSystemUtils.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 isDirectoryEmpty has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                    Open

                        public static function isDirectoryEmpty(string $directoryPath): bool
                        {
                            self::checkIsInAllowedDirectories($directoryPath);
                    
                            if (!is_dir($directoryPath)) {
                    Severity: Minor
                    Found in adm_program/system/classes/FileSystemUtils.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 chmodFile has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                    Open

                        public static function chmodFile(string $filePath, int $mode = self::DEFAULT_MODE_FILE)
                        {
                            if (!self::isUnixWithPosix()) {
                                throw new RuntimeException('"FileSystemUtils::chmodFile()" is only available on systems with POSIX support!');
                            }
                    Severity: Minor
                    Found in adm_program/system/classes/FileSystemUtils.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

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

                        public static function getPathOwnerInfo(string $path): array
                        {
                            if (!self::isUnixWithPosix()) {
                                throw new RuntimeException('"FileSystemUtils::getPathOwnerInfo()" is only available on systems with POSIX support!');
                            }
                    Severity: Major
                    Found in adm_program/system/classes/FileSystemUtils.php and 1 other location - About 1 hr to fix
                    adm_program/system/classes/FileSystemUtils.php on lines 924..940

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

                    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

                        public static function getPathGroupInfo(string $path): array
                        {
                            if (!self::isUnix()) {
                                throw new RuntimeException('"FileSystemUtils::getPathGroupInfo()" is only available on systems with POSIX support!');
                            }
                    Severity: Major
                    Found in adm_program/system/classes/FileSystemUtils.php and 1 other location - About 1 hr to fix
                    adm_program/system/classes/FileSystemUtils.php on lines 898..914

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

                    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