Skip to content
This repository has been archived by the owner on Mar 18, 2022. It is now read-only.

Commit

Permalink
Update helper functions
Browse files Browse the repository at this point in the history
Update faker function to return Generator object
fixed randomNumber if statement bug
Update randomString helper function
  • Loading branch information
Alireza Josheghani committed Feb 4, 2017
1 parent 7917e59 commit ab8c4fe
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions src/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ function string($value)
*
* @author Alireza Josheghani <josheghani.dev@gmail.com>
* @since 3 Feb 2016
* @return Faker
* @return Generator
*/
function faker()
{
return new Faker();
return new Generator();
}
}

Expand All @@ -49,7 +49,7 @@ function randomNumber($length = 20, $int = false)

for($i = 1;$i <= $length;$i++){
$num = $numbers[rand(0,strlen($numbers) - 1)];
if($num === 0 && $i === 1){
if($num == 0 && $i == 1){
continue;
}

Expand Down Expand Up @@ -77,20 +77,19 @@ function randomNumber($length = 20, $int = false)
*/
function randomString($length = 20, $type = null){

$uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$characters = [
'uppercase' => 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
'lowercase' => 'abcdefghijklmnopqrstuvwxyz'
];

$lowercase = 'abcdefghijklmnopqrstuvwxyz';

if(is_null($type)){

$characters = $uppercase . $lowercase;

} elseif ($type = 'lowercase'){
if(($type !== 'uppercase' && $type !== 'lowercase') && ! is_null($type)){
throw new \Exception("The type of $type does not exists!");
}

$characters = $lowercase;
$characters = array_merge($characters);

} else {
$characters = $uppercase;
if(! is_null($type)){
$characters = $characters[$type];
}

$string = '';
Expand Down

0 comments on commit ab8c4fe

Please sign in to comment.