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

[Php81] NullToStrictStringFuncCallArgRector - Register more function #2543

Merged
merged 2 commits into from
Jun 21, 2022

Conversation

hungtrinh
Copy link
Contributor

No description provided.

@hungtrinh hungtrinh requested a review from TomasVotruba as a code owner June 20, 2022 18:36
@TomasVotruba
Copy link
Member

Thanks for the feature.
What is the added value of per-function fixture files? It seems the name matching functions is always the same.

Could you keep just one?

@hungtrinh
Copy link
Contributor Author

If keep just one, i think we can remove all fixture non_string_param_type_2_* in this PR , non string param type case covered by https://github.com/rectorphp/rector-src/blob/main/rules-tests/Php81/Rector/FuncCall/NullToStrictStringFuncCallArgRector/Fixture/non_string_param_type.php.inc

What is the added value of per-function fixture files?
that to make sure each function in this list ARG_POSITION_NAME_NULL_TO_STRICT_STRING covered by test non_string_param_type_2_* without throw exception

private const ARG_POSITION_NAME_NULL_TO_STRICT_STRING = [
'preg_split' => ['subject'],
'preg_match' => ['subject'],
'preg_match_all' => ['subject'],
'explode' => ['string'],
'strlen' => ['string'],
'str_contains' => ['haystack', 'needle'],
];

In the future if somebody add 'strtr' => ['string'] into ARG_POSITION_NAME_NULL_TO_STRICT_STRING without test fixture non_string_param_type_2_strtr.php.inc => unit test pass but actual when run this rules in prod will raise exception

`1) Rector\Tests\Php81\Rector\FuncCall\NullToStrictStringFuncCallArgRector\NullToStrictStringFuncCallArgRectorTest::test with data set #165 (Symplify\SmartFileSystem\SmartFileInfo Object (...))
PHPStan\ShouldNotHappenException: Multiple variants - use selectFromArgs() instead.

phar:///Users/trinhhung/Projects/rector-src/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/ParametersAcceptorSelector.php:45
/Users/trinhhung/Projects/rector-src/rules/Php81/Rector/FuncCall/NullToStrictStringFuncCallArgRector.php:474
/Users/trinhhung/Projects/rector-src/rules/Php81/Rector/FuncCall/NullToStrictStringFuncCallArgRector.php:335
/Users/trinhhung/Projects/rector-src/src/Rector/AbstractRector.php:218
/Users/trinhhung/Projects/rector-src/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php:123
/Users/trinhhung/Projects/rector-src/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php:223
/Users/trinhhung/Projects/rector-src/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php:114
/Users/trinhhung/Projects/rector-src/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php:223
/Users/trinhhung/Projects/rector-src/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php:114
/Users/trinhhung/Projects/rector-src/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php:223
/Users/trinhhung/Projects/rector-src/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php:114
/Users/trinhhung/Projects/rector-src/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php:223
/Users/trinhhung/Projects/rector-src/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php:91
/Users/trinhhung/Projects/rector-src/src/PhpParser/NodeTraverser/RectorNodeTraverser.php:33
/Users/trinhhung/Projects/rector-src/src/Application/FileProcessor.php:42
/Users/trinhhung/Projects/rector-src/src/Application/FileProcessor/PhpFileProcessor.php:103
/Users/trinhhung/Projects/rector-src/src/Application/FileProcessor/PhpFileProcessor.php:62
/Users/trinhhung/Projects/rector-src/src/Application/ApplicationFileProcessor.php:130
/Users/trinhhung/Projects/rector-src/packages/Testing/PHPUnit/AbstractRectorTestCase.php:177
/Users/trinhhung/Projects/rector-src/packages/Testing/PHPUnit/AbstractRectorTestCase.php:131
/Users/trinhhung/Projects/rector-src/packages/Testing/PHPUnit/AbstractRectorTestCase.php:115
/Users/trinhhung/Projects/rector-src/rules-tests/Php81/Rector/FuncCall/NullToStrictStringFuncCallArgRector/NullToStrictStringFuncCallArgRectorTest.php:18`

https://www.php.net/manual/en/function.strtr

@TomasVotruba
Copy link
Member

If keep just one, i think we can remove all fixture

Please go for it 👍

The reason is tests should cover edge cases, e.g. one with position of 1, other with 0. Every other is just duplicate that makes them harder to read.

@TomasVotruba
Copy link
Member

Thank you 👍

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.

3 participants