for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace iiifx\PasswordGenerator;
use iiifx\PasswordGenerator\Method\MethodInterface;
use InvalidArgumentException;
class Symbols
{
/**
* @var string
*/
protected $symbols;
* @var int
protected $priority;
* @param string $symbols
* @param int $priority
public function __construct ( $symbols, $priority = 100 )
$this->setSymbols( $symbols );
$this->setPriority( $priority );
}
* @param $symbols
*
* @return bool
* @throws InvalidArgumentException
protected function setSymbols ( $symbols )
if ( is_string( $symbols ) && strlen( $symbols ) > 0 ) {
$this->symbols = $symbols;
return true;
throw new InvalidArgumentException( 'Symbols must be a string, and contain at least one character' );
protected function setPriority ( $priority )
if ( is_int( $priority ) && $priority > 0 && $priority <= 100 ) {
$this->priority = $priority;
throw new InvalidArgumentException( 'Priority must be interger and in the range from 1 to 100' );
* @return int
public function getPriority ()
return $this->priority;
* @param MethodInterface $method
* @return string
public function getRandomSymbol ( MethodInterface $method = null )
$length = strlen( $this->symbols );
if ( $method ) {
$position = $method->getRandomInt( $length - 1 );
} else {
$position = mt_rand( 0, $length - 1 );
return $this->symbols[ $position ];