Skip to content

[Uploadable] Remove deprecation warning when calling is_file with a null value #2901

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/Uploadable/UploadableListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@
*/
public function removeFile($filePath)
{
if (is_file($filePath)) {
if (!is_null($filePath) && is_file($filePath)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!is_null($filePath) && is_file($filePath)) {
if (null !== $filePath && is_file($filePath)) {

return @unlink($filePath);
}

Expand Down Expand Up @@ -709,11 +709,14 @@
protected function addFileRemoval($meta, $config, $object)
{
if ($config['filePathField']) {
$this->pendingFileRemovals[] = $this->getFilePathFieldValue($meta, $config, $object);
$filename = $this->getFilePathFieldValue($meta, $config, $object);
} else {
$path = $this->getPath($meta, $config, $object);
$fileName = $this->getFileNameFieldValue($meta, $config, $object);
$this->pendingFileRemovals[] = $path.DIRECTORY_SEPARATOR.$fileName;
$filename = $path.DIRECTORY_SEPARATOR.$this->getFileNameFieldValue($meta, $config, $object);

Check warning on line 715 in src/Uploadable/UploadableListener.php

View check run for this annotation

Codecov / codecov/patch

src/Uploadable/UploadableListener.php#L715

Added line #L715 was not covered by tests
}

if (!is_null($filename) && file_exists($filename)) {
$this->pendingFileRemovals[] = $filename;
}
}

Expand Down Expand Up @@ -752,7 +755,7 @@
* @param array<string, mixed> $config
* @param object $object
*
* @return string
* @return string|null
*/
protected function getFilePathFieldValue(ClassMetadata $meta, array $config, $object)
{
Expand Down
Loading