1<?php 2 3namespace Hackzilla\PasswordGenerator\Model\Option; 4 5use InvalidArgumentException; 6 7class IntegerOption extends Option 8{ 9 private $minRange; 10 private $maxRange; 11 12 /** 13 * {@inheritdoc} 14 */ 15 public function __construct(array $settings = array()) 16 { 17 parent::__construct($settings); 18 19 $this->minRange = isset($settings['min']) ? $settings['min'] : ~PHP_INT_MAX; 20 $this->maxRange = isset($settings['max']) ? $settings['max'] : PHP_INT_MAX; 21 } 22 23 /** 24 * {@inheritdoc} 25 */ 26 public function setValue($value) 27 { 28 if (!is_integer($value)) { 29 throw new InvalidArgumentException('Integer required'); 30 } 31 32 if ($this->minRange > $value || $this->maxRange < $value) { 33 throw new InvalidArgumentException('Invalid Value'); 34 } 35 36 parent::setValue($value); 37 } 38 39 /** 40 * {@inheritdoc} 41 */ 42 public function getType() 43 { 44 return self::TYPE_INTEGER; 45 } 46} 47