luyadev/luya-module-admin

View on GitHub
src/storage/BaseFileSystemStorage.php

Summary

Maintainability
F
3 days
Test Coverage
F
55%

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

<?php

namespace luya\admin\storage;

use luya\admin\events\FileEvent;
Severity: Minor
Found in src/storage/BaseFileSystemStorage.php - About 6 hrs to fix

    BaseFileSystemStorage has 40 functions (exceeds 20 allowed). Consider refactoring.
    Open

    abstract class BaseFileSystemStorage extends Component
    {
        use CacheableTrait;
    
        /**
    Severity: Minor
    Found in src/storage/BaseFileSystemStorage.php - About 5 hrs to fix

      Method createImage has 50 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function createImage($fileId, $filterId)
          {
              gc_collect_cycles();
      
              $image = StorageImage::find()->where(['file_id' => $fileId, 'filter_id' => $filterId])->one();
      Severity: Minor
      Found in src/storage/BaseFileSystemStorage.php - About 2 hrs to fix

        Method addFile has 40 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function addFile($fileSource, $fileName, $folderId = 0, $isHidden = false)
            {
                // ensure the file upload
                $fileData = $this->ensureFileUpload($fileSource, $fileName);
                // generate md5 hash from file source
        Severity: Minor
        Found in src/storage/BaseFileSystemStorage.php - About 1 hr to fix

          Method ensureFileUpload has 40 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function ensureFileUpload($fileSource, $fileName)
              {
                  // throw exception if source or name is empty
                  if (empty($fileSource) || empty($fileName)) {
                      throw new Exception("Filename and source can not be empty.");
          Severity: Minor
          Found in src/storage/BaseFileSystemStorage.php - About 1 hr to fix

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

                public function addImage($fileId, $filterId = 0, $throwException = false)
                {
                    try {
                        // if the filterId is provded as a string the filter will be looked up by its name in the get filters array list.
                        if (is_string($filterId) && !is_numeric($filterId)) {
            Severity: Minor
            Found in src/storage/BaseFileSystemStorage.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 ensureFileUpload has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
            Open

                public function ensureFileUpload($fileSource, $fileName)
                {
                    // throw exception if source or name is empty
                    if (empty($fileSource) || empty($fileName)) {
                        throw new Exception("Filename and source can not be empty.");
            Severity: Minor
            Found in src/storage/BaseFileSystemStorage.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 createImage has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
            Open

                public function createImage($fileId, $filterId)
                {
                    gc_collect_cycles();
            
                    $image = StorageImage::find()->where(['file_id' => $fileId, 'filter_id' => $filterId])->one();
            Severity: Minor
            Found in src/storage/BaseFileSystemStorage.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 addImage has 32 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function addImage($fileId, $filterId = 0, $throwException = false)
                {
                    try {
                        // if the filterId is provded as a string the filter will be looked up by its name in the get filters array list.
                        if (is_string($filterId) && !is_numeric($filterId)) {
            Severity: Minor
            Found in src/storage/BaseFileSystemStorage.php - About 1 hr to fix

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

                  public function addFile($fileSource, $fileName, $folderId = 0, $isHidden = false)
                  {
                      // ensure the file upload
                      $fileData = $this->ensureFileUpload($fileSource, $fileName);
                      // generate md5 hash from file source
              Severity: Minor
              Found in src/storage/BaseFileSystemStorage.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 processThumbnails has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                  public function processThumbnails()
                  {
                      foreach ($this->findFiles(['is_hidden' => false, 'is_deleted' => false]) as $file) {
                          if ($file->isImage) {
                              // create tiny thumbnail
              Severity: Minor
              Found in src/storage/BaseFileSystemStorage.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 false;
              Severity: Major
              Found in src/storage/BaseFileSystemStorage.php - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                        return $image;
                Severity: Major
                Found in src/storage/BaseFileSystemStorage.php - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

                              return $image;
                  Severity: Major
                  Found in src/storage/BaseFileSystemStorage.php - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                                    return false;
                    Severity: Major
                    Found in src/storage/BaseFileSystemStorage.php - About 30 mins to fix

                      There are no issues that match your filters.

                      Category
                      Status