Skip to content

Commit

Permalink
Merge pull request #14 from scottrobertson/fix-undefined-id and fixed…
Browse files Browse the repository at this point in the history
… conflicts
  • Loading branch information
Zizaco committed Apr 25, 2014
2 parents a5e2480 + 6fca6b0 commit 19833dd
Showing 1 changed file with 33 additions and 25 deletions.
58 changes: 33 additions & 25 deletions src/Zizaco/FactoryMuff/FactoryMuff.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php namespace Zizaco\FactoryMuff;

/**
* Creates models with randomic attributes
* Creates models with random attributes
*
* @package Zizaco\FactoryMuff
* @author Zizaco <[email protected]>
Expand Down Expand Up @@ -29,7 +29,7 @@ class FactoryMuff
*/
private $mail_domains = array(
'example.com', 'dontexist.com',
'mockdoman.com', 'emailprovider.com',
'mockdomain.com', 'emailprovider.com',
'exampledomain.org'
);

Expand Down Expand Up @@ -104,7 +104,7 @@ public function instance( $model, $attr = array() )

/**
* Returns an array of mock attributes
* for the especified model
* for the specified model
*
* @param string $model Model class name.
* @param array $attr Model attributes.
Expand Down Expand Up @@ -237,44 +237,52 @@ private function generateAttr( $kind, $model = NULL )
}
else {

if ( is_string($kind) && substr( $kind, 0, 8 ) === 'integer|' ) {
$numgen = substr( $kind, 8 );

for ( $i=0; $i<$numgen; $i++ ) {
$result .= mt_rand(0,9);
}
}

// Overwise interpret the kind and 'generate' some
// crap.
switch ( $kind ) {

// Pick a word and append a domain
case 'email':
shuffle( $this->mail_domains );
// Pick a word and append a domain
case 'email':
shuffle( $this->mail_domains );

$result = $this->getWord().'@'.$this->mail_domains[0];
break;
$result = $this->getWord().'@'.$this->mail_domains[0];
break;

// Pick some words
case 'text':
for ( $i=0; $i < ( ((int)date( 'U' )+rand(0,5)) % 8 ) + 2; $i++ ) {
$result .= $this->getWord()." ";
}
// Pick some words
case 'text':
for ( $i=0; $i < ( ((int)date( 'U' )+rand(0,5)) % 8 ) + 2; $i++ ) {
$result .= $this->getWord()." ";
}

$result = trim( $result );
break;
$result = trim( $result );
break;

// Pick a single word then
case 'string':
$result = $this->getWord();
// Pick a single word
case 'string':
$result = $this->getWord();

if (rand(0,1))
$result = ucfirst($result);
if (rand(0,1))
$result = ucfirst($result);

break;
break;

/**
* ITS HERE: The point where you can extend
* this class, to support new datatypes
*/

// Returns the original string or number
default:
$result = $kind;
break;
// Returns the original string or number
default:
$result = $kind;
break;
}

}
Expand Down

0 comments on commit 19833dd

Please sign in to comment.