Skip to content

Commit

Permalink
Merge pull request #25 from robcaw/master
Browse files Browse the repository at this point in the history
Generator created at point of calling generate()
  • Loading branch information
rcwsr committed Apr 22, 2015
2 parents 1757768 + c6e4e6f commit 3a9ab1a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@

class SecureStringGeneratorSpec extends ObjectBehavior
{

/**
* @var Factory
*/
private $factory;

function it_is_initializable()
{
$this->shouldHaveType('Vivait\StringGeneratorBundle\Generator\SecureStringGenerator');
Expand All @@ -37,11 +31,6 @@ function let(Factory $factory, Generator $low, Generator $medium)
$this->setOptions($defaults);
}

function it_chooses_medium_strength_gen_by_default(Generator $medium)
{
$this->getGenerator()->shouldReturn($medium);
}

function it_chooses_a_specified_strength_gen(Generator $medium, Generator $low)
{
$this->getGenerator('medium')->shouldReturn($medium);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,18 @@ class SecureStringGenerator implements ConfigurableGeneratorInterface
{

/**
* @var
* @var int
*/
private $length = 32;

/**
* @var Generator
* @var string
*/
private $generator;

private $chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';

/**
* @var string
*/
private $strength = 'medium';

/**
Expand All @@ -44,10 +45,10 @@ public function __construct(Factory $factory)
*/
public function generate()
{
return $this->generator->generateString($this->length, $this->chars);
return $this->getGenerator($this->strength)->generateString($this->length, $this->chars);
}

public function getGenerator($strength = 'medium')
public function getGenerator($strength)
{
switch ($strength) {
case 'low':
Expand All @@ -63,7 +64,7 @@ public function getGenerator($strength = 'medium')

public function setOptions(array $options)
{
$this->generator = $this->getGenerator($options['strength']);
$this->strength = $options['strength'];
$this->length = $options['length'];
$this->chars = $options['chars'];
}
Expand Down

0 comments on commit 3a9ab1a

Please sign in to comment.