@@ -27,7 +27,7 @@ |
||
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | - * @param $symbols |
|
| 30 | + * @param string $symbols |
|
| 31 | 31 | * |
| 32 | 32 | * @return bool |
| 33 | 33 | * |
@@ -20,10 +20,10 @@ discard block |
||
| 20 | 20 | * @param string $symbols |
| 21 | 21 | * @param int $priority |
| 22 | 22 | */ |
| 23 | - public function __construct ( $symbols, $priority = 100 ) |
|
| 23 | + public function __construct($symbols, $priority = 100) |
|
| 24 | 24 | { |
| 25 | - $this->setSymbols( $symbols ); |
|
| 26 | - $this->setPriority( $priority ); |
|
| 25 | + $this->setSymbols($symbols); |
|
| 26 | + $this->setPriority($priority); |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | /** |
@@ -33,13 +33,13 @@ discard block |
||
| 33 | 33 | * |
| 34 | 34 | * @throws InvalidArgumentException |
| 35 | 35 | */ |
| 36 | - protected function setSymbols ( $symbols ) |
|
| 36 | + protected function setSymbols($symbols) |
|
| 37 | 37 | { |
| 38 | - if ( is_string( $symbols ) && strlen( $symbols ) > 0 ) { |
|
| 38 | + if (is_string($symbols) && strlen($symbols) > 0) { |
|
| 39 | 39 | $this->symbols = $symbols; |
| 40 | 40 | return true; |
| 41 | 41 | } |
| 42 | - throw new InvalidArgumentException( 'Symbols must be a string, and contain at least one character' ); |
|
| 42 | + throw new InvalidArgumentException('Symbols must be a string, and contain at least one character'); |
|
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | /** |
@@ -49,19 +49,19 @@ discard block |
||
| 49 | 49 | * |
| 50 | 50 | * @throws InvalidArgumentException |
| 51 | 51 | */ |
| 52 | - protected function setPriority ( $priority ) |
|
| 52 | + protected function setPriority($priority) |
|
| 53 | 53 | { |
| 54 | - if ( is_numeric( $priority ) && $priority > 0 && $priority <= 100 ) { |
|
| 54 | + if (is_numeric($priority) && $priority > 0 && $priority <= 100) { |
|
| 55 | 55 | $this->priority = $priority; |
| 56 | 56 | return true; |
| 57 | 57 | } |
| 58 | - throw new InvalidArgumentException( 'Priority must be interger and in the range from 1 to 100' ); |
|
| 58 | + throw new InvalidArgumentException('Priority must be interger and in the range from 1 to 100'); |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | /** |
| 62 | 62 | * @return int |
| 63 | 63 | */ |
| 64 | - public function getPriority () |
|
| 64 | + public function getPriority() |
|
| 65 | 65 | { |
| 66 | 66 | return $this->priority; |
| 67 | 67 | } |
@@ -69,10 +69,10 @@ discard block |
||
| 69 | 69 | /** |
| 70 | 70 | * @return string |
| 71 | 71 | */ |
| 72 | - public function getRandomSymbol () |
|
| 72 | + public function getRandomSymbol() |
|
| 73 | 73 | { |
| 74 | - $length = strlen( $this->symbols ); |
|
| 75 | - $position = mt_rand( 0, $length - 1 ); |
|
| 76 | - return $this->symbols[ $position ]; |
|
| 74 | + $length = strlen($this->symbols); |
|
| 75 | + $position = mt_rand(0, $length - 1); |
|
| 76 | + return $this->symbols[$position]; |
|
| 77 | 77 | } |
| 78 | 78 | } |
@@ -20,18 +20,18 @@ discard block |
||
| 20 | 20 | * @param Length $length |
| 21 | 21 | * @param Symbols[] $symbols |
| 22 | 22 | */ |
| 23 | - public function __construct ( Length $length, array $symbols ) |
|
| 23 | + public function __construct(Length $length, array $symbols) |
|
| 24 | 24 | { |
| 25 | - $this->setLength( $length ); |
|
| 26 | - foreach ( $symbols as $item ) { |
|
| 27 | - $this->addSymbols( $item ); |
|
| 25 | + $this->setLength($length); |
|
| 26 | + foreach ($symbols as $item) { |
|
| 27 | + $this->addSymbols($item); |
|
| 28 | 28 | } |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | /** |
| 32 | 32 | * @param Length $length |
| 33 | 33 | */ |
| 34 | - protected function setLength ( Length $length ) |
|
| 34 | + protected function setLength(Length $length) |
|
| 35 | 35 | { |
| 36 | 36 | $this->length = $length; |
| 37 | 37 | } |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | /** |
| 40 | 40 | * @param Symbols $symbols |
| 41 | 41 | */ |
| 42 | - protected function addSymbols ( Symbols $symbols ) |
|
| 42 | + protected function addSymbols(Symbols $symbols) |
|
| 43 | 43 | { |
| 44 | 44 | $this->symbols[] = $symbols; |
| 45 | 45 | } |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | /** |
| 48 | 48 | * @return Symbols[] |
| 49 | 49 | */ |
| 50 | - protected function getSymbolsList () |
|
| 50 | + protected function getSymbolsList() |
|
| 51 | 51 | { |
| 52 | 52 | return $this->symbols; |
| 53 | 53 | } |
@@ -55,15 +55,15 @@ discard block |
||
| 55 | 55 | /** |
| 56 | 56 | * @return Symbols[] |
| 57 | 57 | */ |
| 58 | - public function createHitRateMap () |
|
| 58 | + public function createHitRateMap() |
|
| 59 | 59 | { |
| 60 | 60 | $hitRateMap = []; |
| 61 | 61 | $symbolsList = $this->getSymbolsList(); |
| 62 | - $totalCount = count( $symbolsList ); |
|
| 63 | - foreach ( $this->getSymbolsList() as $symbols ) { |
|
| 64 | - $hitRate = ( $symbols->getPriority() / $totalCount ) * 100; |
|
| 62 | + $totalCount = count($symbolsList); |
|
| 63 | + foreach ($this->getSymbolsList() as $symbols) { |
|
| 64 | + $hitRate = ($symbols->getPriority() / $totalCount) * 100; |
|
| 65 | 65 | $hitRate = $hitRate > 0 ? $hitRate : 1; |
| 66 | - for ( $counter = 0; $counter <= $hitRate; $counter++ ) { |
|
| 66 | + for ($counter = 0; $counter <= $hitRate; $counter++) { |
|
| 67 | 67 | $hitRateMap[] = $symbols; |
| 68 | 68 | } |
| 69 | 69 | } |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | /** |
| 74 | 74 | * @return int |
| 75 | 75 | */ |
| 76 | - public function createLength () |
|
| 76 | + public function createLength() |
|
| 77 | 77 | { |
| 78 | 78 | return $this->length->getLength(); |
| 79 | 79 | } |
@@ -20,10 +20,10 @@ discard block |
||
| 20 | 20 | * @param int $minimum |
| 21 | 21 | * @param int|null $maximum |
| 22 | 22 | */ |
| 23 | - public function __construct ( $minimum = 8, $maximum = null ) |
|
| 23 | + public function __construct($minimum = 8, $maximum = null) |
|
| 24 | 24 | { |
| 25 | - $this->setMinimum( $minimum ); |
|
| 26 | - $this->setMaximum( $maximum === null ? $minimum : $maximum ); |
|
| 25 | + $this->setMinimum($minimum); |
|
| 26 | + $this->setMaximum($maximum === null ? $minimum : $maximum); |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | /** |
@@ -33,13 +33,13 @@ discard block |
||
| 33 | 33 | * |
| 34 | 34 | * @throws InvalidArgumentException |
| 35 | 35 | */ |
| 36 | - protected function setMinimum ( $minimum ) |
|
| 36 | + protected function setMinimum($minimum) |
|
| 37 | 37 | { |
| 38 | - if ( $minimum > 0 && $minimum <= 100 ) { |
|
| 38 | + if ($minimum > 0 && $minimum <= 100) { |
|
| 39 | 39 | $this->minimum = (int) $minimum; |
| 40 | 40 | return true; |
| 41 | 41 | } |
| 42 | - throw new InvalidArgumentException( 'The minimum length should be from 1 to 100' ); |
|
| 42 | + throw new InvalidArgumentException('The minimum length should be from 1 to 100'); |
|
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | /** |
@@ -49,13 +49,13 @@ discard block |
||
| 49 | 49 | * |
| 50 | 50 | * @throws InvalidArgumentException |
| 51 | 51 | */ |
| 52 | - protected function setMaximum ( $maximum ) |
|
| 52 | + protected function setMaximum($maximum) |
|
| 53 | 53 | { |
| 54 | - if ( $maximum > 0 && $maximum <= 100 ) { |
|
| 54 | + if ($maximum > 0 && $maximum <= 100) { |
|
| 55 | 55 | $this->maximum = (int) $maximum; |
| 56 | 56 | return true; |
| 57 | 57 | } |
| 58 | - throw new InvalidArgumentException( 'The maximum length should be from 1 to 100' ); |
|
| 58 | + throw new InvalidArgumentException('The maximum length should be from 1 to 100'); |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | /** |
@@ -63,11 +63,11 @@ discard block |
||
| 63 | 63 | * |
| 64 | 64 | * @throws InvalidArgumentException |
| 65 | 65 | */ |
| 66 | - public function getLength () |
|
| 66 | + public function getLength() |
|
| 67 | 67 | { |
| 68 | - if ( $this->minimum <= $this->maximum ) { |
|
| 69 | - return mt_rand( $this->minimum, $this->maximum ); |
|
| 68 | + if ($this->minimum <= $this->maximum) { |
|
| 69 | + return mt_rand($this->minimum, $this->maximum); |
|
| 70 | 70 | } |
| 71 | - throw new InvalidArgumentException( 'The minimum length should be less than the maximum' ); |
|
| 71 | + throw new InvalidArgumentException('The minimum length should be less than the maximum'); |
|
| 72 | 72 | } |
| 73 | 73 | } |
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | /** |
| 13 | 13 | * @param Options $options |
| 14 | 14 | */ |
| 15 | - public function __construct ( Options $options ) |
|
| 15 | + public function __construct(Options $options) |
|
| 16 | 16 | { |
| 17 | 17 | $this->options = $options; |
| 18 | 18 | } |
@@ -20,16 +20,16 @@ discard block |
||
| 20 | 20 | /** |
| 21 | 21 | * @return string |
| 22 | 22 | */ |
| 23 | - public function generate () |
|
| 23 | + public function generate() |
|
| 24 | 24 | { |
| 25 | 25 | $password = ''; |
| 26 | 26 | $hitRates = $this->options->createHitRateMap(); |
| 27 | - $arrayLimit = count( $hitRates ) - 1; |
|
| 27 | + $arrayLimit = count($hitRates) - 1; |
|
| 28 | 28 | $length = $this->options->createLength(); |
| 29 | - for ( $counter = 0; $counter < $length; $counter++ ) { |
|
| 30 | - $position = mt_rand( 0, $arrayLimit ); |
|
| 31 | - shuffle( $hitRates ); |
|
| 32 | - $symbols = $hitRates[ $position ]; |
|
| 29 | + for ($counter = 0; $counter < $length; $counter++) { |
|
| 30 | + $position = mt_rand(0, $arrayLimit); |
|
| 31 | + shuffle($hitRates); |
|
| 32 | + $symbols = $hitRates[$position]; |
|
| 33 | 33 | $password .= $symbols->getRandomSymbol(); |
| 34 | 34 | } |
| 35 | 35 | return $password; |