yiicod/yii2-fileupload

View on GitHub

Showing 19 of 19 total issues

Function upload has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
Open

    public function upload(string $uploader, array $userData)
    {
        $result = $this->handleUpload();

        $can = $this->canDo();
Severity: Minor
Found in components/UploadHandler.php - About 3 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 post has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
Open

    public function post($print_response = true)
    {
        $upload = isset($_FILES[$this->options['param_name']]) ?
            $_FILES[$this->options['param_name']] : null;
        if ($upload && is_array($upload['tmp_name'])) {
Severity: Minor
Found in components/UploadHandlerOld.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 afterSave has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
Open

    public function afterSave($event)
    {
        foreach ($this->fields as $field) {
            if ($tmpPath = $this->getTmpFile($field)) {
                if (false === is_dir($this->getFolderPath($field))) {
Severity: Minor
Found in models/behaviors/FileUploadBehavior.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 handleFileUpload has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
Open

    protected function handleFileUpload(UploadedFile $uploadedFile)
    {
        $file = $uploadedFile;
        $file->name = (new FileName($this->options['upload_dir'], $this->options['file_name_length'] ?? null))->getFileName($file);
        $file->size = (int)$file->size;
Severity: Minor
Found in components/UploadHandler.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 buildTheme has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

    protected function buildTheme(): ThemeInterface
    {
        $theme = null;

        if (is_a($this->theme, ThemeInterface::class)) {
Severity: Minor
Found in widgets/FileUpload.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 handleUpload has 46 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    protected function handleUpload(): array
    {
        $upload = $this->getUploadData($this->options['param_name']);
        if ($upload && is_array($upload['tmp_name'])) {
            foreach ($upload['tmp_name'] as $index => $value) {
Severity: Minor
Found in components/UploadHandler.php - About 1 hr to fix

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

        protected function handleUpload(): array
        {
            $upload = $this->getUploadData($this->options['param_name']);
            if ($upload && is_array($upload['tmp_name'])) {
                foreach ($upload['tmp_name'] as $index => $value) {
    Severity: Minor
    Found in components/UploadHandler.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 prepareValidators has 35 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        protected function prepareValidators(): array
        {
            return ArrayHelper::merge([
                'FileUploadValidator' => [
                    'class' => FileUploadValidator::class,
    Severity: Minor
    Found in actions/FileUploadAction.php - About 1 hr to fix

      Method handleFileUpload has 34 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          protected function handleFileUpload(UploadedFile $uploadedFile)
          {
              $file = $uploadedFile;
              $file->name = (new FileName($this->options['upload_dir'], $this->options['file_name_length'] ?? null))->getFileName($file);
              $file->size = (int)$file->size;
      Severity: Minor
      Found in components/UploadHandler.php - About 1 hr to fix

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

            public function post($print_response = true)
            {
                $upload = isset($_FILES[$this->options['param_name']]) ?
                    $_FILES[$this->options['param_name']] : null;
                if ($upload && is_array($upload['tmp_name'])) {
        Severity: Minor
        Found in components/UploadHandlerOld.php - About 1 hr to fix

          Function dragAndDrop has 31 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              FileUploadTrigger.prototype.dragAndDrop = function () {
                  $(document)
                      .on('dragover', $.proxy(function (e) {
                          var foundDropzone,
                              timeout = window.dropZoneTimeout;
          Severity: Minor
          Found in themes/base/assets/jquery.fileupload-trigger.js - About 1 hr to fix

            Method upload has 30 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function upload(string $uploader, array $userData)
                {
                    $result = $this->handleUpload();
            
                    $can = $this->canDo();
            Severity: Minor
            Found in components/UploadHandler.php - About 1 hr to fix

              Function defaultEvents has 29 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  FileUploadTrigger.prototype.defaultEvents = function () {
                      this.button
                          .on('fileuploadprocessalways', $.proxy(function (e, data) {
                              if (data.files[data.index].error) {
                                  this.input.empty();
              Severity: Minor
              Found in themes/base/assets/jquery.fileupload-trigger.js - About 1 hr to fix

                Method trim_file_name has 7 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                    protected function trim_file_name($file_path, $name, $size, $type, $error, $index, $content_range)
                Severity: Major
                Found in components/UploadHandlerOld.php - About 50 mins to fix

                  Method __construct has 7 arguments (exceeds 4 allowed). Consider refactoring.
                  Open

                      public function __construct(string $filePath, string $name, $size, string $type, ?string $error = null, ?int $index = null, ?array $contentRange = null)
                  Severity: Major
                  Found in components/common/UploadedFile.php - About 50 mins to fix

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

                        public function validate(UploadedFile &$file): bool
                        {
                            if ($file->filePath && is_uploaded_file($file->filePath)) {
                                $fileSize = filesize($file->filePath);
                            } else {
                    Severity: Minor
                    Found in validators/FileSizeValidator.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 prepareFields has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                    Open

                        protected function prepareFields()
                        {
                            foreach ($this->fields as $field) {
                                if (false === isset($this->fieldsValues[$field])) {
                                    $file = $this->getTmpRepository()->getFile($field);
                    Severity: Minor
                    Found in models/behaviors/FileUploadBehavior.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 remove has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                    Open

                        public function remove(string $uploader, array $userData)
                        {
                            /** @var UploaderInterface $uploader */
                            $uploader = new $uploader();
                            if (false === is_a($uploader, UploaderInterface::class)) {
                    Severity: Minor
                    Found in components/RemoveHandler.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

                    Function decodeServerOptions has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                    Open

                        public static function decodeServerOptions($data): array
                        {
                            $vars = Yii::$app->session->get($data);
                    
                            if (false === $vars && isset($_FILES['files'])) {
                    Severity: Minor
                    Found in widgets/FileUpload.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