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

[Downgrade PHP 8.0] Throw expression #4314

Closed
leoloso opened this issue Sep 29, 2020 · 3 comments
Closed

[Downgrade PHP 8.0] Throw expression #4314

leoloso opened this issue Sep 29, 2020 · 3 comments
Labels

Comments

@leoloso
Copy link
Contributor

leoloso commented Sep 29, 2020

Feature Request

Downgrade new feature from PHP 8.0 to its equivalent PHP 7.4 code. RFC with explanation

We must identify all the different places where throw can appear as an expression, and transform each of them to a statement.

If when executing the rule the code contains an unhandled example, it should throw a DowngradeNotImplementedException (and not a DowngradeNotPossibleException), asking the developer to report the code as a new issue in Rector, so it can be implemented.

From the RFC, the following examples have been identified. What others are there?

Diff

// This was previously not possible since arrow functions only accept a single expression while throw was a statement.
-$callable = fn() => throw new Exception();
+$callable = function() {
+    throw new Exception()
+};
 
// $value is non-nullable.
-$value = $nullableValue ?? throw new InvalidArgumentException();
+if ($nullableValue !== null) {
+    $value = $nullableValue;
+} else {
+    throw new InvalidArgumentException();
+}
 
// $value is truthy.
-$value = $falsableValue ?: throw new InvalidArgumentException();
+if ($falsableValue) {
+    $value = $falsableValue;
+} else {
+    throw new InvalidArgumentException();
+}
 
// $value is only set if the array is not empty.
-$value = !empty($array)
-    ? reset($array)
-    : throw new InvalidArgumentException();
+if (!empty($array)) {
+    $value = reset($array);
+} else {
+    throw new InvalidArgumentException();
+}
@TomasVotruba
Copy link
Member

I'm on it

@TomasVotruba
Copy link
Member

It's way more complicated then I expected. I'm giving up for other priorities

@TomasVotruba
Copy link
Member

Closing as PHP 8.0 is not a version we need to downgrade now. Let's handle in the future, when issues will pop :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants