Skip to content

[Polyfill] Add UnwrapFutureCompatibleIfRector#2569

Merged
TomasVotruba merged 1 commit intomasterfrom
unwrap-compat
Jan 6, 2020
Merged

[Polyfill] Add UnwrapFutureCompatibleIfRector#2569
TomasVotruba merged 1 commit intomasterfrom
unwrap-compat

Conversation

@TomasVotruba
Copy link
Copy Markdown
Member

Closes #2540

Comment on lines +14 to +16
private const FUNCTIONS_BY_VERSION = [
'5.6' => ['session_abort'],
];
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@staabm Here is just the code example you showed me. I need your help to complete list as far as possible.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I need to think about how to compile such method most easily

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor

@staabm staabm Jan 6, 2020

Choose a reason for hiding this comment

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

Another thing I checked via github code-search
https://github.com/search?l=PHP&q=function_exists&type=Code

There we can see most examples are like

if( ! function_exists( 'supernova_comment' ) ){
  function supernova_comment($comment, $args, $depth) {
   // impl
  }
}

In these cases we could eleminate the code when we are sure that the function beeing checked is one from the php standard library (so semantically the code is polyfilling, not e.g. guarding against „function already exist“ error because of multiple including the same file)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

After thinking about it I feel we could compile this list from exisiting polyfil libs, e.g.

Great!

Another thing I checked via github code-search

Try to keep issues separated, so we don't get stuck with complexity. This is another use case.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I see

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

There are many new PRs merged every day so there are new conflicts to rebase on.
I'll merge this now to prevent that.

You can send the function list as a new PR targeting this class 👍

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@staabm Any update on this? The rule is pretty lonely with just 1 function now :D

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Was on vacation till yesterday.. will need a few more days to catch up

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

here we go #2673

continue;
}

if (! $this->phpVersionProvider->isAtLeast($version)) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I guess it would also be helpfull to remove code when explicit php version checks are used (might be a separTe rector then?)

In codes like https://github.com/redaxo/redaxo/blob/591146a1dc60e8aacefd58dc9b7e9c307c0983b9/redaxo/src/addons/tests/vendor/phpspec/prophecy/src/Prophecy/Doubler/Generator/ClassCodeGenerator.php#L85

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Sure! I though of that too.

Could you help by making a new issue with minimal code (3-lines) in diff a format?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

See #2573 #2574

@TomasVotruba TomasVotruba merged commit befc972 into master Jan 6, 2020
@TomasVotruba TomasVotruba deleted the unwrap-compat branch January 6, 2020 12:15
TomasVotruba added a commit that referenced this pull request Jun 27, 2022
rectorphp/rector-src@89a684f [Core] Apply Scope refresh for Namespace_ and FileWithoutNamespace (#2569)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Detect feature-detecting code as dead code

2 participants