- Status changed to Needs review
about 2 years ago 9:36am 19 January 2023 - Status changed to RTBC
about 2 years ago 4:09pm 19 January 2023 - Status changed to Needs work
about 2 years ago 2:35pm 26 January 2023 - 🇺🇸United States xjm
This took awhile to review thoroughly, but it is pretty close to ready. Nice work!
-
+++ b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Rotate.php @@ -37,12 +37,37 @@ protected function arguments() { + if (!is_numeric($arguments['degrees'])) {
Presumably it should also be between -360 and 360? This might be followup territory since technically someone rotating 477 degrees might experience a BC break. I tested in the user interface and entering e.g. "-477" in the widget works fine. It is odd/confusing with the "Randomize" option though.
-
+++ b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Rotate.php @@ -37,12 +37,37 @@ protected function arguments() { + throw new \InvalidArgumentException('Invalid degrees (' . $arguments['degrees'] . ') specified for the image \'rotate\' operation. It should be numeric.'); ... + throw new \InvalidArgumentException('Invalid background color (' . $arguments['background'] . ') specified for the image \'rotate\' operation. It should be a hex string.');
I confirmed that the method is already documented as
@throws
for this exception on the interface.Should we maybe double-quote these strings to avoid needing to escape the single quotes and to avoid the concatenation with the arguments?
-
+++ b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Rotate.php @@ -37,12 +37,37 @@ protected function arguments() { + // Assure background color is a valid hex string.
"Assure" does not make sense in the context. It's a transitive verb that means "to soothe doubts", e.g., "I assured them that I would review the patch carefully." This should be:
Ensure that the background color is a valid hex string.
-
+++ b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Rotate.php @@ -37,12 +37,37 @@ protected function arguments() { + /** + * {@inheritdoc} + */ + protected function execute(array $arguments) { + // PHP installations using non-bundled GD do not have imagerotate. + if (!function_exists('imagerotate')) { + $this->logger->notice('The image %file could not be rotated because the imagerotate() function is not available in this PHP installation.', [ + '%file' => $this->getToolkit()->getSource(), + ]); + return FALSE; + } @@ -80,19 +105,6 @@ protected function validateArguments(array $arguments) { - /** - * {@inheritdoc} - */ - protected function execute(array $arguments) { - // PHP installations using non-bundled GD do not have imagerotate. - if (!function_exists('imagerotate')) { - $this->logger->notice('The image %file could not be rotated because the imagerotate() function is not available in this PHP installation.', ['%file' => $this->getToolkit()->getSource()]); - return FALSE; - }
I verified that this is just a diff artifact. These lines are not actually changing. They just appear to be moved because a larger number of lines are moved from one method to another.
-
+++ b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Rotate.php @@ -37,12 +37,37 @@ protected function arguments() { // PHP 5.5 GD bug: https://bugs.php.net/bug.php?id=65148: To prevent buggy // behavior on negative multiples of 90 degrees we convert any negative // angle to a positive one between 0 and 360 degrees. $arguments['degrees'] -= floor($arguments['degrees'] / 360) * 360;
Out of scope, but maybe a followup: Does this bug still exist? It's been five years since Drupal supported PHP 5.5.
-
+++ b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Rotate.php @@ -80,19 +105,6 @@ protected function validateArguments(array $arguments) { - return $arguments; - } -
At a glance the diff makes it look like this is removing the return value, but it is just a diff artifact due to the lines being moved. I confirmed that
execute()
never returns$arguments
in HEAD, only Booleans. -
This should probably have a change record, since it will change what happens when for contrib or custom code that extends it.
NW primarily for point 3 and for the change record, though followups (or finding existing related issues) would be helpful too. Thanks!
-
- 🇮🇹Italy mondrake 🇮🇹
📌 Remove PHP 5 code for GD Needs work addresses #72.5.