diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 4a64ef3..a7737df 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -54,7 +54,7 @@ jobs: strategy: matrix: operating-system: [ubuntu-latest, windows-latest] - php-versions: [ '8.2', '8.1', '8.0'] + php-versions: [ '8.4', '8.3', '8.2', '8.1', '8.0'] dependency-stability: [ prefer-stable ] name: P${{ matrix.php-versions }} - L${{ matrix.laravel }} - ${{ matrix.dependency-stability }} - ${{ matrix.operating-system}} diff --git a/composer.json b/composer.json index fb0cf0c..d8dce85 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ } ], "require": { - "php": "^8.0|^8.1|^8.2|^8.3" + "php": "^8.0|^8.1|^8.2|^8.3|^8.4" }, "require-dev": { "phpstan/phpstan": "^1.9", diff --git a/examples/DistributionChar.php b/examples/DistributionChar.php index 82c8b2e..9379630 100644 --- a/examples/DistributionChar.php +++ b/examples/DistributionChar.php @@ -1,6 +1,6 @@ alphanumeric()->generate(); - $results[$item] = (key_exists($item, $results)) ? $results[$item] + 1 : 0; + $results[$item] = (array_key_exists($item, $results)) ? $results[$item] + 1 : 0; } ksort($results); print_r($results); diff --git a/examples/RandomBoolean.php b/examples/RandomBoolean.php index 781d12b..bec2bdb 100644 --- a/examples/RandomBoolean.php +++ b/examples/RandomBoolean.php @@ -1,5 +1,5 @@ withPreparedSets( - //deadCode: true, - //codeQuality: true, - //earlyReturn: true, - //typeDeclarations: true, - //privatization: true, - // naming: true + deadCode: true, + codeQuality: true, + earlyReturn: true, + typeDeclarations: true, + privatization: true, + naming: true ); diff --git a/src/Draw.php b/src/Draw.php index 47dc0ed..bae38ec 100644 --- a/src/Draw.php +++ b/src/Draw.php @@ -8,9 +8,8 @@ class Draw { /** * @param array $array - * @return Sample */ - public static function sample($array = []) + public static function sample($array = []): \HiFolks\RandoPhp\Models\Sample { return new Sample($array); } diff --git a/src/Models/Boolean.php b/src/Models/Boolean.php index 4078151..4df02b4 100644 --- a/src/Models/Boolean.php +++ b/src/Models/Boolean.php @@ -5,7 +5,6 @@ class Boolean { /** - * @return bool * @throws \Exception */ public function generate(): bool diff --git a/src/Models/Byte.php b/src/Models/Byte.php index 9446db6..edc8527 100644 --- a/src/Models/Byte.php +++ b/src/Models/Byte.php @@ -4,14 +4,10 @@ class Byte { - /** - * @var int - */ - private $length = 8; + private int $length = 8; /** - * @param int $length * @return $this */ public function length(int $length): self @@ -21,7 +17,6 @@ public function length(int $length): self } /** - * @return string * @throws \Exception */ public function generate(): string diff --git a/src/Models/Char.php b/src/Models/Char.php index 5000a49..2d6c0fe 100644 --- a/src/Models/Char.php +++ b/src/Models/Char.php @@ -19,15 +19,15 @@ class Char /** * @var int[] */ - private $presetAlphaLower; + private array $presetAlphaLower; /** * @var int[] */ - private $presetAlphaUpper; + private array $presetAlphaUpper; /** * @var int[] */ - private $presetNumeric; + private array $presetNumeric; /** * @var int[] @@ -40,7 +40,7 @@ class Char * - 91-96 : [\]^_` * - 123-126 : {|}~ */ - private $presetSpecialCharacters; + private array $presetSpecialCharacters; @@ -52,14 +52,14 @@ class Char * * @var string[] */ - private $transformersStack = []; + private array $transformersStack = []; /** * List of Transformers available (with the related method to call) * @var string[] */ - private $transformers = [ + private array $transformers = [ 'lower' => 'transformLower', 'upper' => 'transformUpper' ]; @@ -77,9 +77,8 @@ public function __construct() /** * Reset all attributes to default values. It is useful for the construct method * but also when you want to reinitialize Char object. - * @return void */ - public function reset() + public function reset(): void { $this->ascii_codes = []; $this->transformersStack = []; @@ -101,12 +100,11 @@ public function reset() * Add an array of chars (ordinal/numerical ascii value) to the array for randomly select char * * @param int[] $preset - * @return self */ - public function addPreset(array $preset) + public function addPreset(array $preset): static { foreach ($preset as $p) { - array_push($this->ascii_codes, $p); + $this->ascii_codes[] = $p; } return $this; } @@ -122,10 +120,7 @@ public function getAsciiCodes() return $this->ascii_codes; } - /** - * @return string - */ - public function getAsciiCodesAsString() + public function getAsciiCodesAsString(): string { return implode(",", $this->ascii_codes); } @@ -133,17 +128,15 @@ public function getAsciiCodesAsString() /** * @param int[] $charset - * @return self */ - public function addArrayCharsInt(array $charset) + public function addArrayCharsInt(array $charset): static { return $this->addPreset($charset); } /** * @param string[] $charset - * @return self */ - public function addArrayChars(array $charset) + public function addArrayChars(array $charset): static { $preset = []; foreach ($charset as $c) { @@ -157,14 +150,11 @@ public function addArrayChars(array $charset) * A Transformer is a method used in generate method to modify the char set. * For example if you want to have only lower case * (it applies strtolower to the charset) before to select randomly 1 - * - * @param string $transformType - * @return void */ - private function addTransform(string $transformType) + private function addTransform(string $transformType): void { if (array_key_exists($transformType, $this->transformers)) { - $this->transformersStack = $this->transformersStack + [$transformType]; + $this->transformersStack += [$transformType]; } } @@ -172,9 +162,8 @@ private function addTransform(string $transformType) /** * Set the alpha value to generate. 'A'-'Z' and 'a'-'z' (upper and lower case) - * @return self */ - public function alpha() + public function alpha(): static { $this->addPreset($this->presetAlphaLower); $this->addPreset($this->presetAlphaUpper); @@ -182,18 +171,16 @@ public function alpha() } /** * Set the alpha value to generate. 'a'-'z' (lower case) - * @return self */ - public function alphaLowerCase() + public function alphaLowerCase(): static { $this->addPreset($this->presetAlphaLower); return $this; } /** * Set the alpha value to generate. 'A'-'Z' (upper case) - * @return self */ - public function alphaUpperCase() + public function alphaUpperCase(): static { $this->addPreset($this->presetAlphaUpper); return $this; @@ -201,10 +188,8 @@ public function alphaUpperCase() /** * Set active transformer to lowercase - * - * @return self */ - public function lower() + public function lower(): static { $this->addTransform("lower"); return $this; @@ -212,10 +197,8 @@ public function lower() /** * Set active transformer to uppercase - * - * @return self */ - public function upper() + public function upper(): static { $this->addTransform('upper'); return $this; @@ -223,10 +206,8 @@ public function upper() /** * Set the numeric value to generate ('0'-'9') - * - * @return self */ - public function numeric() + public function numeric(): static { $this->addPreset($this->presetNumeric); return $this; @@ -234,8 +215,6 @@ public function numeric() /** * Get Alphanumeric value. 'A'-'Z' AND 'a'-'z' AND '0'-'9' - * - * @return self */ public function alphanumeric(): Char { @@ -247,10 +226,8 @@ public function alphanumeric(): Char /** * Set the special characters - * - * @return self */ - public function specialCharacters() + public function specialCharacters(): static { $this->addPreset($this->presetSpecialCharacters); return $this; @@ -260,7 +237,6 @@ public function specialCharacters() * Set Ascii Codes * * @param int[] $ascii_codes - * @return Char */ public function setAsciiCodes($ascii_codes): self { @@ -270,11 +246,10 @@ public function setAsciiCodes($ascii_codes): self /** * return true if no ascii codes is set - * @return bool */ public function hasNoAsciiCodes(): bool { - return ( sizeof($this->ascii_codes) === 0); + return ( count($this->ascii_codes) === 0); } /** @@ -293,8 +268,8 @@ public function cleanAsciiCodes(array $array): void private function transformLower(): self { $t = []; - foreach ($this->ascii_codes as $a) { - $t[] = ord(strtolower(chr($a))); + foreach ($this->ascii_codes as $ascii_code) { + $t[] = ord(strtolower(chr($ascii_code))); } $this->cleanAsciiCodes($t); return $this; @@ -306,8 +281,8 @@ private function transformLower(): self private function transformUpper(): self { $t = []; - foreach ($this->ascii_codes as $a) { - $t[] = ord(strtoupper(chr($a))); + foreach ($this->ascii_codes as $ascii_code) { + $t[] = ord(strtoupper(chr($ascii_code))); } $this->cleanAsciiCodes($t); return $this; @@ -323,7 +298,7 @@ private function transformUpper(): self public function generate(): string { - if (sizeof($this->ascii_codes) === 0) { + if (count($this->ascii_codes) === 0) { /* * The DEFAULT IS: if no set (alpha , numeric etc) is defined * it will be considered only alphabetical char in lower case @@ -331,16 +306,14 @@ public function generate(): string */ $this->addPreset($this->presetAlphaLower); } - foreach ($this->transformersStack as $transformerCode) { - call_user_func([$this, $this->transformers[$transformerCode]]); + foreach ($this->transformersStack as $transformerStack) { + call_user_func([$this, $this->transformers[$transformerStack]]); } - $rand_index = random_int(0, sizeof($this->ascii_codes) - 1); - - $returnValue = chr($this->ascii_codes[$rand_index]); + $rand_index = random_int(0, count($this->ascii_codes) - 1); // we don't need to reset because once the object is instanced, you can call // multiple time // $this->reset(); - return $returnValue; + return chr($this->ascii_codes[$rand_index]); } } diff --git a/src/Models/Chars.php b/src/Models/Chars.php index 944ffba..7e71147 100644 --- a/src/Models/Chars.php +++ b/src/Models/Chars.php @@ -6,7 +6,6 @@ class Chars extends Sequence { /** * Chars constructor. - * @param int $count * @return $this */ public function __construct(int $count = 10) diff --git a/src/Models/DateTime.php b/src/Models/DateTime.php index 94f6229..c8842d2 100644 --- a/src/Models/DateTime.php +++ b/src/Models/DateTime.php @@ -4,33 +4,23 @@ class DateTime { - /** - * @var string - */ - private $format = 'Y-m-d H:i:s'; - /** - * @var int - */ - private $min; - /** - * @var int - */ - private $max; + private string $format = 'Y-m-d H:i:s'; + private int|bool $min; + private int $max; public function __construct() { - $this->min = self::setMin(); - $this->max = self::setMax(); + $this->min = $this->setMin(); + $this->max = $this->setMax(); } /** * Set the min day * First day (time 00:00:00) * - * @param string $min * @return int */ - private static function setMin(string $min = 'first day of january this year') + private function setMin(string $min = 'first day of january this year'): int|false { return strtotime($min); } @@ -38,11 +28,8 @@ private static function setMin(string $min = 'first day of january this year') /** * Set the max day * Last day (time 23:59:59) - * - * @param string $max - * @return int */ - private static function setMax(string $max = 'last day of december this year') + private function setMax(string $max = 'last day of december this year'): int { return strtotime('tomorrow', strtotime($max)) - 1; } @@ -51,7 +38,6 @@ private static function setMax(string $max = 'last day of december this year') * Set the output format * * @param string $format to use - * @return self */ public function format(string $format): self { @@ -63,11 +49,10 @@ public function format(string $format): self * Set the greatest value to generate * * @param string $max greatest date - * @return self */ public function max(string $max): self { - $this->max = self::setMax($max); + $this->max = $this->setMax($max); return $this; } @@ -75,11 +60,10 @@ public function max(string $max): self * Set the smallest value to generate * * @param string $min smallest date - * @return self */ public function min(string $min): self { - $this->min = self::setMin($min); + $this->min = $this->setMin($min); return $this; } @@ -87,14 +71,12 @@ public function min(string $min): self * Set the range (min and max) * Calling range('01-05-1989','06-05-1989') * - * @param string $min - * @param string $max * @return $this */ - public function range(string $min, string $max) + public function range(string $min, string $max): static { - $this->min = self::setMin($min); - $this->max = self::setMax($max); + $this->min = $this->setMin($min); + $this->max = $this->setMax($max); return $this; } @@ -104,7 +86,7 @@ public function range(string $min, string $max) * @return string the random value (string) * @throws \Exception */ - public function generate() + public function generate(): string { return gmdate($this->format, random_int($this->min, $this->max)); } diff --git a/src/Models/FloatModel.php b/src/Models/FloatModel.php index 9c72aef..d901e1d 100644 --- a/src/Models/FloatModel.php +++ b/src/Models/FloatModel.php @@ -7,15 +7,9 @@ class FloatModel { - /** - * @var float - */ - private $min = 0.0; + private float|int $min = 0.0; - /** - * @var float - */ - private $max = 1.0; + private float|int $max = 1.0; /** * @var int @@ -27,7 +21,6 @@ class FloatModel * * @param int|float $max greatest value * @throws InvalidArgumentException - * @return self */ public function max($max): self { @@ -44,7 +37,6 @@ public function max($max): self * * @param int|float $min smallest value * @throws InvalidArgumentException - * @return self */ public function min($min): self { @@ -60,7 +52,6 @@ public function min($min): self * Sets the number of decimals (precision) * * @param int $decimals number of decimals (precision) - * @return self */ public function decimals(int $decimals): self { @@ -80,7 +71,6 @@ public function decimals(int $decimals): self * * @param int|float $min * @param int|float $max - * @return self */ public function range($min, $max): self { diff --git a/src/Models/Integer.php b/src/Models/Integer.php index 41fe730..25093f4 100644 --- a/src/Models/Integer.php +++ b/src/Models/Integer.php @@ -9,8 +9,6 @@ class Integer /** * Integer constructor. - * @param int $min - * @param int $max */ public function __construct(private int $min = self::DEFAULT_MIN, private int $max = self::DEFAULT_MAX) { @@ -21,7 +19,6 @@ public function __construct(private int $min = self::DEFAULT_MIN, private int $m * Set the greatest value to generate * * @param int $max greatest value - * @return self */ public function max(int $max): self { @@ -33,7 +30,6 @@ public function max(int $max): self * Set the smallest value to generate * * @param int $min smallest value - * @return self */ public function min(int $min): self { @@ -44,10 +40,6 @@ public function min(int $min): self /** * Set the range (min and max) * Calling range(1,10), it is equivalent of ->min(1)->max(10) - * - * @param int $min - * @param int $max - * @return self */ public function range(int $min, int $max): self { diff --git a/src/Models/LatLong.php b/src/Models/LatLong.php index 115b3af..28a74db 100644 --- a/src/Models/LatLong.php +++ b/src/Models/LatLong.php @@ -6,15 +6,10 @@ class LatLong { - /** - * @var string - */ - private $format = "array"; + private string $format = "array"; /** * Set output format to array. - * - * @return self */ public function asArray(): self { @@ -24,8 +19,6 @@ public function asArray(): self /** * Set output format to object. - * - * @return self */ public function asObject(): self { @@ -35,8 +28,6 @@ public function asObject(): self /** * Set output format to latitude. - * - * @return self */ public function asLatitude(): self { @@ -46,8 +37,6 @@ public function asLatitude(): self /** * Set output format to longitude. - * - * @return self */ public function asLongitude(): self { diff --git a/src/Models/Sample.php b/src/Models/Sample.php index 5dd7ef1..f857baf 100644 --- a/src/Models/Sample.php +++ b/src/Models/Sample.php @@ -11,22 +11,10 @@ */ class Sample { - /** - * @var int - */ - private $count = 1; - /** - * @var bool - */ - private $unique = true; - /** - * @var bool - */ - private $implode = false; - /** - * @var bool - */ - private $preserveKeys = false; + private int $count = 1; + private bool $unique = true; + private bool $implode = false; + private bool $preserveKeys = false; /** @@ -41,10 +29,9 @@ public function __construct(private $array = []) /** * Number of items to "extract" * - * @param int $count * @return $this */ - public function count($count = 1) + public function count(int $count = 1): static { $this->count = $count; return $this; @@ -63,10 +50,9 @@ public function preserveKeys(): self /** * Sets the unique attribute * - * @param bool $unique * @return $this */ - public function unique($unique = true): self + public function unique(bool $unique = true): self { $this->unique = $unique; return $this; @@ -74,20 +60,16 @@ public function unique($unique = true): self /** * Allow extract duplicates from the original array - * - * @return $this */ - public function allowDuplicates() + public function allowDuplicates(): \HiFolks\RandoPhp\Models\Sample { return $this->unique(false); } /** * No duplicates from the original array - * - * @return $this */ - public function noDuplicates() + public function noDuplicates(): \HiFolks\RandoPhp\Models\Sample { return $this->unique(true); } @@ -97,7 +79,7 @@ public function noDuplicates() * * @return int[]|string[]|int|string|null */ - public function extractKeys() + public function extractKeys(): array|null|int|string { $size = count($this->array); if ($size >= 1) { @@ -108,30 +90,24 @@ public function extractKeys() $result[] = $keys[random_int(0, count($keys) - 1)]; } return $result; - } else { - $a = null; - try { - $a = array_rand($this->array, $this->count); - if (is_array($a)) { - shuffle($a); - } - } catch (\Exception | \Error) { - return null; + } + $a = null; + try { + $a = array_rand($this->array, $this->count); + if (is_array($a)) { + shuffle($a); } - - return $a; + } catch (\Exception | \Error) { + return null; } - } else { - return null; + return $a; } + return null; } /** * Set the output. The extract method instead of returning an array, * it returns a string with items separated by "," - * - * @param bool $implode - * @return Sample */ public function implode(bool $implode = true): self { @@ -153,10 +129,9 @@ public function snap() * Return just 1 element (the key) from array * @return int|int[]|string|string[]|null */ - public function snapKey() + public function snapKey(): int|string|array|null { - $key = $this->count(1)->preserveKeys()->extractKeys(); - return $key; + return $this->count(1)->preserveKeys()->extractKeys(); } @@ -166,27 +141,24 @@ public function snapKey() * @return int[]|string[]|\stdClass[]|string * @throws \Exception */ - public function extract() + public function extract(): string|array { $keys = $this->extractKeys(); $results = []; foreach ((array) $keys as $key) { if (! $this->unique) { $results[] = $this->array[$key]; + } elseif ($this->preserveKeys) { + $results[$key] = $this->array[$key]; } else { - if ($this->preserveKeys) { - $results[$key] = $this->array[$key]; - } else { - $results[] = $this->array[$key]; - } + $results[] = $this->array[$key]; } } if ($this->implode) { // @TODO implode only for scalar type items /** @phpstan-ignore-next-line */ return implode(";", $results); - } else { - return $results; } + return $results; } } diff --git a/src/Models/Sequence.php b/src/Models/Sequence.php index 5b2643d..92519c5 100644 --- a/src/Models/Sequence.php +++ b/src/Models/Sequence.php @@ -7,46 +7,22 @@ class Sequence { - /** - * @var string - */ - private $type = "int"; - /** - * @var int - */ - private $count = 10; - /** - * @var int - */ - private $min = 0; - /** - * @var int - */ - private $max = 10; - /** - * @var bool - */ - private $unique = false; - /** - * @var bool - */ - private $implode = false; - /** - * @var bool - */ - private $toString = false; + private string $type = "int"; + private int $count = 10; + private int $min = 0; + private int $max = 10; + private bool $unique = false; + private bool $implode = false; + private bool $toString = false; - /** - * @var Char - */ - private $charModel; + private ?\HiFolks\RandoPhp\Models\Char $char = null; /** * @return $this */ - public function integer() + public function integer(): static { $this->type("int"); return $this; @@ -60,7 +36,7 @@ public function integer() */ public function chars(): self { - $this->charModel = new Char(); + $this->char = new Char(); $this->type = "char"; return $this; } @@ -70,10 +46,9 @@ public function chars(): self * [1,2,4,7,3] is $unique === true, no duplicates * [1,4,3,4,3] is $unique === false, with duplicates * - * @param bool $unique * @return $this */ - public function unique($unique = true): self + public function unique(bool $unique = true): self { $this->unique = $unique; return $this; @@ -98,8 +73,6 @@ public function noDuplicates(): self /** * Set the output. The extract method instead of returning an array, * it returns a string with items separated by "," - * - * @param bool $implode */ public function implode(bool $implode = true): self { @@ -108,7 +81,6 @@ public function implode(bool $implode = true): self } /** - * @param int $min * @return $this */ public function min(int $min): self @@ -118,7 +90,6 @@ public function min(int $min): self } /** - * @param int $max * @return $this */ public function max(int $max): self @@ -128,7 +99,6 @@ public function max(int $max): self } /** - * @param int $count * @return $this */ public function count(int $count): self @@ -138,7 +108,6 @@ public function count(int $count): self } /** - * @param string $type * @return $this */ public function type(string $type): self @@ -149,45 +118,37 @@ public function type(string $type): self /** * Set the alpha value to generate - * - * @return self */ - public function alpha() + public function alpha(): static { - $this->charModel->alpha(); + $this->char->alpha(); return $this; } /** * Set the numeric value to generate - * - * @return self */ - public function numeric() + public function numeric(): static { - $this->charModel->numeric(); + $this->char->numeric(); return $this; } /** * Get Alphanumeric value - * - * @return self */ - public function alphanumeric() + public function alphanumeric(): static { - $this->charModel->alphanumeric(); + $this->char->alphanumeric(); return $this; } /** * Get SpecialCharacters value - * - * @return self */ - public function specialCharacters() + public function specialCharacters(): static { - $this->charModel->specialCharacters(); + $this->char->specialCharacters(); return $this; } @@ -197,25 +158,21 @@ public function specialCharacters() */ public function alphaLowerCase(): self { - $this->charModel->alphaLowerCase(); + $this->char->alphaLowerCase(); return $this; } /** * It sets upper case char set - * @return self */ public function alphaUpperCase(): self { - $this->charModel->alphaUpperCase(); + $this->char->alphaUpperCase(); return $this; } /** * Get String - * - * @param bool $toString - * @return self */ public function asString(bool $toString = true): self { @@ -230,7 +187,7 @@ public function asString(bool $toString = true): self * @return int[]|string[]|string * @throws \Exception */ - public function generate() + public function generate(): string|array { $result = []; @@ -247,32 +204,33 @@ public function generate() break; case "char": - if ($this->charModel->hasNoAsciiCodes()) { - $this->charModel->alphaLowerCase(); + if ($this->char->hasNoAsciiCodes()) { + $this->char->alphaLowerCase(); } if ($this->unique) { $intArrResult = - Draw::sample($this->charModel->getAsciiCodes()) + Draw::sample($this->char->getAsciiCodes()) ->noDuplicates() ->count($this->count) ->extract(); - for ($i = 0; $i < sizeof($intArrResult); $i++) { + $counter = count($intArrResult); + for ($i = 0; $i < $counter; $i++) { $result[] = chr($intArrResult[$i]); } } else { for ($i = 0; $i < $this->count; $i++) { - $result[] = $this->charModel->generate(); + $result[] = $this->char->generate(); } } break; } - if ($this->implode) { return implode(";", $result); - } elseif ($this->toString) { + } + + if ($this->toString) { return implode("", $result); - } else { - return $result; } + return $result; } } diff --git a/src/Randomize.php b/src/Randomize.php index 811a63d..a18724d 100644 --- a/src/Randomize.php +++ b/src/Randomize.php @@ -32,7 +32,7 @@ class Randomize * Registered models with format: 'methodToLoadModel' => ClassName * @var mixed[] $models */ - private static $models = [ + private static array $models = [ 'boolean' => Boolean::class, //'integer' => IntModel::class, 'float' => FloatModel::class, @@ -47,19 +47,19 @@ class Randomize /** * @param int $min * @param int $max - * @return IntModel */ - public static function integer($min = IntModel::DEFAULT_MIN, $max = IntModel::DEFAULT_MAX) - { + public static function integer( + $min = IntModel::DEFAULT_MIN, + $max = IntModel::DEFAULT_MAX + ): \HiFolks\RandoPhp\Models\Integer { return new IntModel($min, $max); } /** * @param int $count - * @return Chars */ - public static function chars($count = 10) + public static function chars($count = 10): \HiFolks\RandoPhp\Models\Chars { return new Chars($count); } @@ -68,7 +68,6 @@ public static function chars($count = 10) /** * Return the model registered in $models property * - * @param string $name * @return mixed * @throws ModelNotFoundException */ diff --git a/tests/DrawSampleTest.php b/tests/DrawSampleTest.php index 31830b0..964083e 100644 --- a/tests/DrawSampleTest.php +++ b/tests/DrawSampleTest.php @@ -8,7 +8,7 @@ class DrawSampleTest extends TestCase { /** @test */ - public function random_extract() + public function random_extract(): void { $array = [1,2,3,4,5,6,7,8,9]; $count = 5; @@ -20,7 +20,7 @@ public function random_extract() $this->assertSame($count, count($sampleKeys)); } /** @test */ - public function random_extract_duplicates() + public function random_extract_duplicates(): void { $array = [1, 2, 3, 4, 5, 6, 7, 8, 9]; $count = 5; @@ -30,7 +30,7 @@ public function random_extract_duplicates() } /** @test */ - public function random_extract_keys() + public function random_extract_keys(): void { $array = [1, 2, 3, 4, 5, 6, 7, 8, 9]; $count = 5; @@ -40,10 +40,9 @@ public function random_extract_keys() } /** @test */ - public function random_extract_keys_with_empty_stuff() + public function random_extract_keys_with_empty_stuff(): void { $array = [1, 2, 3, 4, 5, 6, 7, 8, 9]; - $count = 5; $sampleKeys = Draw::sample($array)->count(0)->extractKeys(); $this->assertSame(null, $sampleKeys, "Null for count 0"); $this->assertEmpty($sampleKeys, "Check extract key with 0 count"); @@ -52,7 +51,7 @@ public function random_extract_keys_with_empty_stuff() } /** @test */ - public function random_extract_implode() + public function random_extract_implode(): void { $array = [1,2,3,4,5,6,7,8,9]; $count = 5; @@ -61,7 +60,7 @@ public function random_extract_implode() } /** @test */ - public function random_extract_preservekeys() + public function random_extract_preservekeys(): void { $array = range(1, 100); $count = 5; @@ -71,7 +70,7 @@ public function random_extract_preservekeys() } /** @test */ - public function random_snap() + public function random_snap(): void { $array = ["testa" => "Testa", "croce" => "Croce"]; diff --git a/tests/LoadModelsWithMagicFunctionsTest.php b/tests/LoadModelsWithMagicFunctionsTest.php index 53661e9..e90f4fe 100644 --- a/tests/LoadModelsWithMagicFunctionsTest.php +++ b/tests/LoadModelsWithMagicFunctionsTest.php @@ -11,65 +11,65 @@ class LoadModelsWithMagicFunctionsTest extends TestCase { /** @test */ - public function load_boolean_test() + public function load_boolean_test(): void { - $model = Randomize::boolean(); - $this->assertInstanceOf(Models\Boolean::class, $model); + $boolean = Randomize::boolean(); + $this->assertInstanceOf(Models\Boolean::class, $boolean); } /** @test */ - public function load_integer_test() + public function load_integer_test(): void { - $model = Randomize::integer(); - $this->assertInstanceOf(Models\Integer::class, $model); + $integer = Randomize::integer(); + $this->assertInstanceOf(Models\Integer::class, $integer); } /** @test */ - public function load_float_test() + public function load_float_test(): void { - $model = Randomize::float(); - $this->assertInstanceOf(Models\FloatModel::class, $model); + $floatModel = Randomize::float(); + $this->assertInstanceOf(Models\FloatModel::class, $floatModel); } /** @test */ - public function load_byte_test() + public function load_byte_test(): void { - $model = Randomize::byte(); - $this->assertInstanceOf(Models\Byte::class, $model); + $byte = Randomize::byte(); + $this->assertInstanceOf(Models\Byte::class, $byte); } /** @test */ - public function load_sequence_test() + public function load_sequence_test(): void { - $model = Randomize::sequence(); - $this->assertInstanceOf(Models\Sequence::class, $model); + $sequence = Randomize::sequence(); + $this->assertInstanceOf(Models\Sequence::class, $sequence); } /** @test */ - public function load_datetime_test() + public function load_datetime_test(): void { - $model = Randomize::datetime(); - $this->assertInstanceOf(Models\DateTime::class, $model); + $dateTime = Randomize::datetime(); + $this->assertInstanceOf(Models\DateTime::class, $dateTime); } /** @test */ - public function load_char_test() + public function load_char_test(): void { - $model = Randomize::char(); - $this->assertInstanceOf(Models\Char::class, $model); + $char = Randomize::char(); + $this->assertInstanceOf(Models\Char::class, $char); } /** @test */ - public function load_latlong_test() + public function load_latlong_test(): void { - $model = Randomize::latlong(); - $this->assertInstanceOf(Models\LatLong::class, $model); + $latLong = Randomize::latlong(); + $this->assertInstanceOf(Models\LatLong::class, $latLong); } /** @test */ - public function model_not_found_exception_test() + public function model_not_found_exception_test(): void { $this->expectException(ModelNotFoundException::class); - $model = Randomize::nonExistingModel(); + Randomize::nonExistingModel(); } } diff --git a/tests/RandomBooleanTest.php b/tests/RandomBooleanTest.php index 5c85887..cb8ba14 100644 --- a/tests/RandomBooleanTest.php +++ b/tests/RandomBooleanTest.php @@ -8,7 +8,7 @@ class RandomBooleanTest extends TestCase { /** @test */ - public function random_boolean() + public function random_boolean(): void { $boolean = Randomize::boolean()->generate(); $this->assertGreaterThanOrEqual(0, $boolean, "Check min number - boolean"); diff --git a/tests/RandomByteTest.php b/tests/RandomByteTest.php index ba22d9b..527d0d0 100644 --- a/tests/RandomByteTest.php +++ b/tests/RandomByteTest.php @@ -8,7 +8,7 @@ class RandomByteTest extends TestCase { /** @test */ - public function random_byte() + public function random_byte(): void { $byte = Randomize::byte()->generate(); $this->assertIsString($byte, "Is String"); diff --git a/tests/RandomCharTest.php b/tests/RandomCharTest.php index a301188..4a70be8 100644 --- a/tests/RandomCharTest.php +++ b/tests/RandomCharTest.php @@ -8,7 +8,7 @@ class RandomCharTest extends TestCase { /** @test */ - public function it_generates_char() + public function it_generates_char(): void { $char = Randomize::char()->generate(); $this->assertIsString($char, "Is String"); @@ -37,11 +37,11 @@ public function it_generates_char() $this->assertIsString($char, "Is String"); $this->assertSame(1, strlen($char), "Is 1 char"); $this->assertTrue(ctype_alpha($char), "Check for alphabetic character"); - $this->assertTrue(($char === 'a' or $char === 'b'), "Check for alphabetic character: " . $char); + $this->assertTrue(($char === 'a' || $char === 'b'), "Check for alphabetic character: " . $char); } /** @test */ - public function it_generates_alpha_char() + public function it_generates_alpha_char(): void { $alpha = Randomize::char()->alpha()->generate(); $this->assertIsString($alpha, "Is String"); @@ -50,7 +50,7 @@ public function it_generates_alpha_char() } /** @test */ - public function it_generates_lowercase_alpha() + public function it_generates_lowercase_alpha(): void { $alpha = Randomize::char()->alpha()->lower()->generate(); $this->assertIsString($alpha, "Is String"); @@ -60,7 +60,7 @@ public function it_generates_lowercase_alpha() } /** @test */ - public function it_generates_uppercase_alpha() + public function it_generates_uppercase_alpha(): void { $alpha = Randomize::char()->alpha()->upper()->generate(); $this->assertIsString($alpha, "Is String"); @@ -70,7 +70,7 @@ public function it_generates_uppercase_alpha() } /** @test */ - public function it_generates_numeric_char() + public function it_generates_numeric_char(): void { $alpha = Randomize::char()->numeric()->generate(); $this->assertIsString($alpha, "Is String"); @@ -79,7 +79,7 @@ public function it_generates_numeric_char() } /** @test */ - public function it_generates_alphanumeric_char() + public function it_generates_alphanumeric_char(): void { $alpha = Randomize::char()->alphanumeric()->generate(); $this->assertIsString($alpha, "Is String"); @@ -88,7 +88,7 @@ public function it_generates_alphanumeric_char() } /** @test */ - public function it_generates_alphanumeric_lowercase_char() + public function it_generates_alphanumeric_lowercase_char(): void { $alpha = Randomize::char()->alphanumeric()->lower()->generate(); $this->assertIsString($alpha, "Is String"); @@ -98,7 +98,7 @@ public function it_generates_alphanumeric_lowercase_char() } /** @test */ - public function it_generates_alphanumeric_uppercase_char() + public function it_generates_alphanumeric_uppercase_char(): void { $alpha = Randomize::char()->alphanumeric()->upper()->generate(); $this->assertIsString($alpha, "Is String"); @@ -108,7 +108,7 @@ public function it_generates_alphanumeric_uppercase_char() } /** @test */ - public function it_generates_customchars() + public function it_generates_customchars(): void { $array = range(33, 47); $obj = Randomize::char()->addArrayCharsInt($array); diff --git a/tests/RandomCharsTest.php b/tests/RandomCharsTest.php index 11d6477..4269891 100644 --- a/tests/RandomCharsTest.php +++ b/tests/RandomCharsTest.php @@ -10,7 +10,7 @@ class RandomCharsTest extends TestCase /** * @test */ - public function random_sequence() + public function random_sequence(): void { $string = Randomize::chars()->generate(); $this->assertIsString($string, "Check is String"); @@ -20,7 +20,7 @@ public function random_sequence() /** * @test */ - public function random_count_sequence() + public function random_count_sequence(): void { $string = Randomize::chars()->count(7)->generate(); $this->assertIsString($string, "Check is String"); @@ -33,7 +33,7 @@ public function random_count_sequence() /** * @test */ - public function random_char_sequence() + public function random_char_sequence(): void { $string = Randomize::chars()->generate(); $this->assertIsString($string, "Char sequence check is String"); @@ -42,7 +42,7 @@ public function random_char_sequence() /** * @test */ - public function random_no_duplicate_char_sequence() + public function random_no_duplicate_char_sequence(): void { $string = Randomize::chars(7)->noDuplicates()->generate(); $arrayUnique = array_unique(str_split($string)); @@ -56,7 +56,7 @@ public function random_no_duplicate_char_sequence() /** * @test */ - public function random_numeric_char_sequence() + public function random_numeric_char_sequence(): void { $len = 5; $string = Randomize::chars()->numeric()->count($len)->generate(); @@ -88,7 +88,7 @@ public function random_numeric_char_sequence() /** * @test */ - public function random_special_characters() + public function random_special_characters(): void { $string = Randomize::chars(20)->specialCharacters()->alpha()->generate(); $this->assertEquals(20, strlen($string), "String with special characters"); diff --git a/tests/RandomDateTimeTest.php b/tests/RandomDateTimeTest.php index cfafbee..56bec13 100644 --- a/tests/RandomDateTimeTest.php +++ b/tests/RandomDateTimeTest.php @@ -8,27 +8,27 @@ class RandomDateTimeTest extends TestCase { /** @test */ - public function random_datetime() + public function random_datetime(): void { $datetime = Randomize::datetime()->generate(); $this->assertIsString($datetime, "Is String"); } /** @test */ - public function random_datetime_min_max() + public function random_datetime_min_max(): void { $datetime = Randomize::datetime()->min('01-10-2020')->max('10-10-2020')->generate(); $this->assertIsString($datetime, "Min/Max working"); } /** @test */ - public function random_datetime_format() + public function random_datetime_format(): void { $year = Randomize::datetime()->min('01-10-2020')->max('10-10-2020')->format("Y")->generate(); $this->assertEquals("2020", $year); } /** @test */ - public function random_datetime_range_format() + public function random_datetime_range_format(): void { $month = Randomize::datetime()->range('01-10-2020', '30-10-2020')->format("m")->generate(); $this->assertSame("10", $month, "Extracting the right month"); diff --git a/tests/RandomIntegerTest.php b/tests/RandomIntegerTest.php index f5ac216..5c578dc 100644 --- a/tests/RandomIntegerTest.php +++ b/tests/RandomIntegerTest.php @@ -10,7 +10,7 @@ class RandomIntegerTest extends TestCase { /** @test */ - public function random_integer() + public function random_integer(): void { $number = Randomize::integer()->max(5)->generate(); $this->assertGreaterThanOrEqual(0, $number, "Check min number"); @@ -23,7 +23,7 @@ public function random_integer() $this->assertIsInt($number, "Check is integer"); } /** @test */ - public function random_integer_min_max() + public function random_integer_min_max(): void { $min = 90; $max = 95; @@ -44,7 +44,7 @@ public function random_integer_min_max() } /** @test */ - public function random_integer_min_max_wrong() + public function random_integer_min_max_wrong(): void { $min = 50; $max = 30; diff --git a/tests/RandomSequenceTest.php b/tests/RandomSequenceTest.php index 6ff69c1..e3485bb 100644 --- a/tests/RandomSequenceTest.php +++ b/tests/RandomSequenceTest.php @@ -12,7 +12,7 @@ class RandomSequenceTest extends TestCase * * @test */ - public function random_sequence() + public function random_sequence(): void { $array = Randomize::sequence()->generate(); $this->assertIsArray($array, "Check is array"); @@ -23,7 +23,7 @@ public function random_sequence() * * @test */ - public function random_count_sequence() + public function random_count_sequence(): void { $array = Randomize::sequence()->count(7)->generate(); $this->assertIsArray($array, "Check is array"); @@ -35,7 +35,7 @@ public function random_count_sequence() * * @test */ - public function random_char_sequence() + public function random_char_sequence(): void { $array = Randomize::sequence()->chars()->generate(); $this->assertIsArray($array, "Char sequence check is array"); @@ -46,7 +46,7 @@ public function random_char_sequence() * * @test */ - public function random_count_char_sequence() + public function random_count_char_sequence(): void { $array = Randomize::sequence()->chars()->count(7)->generate(); $this->assertIsArray($array, "Char sequence check is array"); @@ -56,7 +56,7 @@ public function random_count_char_sequence() /** * @test */ - public function random_no_duplicate_char_sequence() + public function random_no_duplicate_char_sequence(): void { $array = Randomize::sequence()->chars()->count(7)->noDuplicates()->generate(); $arrryUnique = array_unique($array); @@ -66,7 +66,7 @@ public function random_no_duplicate_char_sequence() /** * @test */ - public function random_numeric_char_sequence() + public function random_numeric_char_sequence(): void { $len = 5; $string = Randomize::sequence()->chars()->asString()->numeric()->count($len)->generate(); @@ -102,7 +102,7 @@ public function random_numeric_char_sequence() * * @test */ - public function random_rollthedice() + public function random_rollthedice(): void { $count = 10; $min = 1; @@ -138,7 +138,7 @@ public function random_rollthedice() * * @test */ - public function random_tombola() + public function random_tombola(): void { $count = 90; $min = 1; @@ -159,7 +159,7 @@ public function random_tombola() * * @test */ - public function random_sequence_implode() + public function random_sequence_implode(): void { $min = 1; $max = 10; @@ -173,7 +173,7 @@ public function random_sequence_implode() * * @test */ - public function random_sequence_asString() + public function random_sequence_asString(): void { $min = 1; $max = 10;