Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: UploadedFile::store() can't return null #4183

Closed
kenjis opened this issue Jan 29, 2021 · 3 comments · Fixed by #4187
Closed

Bug: UploadedFile::store() can't return null #4183

kenjis opened this issue Jan 29, 2021 · 3 comments · Fixed by #4187
Labels
bug Verified issues on the current code behavior or pull requests that will fix them

Comments

@kenjis
Copy link
Member

kenjis commented Jan 29, 2021

Describe the bug
UploadedFile::store() could return null:

return ($this->move(WRITEPATH . 'uploads/' . $folderName, $fileName)) ?
$folderName . $this->name : null;

But the return type is string.
public function store(string $folderName = null, string $fileName = null): string

CodeIgniter 4 version
develop branch.

Affected module(s)
UploadedFile

Expected behavior, and steps to reproduce if appropriate
I'm not sure. If $this->move() fails, what should be returned?

Context

  • OS: [macOS 10.15.7]
  • Web server [PHP built-in]
  • PHP version [7.4.13]
@kenjis kenjis added the bug Verified issues on the current code behavior or pull requests that will fix them label Jan 29, 2021
@paulbalandan
Copy link
Member

It is strange phpstan didn't flag this incompatible return. 🤔

@kenjis
Copy link
Member Author

kenjis commented Jan 29, 2021

I found that $this->move() never returns false. So phpstan does not complains?

public function move(string $targetPath, string $name = null, bool $overwrite = false)

So should it be like this?

--- a/system/HTTP/Files/UploadedFile.php
+++ b/system/HTTP/Files/UploadedFile.php
@@ -376,8 +376,9 @@ class UploadedFile extends File implements UploadedFileInterface
        $fileName   = $fileName ?? $this->getRandomName();
 
        // Move the uploaded file to a new location.
-       return ($this->move(WRITEPATH . 'uploads/' . $folderName, $fileName)) ?
-               $folderName . $this->name : null;
+       $this->move(WRITEPATH . 'uploads/' . $folderName, $fileName);
+
+       return $folderName . $this->name;
    }
 
    //--------------------------------------------------------------------

@kenjis
Copy link
Member Author

kenjis commented Jan 30, 2021

I sent PR #4187

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants