Skip to content

Conversation

@innocenzi
Copy link
Member

This pull request adds many methods to ArrayHelper and StringHelper. This is stuff I had the need for when working on an upcoming console components overhaul PR.

Normally, I would send multiple PRs for each change, but there are too many. Reviewing this PR commit-by-commit might be easier.

Changes to ArrayHelper

  • arr(null) instanciates an empty instance instead of [null]
  • Added generics to first and last
  • Added int support to get and has
  • Added flatten and flatMap

Changes to StringHelper

  • Instanciating StringHelper with null will no longer crash
  • Added replaceAt, for replacing a portion of a string with another a the specified position
  • Added insert, which inserts a string at the specified position
  • Added limit, for truncating a string
  • Added substr, which proxies mb_substr
  • Added take, which keeps only the specified amount of characters
  • Added split, which chunks the string using str_split
  • Added stripTags, for stripping HTML tags in a string

@MrYamous
Copy link
Contributor

Great work !
Some personal thoughts on names
replaceAt and insert have similarities in principle, WDYT about replaceAt and insertAt or replace and insert
limit is for truncating a string, what about truncate function ?

@brendt
Copy link
Member

brendt commented Nov 13, 2024

replaceAt and insert have similarities in principle, WDYT about replaceAt and insertAt or replace and insert

Agree, my preference is replace and insert, maybe we could also rename the position parameter to $at? Just a thought:

str()->replace(at: 5, …)

limit is for truncating a string, what about truncate function ?

I think truncate is a better name

@brendt
Copy link
Member

brendt commented Nov 13, 2024

But of course, great PR 👍

@innocenzi
Copy link
Member Author

@MrYamous I agree, yes!

@brendt while I also like replace and insert, replace already exists. Do you suggest updating it with a new parameter? I think it would be better to go with replaceAt and insertAt to make it clearer.

Definitely agree with truncate though 👍

@innocenzi innocenzi marked this pull request as draft November 13, 2024 16:18
@innocenzi innocenzi force-pushed the feat/support/improve-string-helper branch from aa5db6f to a4037ba Compare November 13, 2024 16:44
@innocenzi innocenzi marked this pull request as ready for review November 13, 2024 16:45
@innocenzi
Copy link
Member Author

Ready for another review 👍

@brendt
Copy link
Member

brendt commented Nov 13, 2024

while I also like replace and insert, replace already exists. Do you suggest updating it with a new parameter? I think it would be better to go with replaceAt and insertAt to make it clearer.

Oh great point! Let's do that, no problem 👍

@brendt
Copy link
Member

brendt commented Nov 13, 2024

Btw, feel free to merge when it's done, no need waiting for me again :)

@brendt
Copy link
Member

brendt commented Nov 13, 2024

Ah, you already made the changes. Peeeeerfect 💪

@brendt brendt merged commit bdf5efc into tempestphp:main Nov 13, 2024
56 checks passed
@innocenzi innocenzi deleted the feat/support/improve-string-helper branch November 13, 2024 18:49
@gturpin-dev
Copy link
Contributor

Just updated the TODO of the ArrayHelper methods issue #543 😄

Blurazzle pushed a commit to Blurazzle/tempest-framework that referenced this pull request Mar 19, 2025
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.

4 participants