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

2 new helpers #3

Merged
merged 2 commits into from
Feb 1, 2023
Merged

2 new helpers #3

merged 2 commits into from
Feb 1, 2023

Conversation

makowskid
Copy link
Contributor

function random_code(int $length = 7): string

function random_code_chars(bool $only_letters = false): array

^[[APsy Shell v0.11.10 (PHP 8.1.11 — cli) by Justin Hileman
> random_code();
= "FBN3LHP"

> random_code();
= "KQ4BVY8"

@stepanenko3
Copy link
Owner

Hi, @makowskid

Why not just use Str::random?

@makowskid
Copy link
Contributor Author

Hi, @makowskid

Why not just use Str::random?

Please check the comments.
This method is very useful to add codes to important business objects (orders, flights bookings, transactions etc.):

  • code is random (of course)
  • can be spelt via phone
  • designed to be interpreted by humans
  • has only capital letters (easier to spell), capital-agnostic
  • does not have confusing characters like 0/O, 1/l/I, etc
  • (should be used with system-wide check for uniqueness)
  • (its a bit like human-readable UUID)

@stepanenko3 stepanenko3 merged commit 9fc5f8c into stepanenko3:main Feb 1, 2023
@makowskid
Copy link
Contributor Author

дякую Арте́м!

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.

2 participants