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

MbStrFunctionsFixer - Add "str_split" => "mb_str_split" mapping [PHP7.4] #4534

Merged
merged 2 commits into from Oct 9, 2019
Merged

MbStrFunctionsFixer - Add "str_split" => "mb_str_split" mapping [PHP7.4] #4534

merged 2 commits into from Oct 9, 2019

Conversation

keradus
Copy link
Member

@keradus keradus commented Aug 31, 2019

This reverts commit d35c431.

Reapply #4380 by reverting #4533

Copy link
Member Author

@keradus keradus left a comment

Choose a reason for hiding this comment

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

Sorry @SpacePossum , I had to revert your PR.
can you take over this one, please?

$this->functions = array_filter(
self::$functionsMap,
static function (array $mapping) {
return \function_exists($mapping['alternativeName']);
Copy link
Member Author

Choose a reason for hiding this comment

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

this is work way to do the check. during runtime, we have ext-mb polyfilled, thus we alternativeName always exists

vide #4380 (comment)
vide #4529

Copy link
Contributor

@Slamdunk Slamdunk Sep 2, 2019

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Looking nice!
Yet, to be honest, i'm not sure is it the way we want to follow - implicit handling of decision "should we transform this function or not" by detecting isInternal or current runtime (that still can be different than end environment), or explicit configuration (like we do eg for PHPUnit - we aim version X or Y, regardless what is installed in repo we are fixing).
What do you think, @Slamdunk ?

Copy link
Contributor

@Slamdunk Slamdunk Sep 2, 2019

Choose a reason for hiding this comment

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

I'm gonna talk about this particular Fixer only: this Fixer aims to not forget anywhere any non-multi-byte string comparison. Why should anyone could want to fix one function but not the others?

by detecting isInternal or current runtime (that still can be different than end environment)

That would be a user's fault: this tool it is intended to be run with the same binary used by the production, so no worry to me about this point

explicit configuration (like we do eg for PHPUnit - we aim version X or Y, regardless what is installed in repo we are fixing)

As a user myself of PHP-CS-Fixer the fact that PHPUnit related fixers are by explicit configuration represents just a lack of the tool, not a cool feature. What would be the purpose of having PHPUnit 999 installed and tells PHP-CS-Fixer to to transition the code from PHPUnit 1 to PHPUnit 2? The installed version and targeted transition one should always be the same to me.
Here I don't question what was done: it is a safety net for PHP-CS-Fixer maintainers and it's good for now; just talking about theory here 😉

Copy link
Member Author

Choose a reason for hiding this comment

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

Why should anyone could want to fix one function but not the others?

vide issue reported - because he does not had the other function (mb_str_split) and code execution after fixing was crashing for him (We had installed polyfill, he didn't).

for phpunit - well, one can has it installed as global dependency or phar file, and we cannot autodetect version.

agree - if we expect to run on same runtime (which we do), then it's not an issue if we don't modify the runtime on the fly (by adding pollyfills). then, maybe isInternal is good enough for us here.

@Slamdunk
Copy link
Contributor

Slamdunk commented Sep 3, 2019

@SpacePossum
Copy link
Contributor

TBH I didn't see the need for the revert as now we still have the same issue with all other function calls, just not the new one added.

The additional guard for the internal check sounds good to me, not sure if it out performs using a look up in the internal functions array (if we start using this check for all fixers, it might be worth casing this kind of meta data about the functions somewhere?)

@keradus
Copy link
Member Author

keradus commented Sep 4, 2019

TBH I didn't see the need for the revert

well, not that much users of PHP CS Fixer already using PHP 7.4, and for all of them that are not using it nor the polyfill, we were breaking the result file.

@keradus keradus changed the base branch from 2.12 to 2.15 September 4, 2019 11:07
@SpacePossum
Copy link
Contributor

@keradus anything else you want here?

@julienfalque julienfalque added the RTM Ready To Merge label Oct 9, 2019
@SpacePossum SpacePossum added this to the 2.15.4 milestone Oct 9, 2019
@SpacePossum SpacePossum changed the title Redo PHP7.4 - Add "str_split" => "mb_str_split" mapping MbStrFunctionsFixer - Add "str_split" => "mb_str_split" mapping [PHP7.4] Oct 9, 2019
@SpacePossum
Copy link
Contributor

Thank you @keradus.

SpacePossum added a commit that referenced this pull request Oct 9, 2019
…keradus, Slamdunk)

This PR was merged into the 2.15 branch.

Discussion
----------

Redo PHP7.4 - Add "str_split" => "mb_str_split" mapping

This reverts commit d35c431.

Reapply #4380 by reverting #4533

Commits
-------

083d062 mb_*: rely on ReflectionFunction::isInternal to detect correct list of functions to fix
3fea39f Revert "Revert PHP7.4 - Add \"str_split\" => \"mb_str_split\" mapping"
@SpacePossum SpacePossum merged commit 083d062 into PHP-CS-Fixer:2.15 Oct 9, 2019
@SpacePossum
Copy link
Contributor

thanks @Slamdunk as well :D

@SpacePossum SpacePossum removed the RTM Ready To Merge label Oct 9, 2019
@SpacePossum SpacePossum deleted the 2_12_74_mb_str_func branch October 10, 2019 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants