-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split Randomizer into smaller interfaces
- Loading branch information
Showing
4 changed files
with
112 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace Aedart\Contracts\Utils\Random; | ||
|
||
use Throwable; | ||
|
||
/** | ||
* Array Randomizer | ||
* | ||
* @author Alin Eugen Deac <[email protected]> | ||
* @package Aedart\Contracts\Utils\Random | ||
*/ | ||
interface ArrayRandomizer | ||
{ | ||
/** | ||
* Returns random array keys | ||
* | ||
* @param array $arr | ||
* @param int $amount Amount of keys to return | ||
* | ||
* @return array<string>|array<int> | ||
* | ||
* @throws Throwable | ||
*/ | ||
public function pickKeys(array $arr, int $amount): array; | ||
|
||
/** | ||
* Shuffles given array | ||
* | ||
* @param array $arr | ||
* | ||
* @return array New shuffled array | ||
* | ||
* @throws Throwable | ||
*/ | ||
public function shuffle(array $arr): array; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace Aedart\Contracts\Utils\Random; | ||
|
||
use Throwable; | ||
|
||
/** | ||
* Numeric Randomizer | ||
* | ||
* @author Alin Eugen Deac <[email protected]> | ||
* @package Aedart\Contracts\Utils\Random | ||
*/ | ||
interface NumericRandomizer | ||
{ | ||
/** | ||
* Returns a uniformly selected integer | ||
* | ||
* @param int $min | ||
* @param int $max | ||
* | ||
* @return int | ||
* | ||
* @throws Throwable | ||
*/ | ||
public function int(int $min, int $max): int; | ||
|
||
/** | ||
* Returns next positive integer | ||
* | ||
* @return int | ||
* | ||
* @throws Throwable | ||
*/ | ||
public function nextInt(): int; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,74 +10,11 @@ | |
* @author Alin Eugen Deac <[email protected]> | ||
* @package Aedart\Contracts\Utils\Random | ||
*/ | ||
interface Randomizer | ||
interface Randomizer extends | ||
StringRandomizer, | ||
NumericRandomizer, | ||
ArrayRandomizer | ||
{ | ||
/** | ||
* Returns random bytes | ||
* | ||
* @param int $length | ||
* | ||
* @return string | ||
* | ||
* @throws Throwable | ||
*/ | ||
public function bytes(int $length): string; | ||
|
||
/** | ||
* Returns a uniformly selected integer | ||
* | ||
* @param int $min | ||
* @param int $max | ||
* | ||
* @return int | ||
* | ||
* @throws Throwable | ||
*/ | ||
public function int(int $min, int $max): int; | ||
|
||
/** | ||
* Returns next positive integer | ||
* | ||
* @return int | ||
* | ||
* @throws Throwable | ||
*/ | ||
public function nextInt(): int; | ||
|
||
/** | ||
* Returns random array keys | ||
* | ||
* @param array $arr | ||
* @param int $amount Amount of keys to return | ||
* | ||
* @return array<string>|array<int> | ||
* | ||
* @throws Throwable | ||
*/ | ||
public function pickKeys(array $arr, int $amount): array; | ||
|
||
/** | ||
* Shuffles given array | ||
* | ||
* @param array $arr | ||
* | ||
* @return array New shuffled array | ||
* | ||
* @throws Throwable | ||
*/ | ||
public function shuffle(array $arr): array; | ||
|
||
/** | ||
* Shuffles given bytes | ||
* | ||
* @param string $bytes | ||
* | ||
* @return string New shuffled bytes | ||
* | ||
* @throws Throwable | ||
*/ | ||
public function shuffleBytes(string $bytes): string; | ||
|
||
/** | ||
* Returns the underlying driver of this randomizer | ||
* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace Aedart\Contracts\Utils\Random; | ||
|
||
use Throwable; | ||
|
||
/** | ||
* String Randomizer | ||
* | ||
* @author Alin Eugen Deac <[email protected]> | ||
* @package Aedart\Contracts\Utils\Random | ||
*/ | ||
interface StringRandomizer | ||
{ | ||
/** | ||
* Returns random bytes | ||
* | ||
* @param int $length | ||
* | ||
* @return string | ||
* | ||
* @throws Throwable | ||
*/ | ||
public function bytes(int $length): string; | ||
|
||
/** | ||
* Shuffles given bytes | ||
* | ||
* @param string $bytes | ||
* | ||
* @return string New shuffled bytes | ||
* | ||
* @throws Throwable | ||
*/ | ||
public function shuffleBytes(string $bytes): string; | ||
} |