bluetree-service/filesystem

View on GitHub
src/StaticObjects/Fs.php

Summary

Maintainability
B
4 hrs
Test Coverage

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

class Fs implements FsInterface
{
    /**
     * @var EventDispatcherInterface
     */
Severity: Minor
Found in src/StaticObjects/Fs.php by phpmd

File Fs.php has 274 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

namespace BlueFilesystem\StaticObjects;

use BlueEvent\Event\Base\Interfaces\EventDispatcherInterface;
Severity: Minor
Found in src/StaticObjects/Fs.php - About 2 hrs to fix

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

        public static function mkdir(string $path): array
        {
            $newPath = '';
            $operationList = [];
            $bool = \preg_match(self::RESTRICTED_SYMBOLS, $path);
    Severity: Minor
    Found in src/StaticObjects/Fs.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

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

            array $dirPaths,
            string $source,
            string $target,
            string $dirToCopy,
            array $operationList
    Severity: Minor
    Found in src/StaticObjects/Fs.php - About 35 mins to fix

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

          public static function rename(string $source, string $target, bool $force = false): bool
          {
              $status = true;
      
              self::setForceMode([$source], $force);
      Severity: Minor
      Found in src/StaticObjects/Fs.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 mkfile has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          public static function mkfile(string $path, string $fileName, $data = null): bool
          {
              $status = false;
      
              self::triggerEvent(self::CREATE_FILE_BEFORE, [&$path, &$fileName, &$data]);
      Severity: Minor
      Found in src/StaticObjects/Fs.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

      Avoid using undefined variables such as '$creationDir' which will lead to PHP notices.
      Open

                  $creationDir[] = $target . $dirToCopy . \str_replace($source, '', $dir);
      Severity: Minor
      Found in src/StaticObjects/Fs.php by phpmd

      UndefinedVariable

      Since: 2.8.0

      Detects when a variable is used that has not been defined before.

      Example

      class Foo
      {
          private function bar()
          {
              // $message is undefined
              echo $message;
          }
      }

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

      Avoid using undefined variables such as '$creationDir' which will lead to PHP notices.
      Open

              $creationDirRevert = \array_reverse($creationDir);
      Severity: Minor
      Found in src/StaticObjects/Fs.php by phpmd

      UndefinedVariable

      Since: 2.8.0

      Detects when a variable is used that has not been defined before.

      Example

      class Foo
      {
          private function bar()
          {
              // $message is undefined
              echo $message;
          }
      }

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

      Avoid using undefined variables such as '$creationDir' which will lead to PHP notices.
      Open

              $creationDir[] = $target . $dirToCopy;
      Severity: Minor
      Found in src/StaticObjects/Fs.php by phpmd

      UndefinedVariable

      Since: 2.8.0

      Detects when a variable is used that has not been defined before.

      Example

      class Foo
      {
          private function bar()
          {
              // $message is undefined
              echo $message;
          }
      }

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

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

          public static function copy(string $source, string $target, bool $force = false): array
      Severity: Minor
      Found in src/StaticObjects/Fs.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

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

          public static function move(string $source, string $target, bool $force = false): array
      Severity: Minor
      Found in src/StaticObjects/Fs.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

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

          public static function rename(string $source, string $target, bool $force = false): bool
      Severity: Minor
      Found in src/StaticObjects/Fs.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

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

          public static function delete(string $path, bool $force = false): array
      Severity: Minor
      Found in src/StaticObjects/Fs.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

      Avoid using static access to class 'BlueFilesystem\StaticObjects\Structure' in method 'copyDir'.
      Open

              if (!Structure::exist($target)) {
      Severity: Minor
      Found in src/StaticObjects/Fs.php by phpmd

      StaticAccess

      Since: 1.4.0

      Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

      Example

      class Foo
      {
          public function bar()
          {
              Bar::baz();
          }
      }

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

      Avoid using static access to class 'BlueFilesystem\StaticObjects\Structure' in method 'rename'.
      Open

              if (!Structure::exist($source)) {
      Severity: Minor
      Found in src/StaticObjects/Fs.php by phpmd

      StaticAccess

      Since: 1.4.0

      Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

      Example

      class Foo
      {
          public function bar()
          {
              Bar::baz();
          }
      }

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

      Avoid using static access to class 'BlueFilesystem\StaticObjects\Structure' in method 'buildDirStructure'.
      Open

                  if (!Structure::exist($dir)) {
      Severity: Minor
      Found in src/StaticObjects/Fs.php by phpmd

      StaticAccess

      Since: 1.4.0

      Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

      Example

      class Foo
      {
          public function bar()
          {
              Bar::baz();
          }
      }

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

      The method remove uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
      Open

                  } else {
                      $operationList['delete:' . $path] = unlink($path);
                  }
      Severity: Minor
      Found in src/StaticObjects/Fs.php by phpmd

      ElseExpression

      Since: 1.4.0

      An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

      Example

      class Foo
      {
          public function bar($flag)
          {
              if ($flag) {
                  // one branch
              } else {
                  // another branch
              }
          }
      }

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

      Avoid using static access to class 'BlueFilesystem\StaticObjects\Structure' in method 'delete'.
      Open

              if (!Structure::exist($path)) {
      Severity: Minor
      Found in src/StaticObjects/Fs.php by phpmd

      StaticAccess

      Since: 1.4.0

      Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

      Example

      class Foo
      {
          public function bar()
          {
              Bar::baz();
          }
      }

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

      Avoid using static access to class 'BlueFilesystem\StaticObjects\Structure' in method 'mkdir'.
      Open

                  if (Structure::exist($newPath)) {
      Severity: Minor
      Found in src/StaticObjects/Fs.php by phpmd

      StaticAccess

      Since: 1.4.0

      Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

      Example

      class Foo
      {
          public function bar()
          {
              Bar::baz();
          }
      }

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

      The method copy uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
      Open

              } else {
                  $operationList = self::copyFile($source, $target);
              }
      Severity: Minor
      Found in src/StaticObjects/Fs.php by phpmd

      ElseExpression

      Since: 1.4.0

      An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

      Example

      class Foo
      {
          public function bar($flag)
          {
              if ($flag) {
                  // one branch
              } else {
                  // another branch
              }
          }
      }

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

      Avoid using static access to class 'BlueFilesystem\StaticObjects\Structure' in method 'rename'.
      Open

              if (Structure::exist($target)) {
      Severity: Minor
      Found in src/StaticObjects/Fs.php by phpmd

      StaticAccess

      Since: 1.4.0

      Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

      Example

      class Foo
      {
          public function bar()
          {
              Bar::baz();
          }
      }

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

      Avoid using static access to class 'BlueFilesystem\StaticObjects\Structure' in method 'mkfile'.
      Open

              if (!Structure::exist($path)) {
      Severity: Minor
      Found in src/StaticObjects/Fs.php by phpmd

      StaticAccess

      Since: 1.4.0

      Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

      Example

      class Foo
      {
          public function bar()
          {
              Bar::baz();
          }
      }

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

      Avoid using static access to class 'BlueFilesystem\StaticObjects\Structure' in method 'copy'.
      Open

              if (!Structure::exist($source)) {
      Severity: Minor
      Found in src/StaticObjects/Fs.php by phpmd

      StaticAccess

      Since: 1.4.0

      Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

      Example

      class Foo
      {
          public function bar()
          {
              Bar::baz();
          }
      }

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

      Avoid classes with short names like Fs. Configured minimum length is 3.
      Open

      class Fs implements FsInterface
      {
          /**
           * @var EventDispatcherInterface
           */
      Severity: Minor
      Found in src/StaticObjects/Fs.php by phpmd

      ShortClassName

      Since: 2.9

      Detects when classes or interfaces have a very short name.

      Example

      class Fo {
      
      }
      
      interface Fo {
      
      }

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

      There are no issues that match your filters.

      Category
      Status