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

Discourage local-FS-only methods #198

Merged
merged 4 commits into from
Dec 3, 2020
Merged
Show file tree
Hide file tree
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
11 changes: 11 additions & 0 deletions Magento2/Sniffs/Functions/DiscouragedFunctionSniff.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Rule: getimagesize() is discouraged

## Reason

[getimagesize](https://www.php.net/manual/en/function.getimagesize.php) function works only with local and supported streams.
With introduction of more advanced storages, like AWS S3 or Azure Blob Storage this function will cause issues where file is not accessible.

## How to fix

[getimagesizefromstring](https://www.php.net/manual/en/function.getimagesizefromstring.php) can be used instead to retrieve all the information from file.
This function works with data strings, so you should read the file content using specific adapter before using it.
1 change: 1 addition & 0 deletions Magento2/Sniffs/Functions/DiscouragedFunctionSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,5 +228,6 @@ class DiscouragedFunctionSniff extends ForbiddenFunctionsSniff
'^intval$' => '(int) construction',
'^strval$' => '(string) construction',
'^htmlspecialchars$' => '\Magento\Framework\Escaper->escapeHtml',
'^getimagesize$' => 'getimagesizefromstring',
];
}