stk2k/file-system

View on GitHub

Showing 17 of 17 total issues

Function put has a Cognitive Complexity of 34 (exceeds 5 allowed). Consider refactoring.
Open

    public function put($contents, bool $ex_lock = false) : self
    {
        if (!is_string($contents)){
            if (is_array($contents)){
                $contents = implode(PHP_EOL, $contents);
Severity: Minor
Found in src/File.php - About 5 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

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

<?php
declare(strict_types=1);

namespace stk2k\filesystem\Filter;

Severity: Major
Found in src/Filter/WildcardFileFilter.php and 1 other location - About 4 hrs to fix
src/Filter/RegExFileFilter.php on lines 1..53

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

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

<?php
declare(strict_types=1);

namespace stk2k\filesystem\Filter;

Severity: Major
Found in src/Filter/RegExFileFilter.php and 1 other location - About 4 hrs to fix
src/Filter/WildcardFileFilter.php on lines 1..52

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

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

File has 36 functions (exceeds 20 allowed). Consider refactoring.
Open

class File
{
    const DS = DIRECTORY_SEPARATOR;

    const MAKEDIRECTORY_DEFAULT_MODE = 0777;
Severity: Minor
Found in src/File.php - About 4 hrs to fix

    Function write has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
    Open

        public static function write(string $filename, array $data, string $line_end = "\r\n")
        {
            $fp = fopen($filename, 'w');
            if (!$fp){
                throw new FileOpenException(new File($filename));
    Severity: Minor
    Found in src/Util/IniFileWriter.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 listFiles has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
    Open

        public function listFiles( $filter = null ) : array
        {
            $path = $this->path;
    
            if ( !file_exists($path) )    return [];
    Severity: Minor
    Found in src/File.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

    FileSystem has 32 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class FileSystem
    {
        /**
         * Returns file hash
         *
    Severity: Minor
    Found in src/FileSystem.php - About 4 hrs to fix

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

      <?php
      declare(strict_types=1);
      
      namespace stk2k\filesystem;
      
      
      Severity: Minor
      Found in src/File.php - About 2 hrs to fix

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

            public static function moveFile(File $src, File $dest)
            {
                // check source path
                if (!$src->isFile()) {
                    throw new NotFileException($src);
        Severity: Major
        Found in src/Util/FileSystemUtil.php and 1 other location - About 2 hrs to fix
        src/Util/FileSystemUtil.php on lines 24..46

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

        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 copyFile(File $src, File $dest)
            {
                // check source path
                if (!$src->isFile()) {
                    throw new NotFileException($src);
        Severity: Major
        Found in src/Util/FileSystemUtil.php and 1 other location - About 2 hrs to fix
        src/Util/FileSystemUtil.php on lines 56..78

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

        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

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

            public function lock(bool $block = false) : void
            {
                if ($this->isClosed()){
                    throw new FileWriterException('File operator is already closed: ' . $this->getFile());
                }
        Severity: Major
        Found in src/FileWriter.php and 1 other location - About 2 hrs to fix
        src/FileReader.php on lines 19..33

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

        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

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

            public function lock(bool $block = false) : void
            {
                if ($this->isClosed()){
                    throw new FileReaderException('File operator is already closed: ' . $this->getFile());
                }
        Severity: Major
        Found in src/FileReader.php and 1 other location - About 2 hrs to fix
        src/FileWriter.php on lines 20..34

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

        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

        Method write has 31 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public static function write(string $filename, array $data, string $line_end = "\r\n")
            {
                $fp = fopen($filename, 'w');
                if (!$fp){
                    throw new FileOpenException(new File($filename));
        Severity: Minor
        Found in src/Util/IniFileWriter.php - About 1 hr to fix

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

              public function listFiles( $filter = null ) : array
              {
                  $path = $this->path;
          
                  if ( !file_exists($path) )    return [];
          Severity: Minor
          Found in src/File.php - About 1 hr to fix

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

                public function put($contents, bool $ex_lock = false) : self
                {
                    if (!is_string($contents)){
                        if (is_array($contents)){
                            $contents = implode(PHP_EOL, $contents);
            Severity: Minor
            Found in src/File.php - About 1 hr to fix

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

                  public function rmdirRecursive() : self
                  {
                      if ( !file_exists($this->path) ){
                          return $this;
                      }
              Severity: Minor
              Found in src/File.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 mkdir has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                  public function mkdir(int $mode = self::MAKEDIRECTORY_DEFAULT_MODE) : self
                  {
                      if ( file_exists($this->path) ){
                          if ( is_file($this->path) ){
                              throw new MakeDirectoryException($this);
              Severity: Minor
              Found in src/File.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

              Severity
              Category
              Status
              Source
              Language