Skip to content

Commit

Permalink
Merge pull request #1679 from tarlepp/feat/string-component
Browse files Browse the repository at this point in the history
Feat - Added `symfony/string` component and refactored `ApiKey` entity to use it
  • Loading branch information
tarlepp committed Feb 6, 2022
2 parents 4fc807f + 8dc53db commit 712db81
Show file tree
Hide file tree
Showing 13 changed files with 134 additions and 140 deletions.
1 change: 1 addition & 0 deletions composer.json
Expand Up @@ -54,6 +54,7 @@
"symfony/runtime": "6.0.3",
"symfony/security-bundle": "6.0.3",
"symfony/serializer": "6.0.3",
"symfony/string": "6.0.3",
"symfony/translation": "6.0.3",
"symfony/twig-bundle": "6.0.3",
"symfony/validator": "6.0.3",
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 2 additions & 9 deletions src/Entity/ApiKey.php
Expand Up @@ -23,13 +23,13 @@
use Ramsey\Uuid\UuidInterface;
use Symfony\Bridge\Doctrine\Validator\Constraints as AssertCollection;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\String\ByteString;
use Symfony\Component\Validator\Constraints as Assert;
use Throwable;
use function array_map;
use function array_merge;
use function array_unique;
use function array_values;
use function random_int;

/**
* Class ApiKey
Expand Down Expand Up @@ -165,14 +165,7 @@ public function setToken(string $token): self
*/
public function generateToken(): self
{
$random = '';
$chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';

for ($i = 0; $i < 40; $i++) {
$random .= $chars[random_int(0, 61)];
}

return $this->setToken($random);
return $this->setToken(ByteString::fromRandom(40)->toString());
}

public function getDescription(): string
Expand Down
36 changes: 18 additions & 18 deletions tools/01_phpunit/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions tools/02_phpstan/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 15 additions & 15 deletions tools/03_psalm/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 18 additions & 18 deletions tools/04_symplify/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 712db81

Please sign in to comment.