for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace iiifx\PasswordGenerator;
use InvalidArgumentException;
class Length
{
/**
* @var int
*/
protected $min;
protected $max;
* @param int $min
* @param int|null $max
public function __construct ( $min = 8, $max = null )
$this->setMin( $min );
$this->setMax( $max === null ? $min : $max );
}
*
* @return bool
* @throws InvalidArgumentException
protected function setMin ( $min )
if ( $min > 0 && $min <= 100 ) {
$this->min = (int) $min;
return true;
throw new InvalidArgumentException( 'The min length should be from 1 to 100' );
* @param int $max
protected function setMax ( $max )
if ( $max > 0 && $max <= 100 ) {
$this->max = (int) $max;
throw new InvalidArgumentException( 'The max length should be from 1 to 100' );
* @return int
public function getLength ()
if ( $this->min <= $this->max ) {
return mt_rand( $this->min, $this->max );
throw new InvalidArgumentException( 'The min length should be less than the max' );