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

refactor: TypeError in strict mode by ArrayHelper::SortValuesByNatural() #8308

Merged
merged 2 commits into from
Dec 8, 2023

Conversation

kenjis
Copy link
Member

@kenjis kenjis commented Dec 8, 2023

Description
Follow-up #8285

1) CodeIgniter\Helpers\Array\ArrayHelperSortValuesByNaturalTest::testSortWithStringValues
TypeError: strnatcmp(): Argument #2 ($string2) must be of type string, int given

/home/runner/work/CodeIgniter4/CodeIgniter4/system/Helpers/Array/ArrayHelper.php:318
/home/runner/work/CodeIgniter4/CodeIgniter4/system/Helpers/Array/ArrayHelper.php:313
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Helpers/Array/ArrayHelperSortValuesByNaturalTest.php:60

2) CodeIgniter\Helpers\Array\ArrayHelperSortValuesByNaturalTest::testSortWithArrayValues
TypeError: strnatcmp(): Argument #2 ($string2) must be of type string, int given

/home/runner/work/CodeIgniter4/CodeIgniter4/system/Helpers/Array/ArrayHelper.php:315
/home/runner/work/CodeIgniter4/CodeIgniter4/system/Helpers/Array/ArrayHelper.php:313
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Helpers/Array/ArrayHelperSortValuesByNaturalTest.php:84

https://github.com/codeigniter4/CodeIgniter4/actions/runs/7135744955/job/19433071552?pr=8307

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@kenjis kenjis changed the title fix: TypeError in strict mode fix: TypeError in strict mode by ArrayHelper::SortValuesByNatural() Dec 8, 2023
@kenjis
Copy link
Member Author

kenjis commented Dec 8, 2023

@neznaika0 Review, please.

@kenjis kenjis added the 4.5 label Dec 8, 2023
@kenjis kenjis changed the title fix: TypeError in strict mode by ArrayHelper::SortValuesByNatural() refactor: TypeError in strict mode by ArrayHelper::SortValuesByNatural() Dec 8, 2023
@kenjis
Copy link
Member Author

kenjis commented Dec 8, 2023

GitHub Action checks fail in 4.5 branch.
This PR will fix it. Review first.

@kenjis kenjis merged commit c185910 into codeigniter4:4.5 Dec 8, 2023
45 checks passed
@kenjis kenjis deleted the fix-ArrayHelper-sortValuesByNatural branch December 8, 2023 06:49
@kenjis
Copy link
Member Author

kenjis commented Dec 8, 2023

@michalsn Thank you!

Copy link
Contributor

@neznaika0 neznaika0 left a comment

Choose a reason for hiding this comment

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

I wonder why the PR check doesn't show this? Type casting helps, but is it worth adding the is_int is_string exception? When the value is a multidimensional array or object

@kenjis
Copy link
Member Author

kenjis commented Dec 8, 2023

Because the PR was created and checked before adding declare(strict_types=1).

If the method does not work on unexpected arrays, it is better to check the value types.

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 this pull request may close these issues.

3 participants