Skip to content

Commit

Permalink
Merge pull request #18 from shatterproof/mixedcase
Browse files Browse the repository at this point in the history
Rename `dashed` $lower to $mixedCase
  • Loading branch information
valorin authored Jan 14, 2024
2 parents dd47d28 + 05bd013 commit 71aae8e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ $token = Random::token(int $length = 32): string;
$password = Random::password(int $length = 16, bool $requireAll = false): string;

// Random alphanumeric token string with chunks separated by dashes, making it easy to read and type.
$password = Random::dashed(int $length = 25, string $delimiter = '-', int $chunkLength = 5, bool $lower = true): string;
$password = Random::dashed(int $length = 25, string $delimiter = '-', int $chunkLength = 5, bool $mixedCase = true): string;
```

To limit the characters available in any of the types (i.e. lower, upper, numbers, or symbols),
Expand Down
12 changes: 6 additions & 6 deletions src/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public function token(int $length = 32): string
* Note, this doesn't guarantee that all the character sets will be included, you can use Random::string() for that.
*
* @param int $length
* @param bool $requireAll If true, at least one character from each set will be included.
* @param bool $requireAll If true, at least one character from each set will be included.
* @return string
*/
public function password(int $length = 16, bool $requireAll = false): string
Expand All @@ -174,12 +174,12 @@ public function password(int $length = 16, bool $requireAll = false): string
* @param int $length
* @param string $delimiter
* @param int $chunkLength = 5
* @param bool $lower
* @param bool $mixedCase If true, lowercase letters will be included.
* @return string
*/
public function dashed(int $length = 25, string $delimiter = '-', int $chunkLength = 5, bool $lower = true): string
public function dashed(int $length = 25, string $delimiter = '-', int $chunkLength = 5, bool $mixedCase = true): string
{
$string = $this->string($length, $lower, true, true, false, true);
$string = $this->string($length, $mixedCase, true, true, false, true);

return wordwrap($string, $chunkLength, $delimiter, true);
}
Expand Down Expand Up @@ -272,7 +272,7 @@ public function pickOne($values)
}

/**
* Use custom lower case character set for random string generation.
* Use custom lowercase character set for random string generation.
*
* @param array $characters
* @return self
Expand All @@ -287,7 +287,7 @@ public function useLower(array $characters): self
}

/**
* Use custom upper case character set for random string generation.
* Use custom uppercase character set for random string generation.
*
* @param array $characters
* @return self
Expand Down
12 changes: 11 additions & 1 deletion tests/StringTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,23 @@ public function testPassword()
public function testDashed()
{
for ($i = 0; $i < 100; $i++) {
$string = Random::dashed($length = 25, $delimiter = '-');
$string = Random::dashed($length = 25, $delimiter = '-', $chunkLength = 5, $mixedCase = true);

$this->assertIsString($string);
$this->assertRegExpCustom('/^[a-zA-Z0-9]{5}\-[a-zA-Z0-9]{5}\-[a-zA-Z0-9]{5}\-[a-zA-Z0-9]{5}\-[a-zA-Z0-9]{5}$/', $string);
}
}

public function testDashedNoLowerCase()
{
for ($i = 0; $i < 100; $i++) {
$string = Random::dashed($length = 25, $delimiter = '-', $chunkLength = 5, $mixedCase = false);

$this->assertIsString($string);
$this->assertRegExpCustom('/^[A-Z0-9]{5}\-[A-Z0-9]{5}\-[A-Z0-9]{5}\-[A-Z0-9]{5}\-[A-Z0-9]{5}$/', $string);
}
}

public function testCustomCharacterSets()
{
$generator = Random::useLower(range('a', 'f'))
Expand Down

0 comments on commit 71aae8e

Please sign in to comment.