Skip to content

Commit

Permalink
Merge pull request #54 from Zizaco/psr2-fixes
Browse files Browse the repository at this point in the history
PSR-2 Standards
  • Loading branch information
scottrobertson committed Jul 6, 2014
2 parents 7b9cf07 + d727538 commit ff6fb6f
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 60 deletions.
12 changes: 6 additions & 6 deletions src/Zizaco/FactoryMuff/Facade/FactoryMuff.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ private static function fmInstance()
*
* @return mixed Returns the model instance.
*/
public static function create( $model, $attr = array() )
public static function create($model, $attr = array())
{
return static::fmInstance()->create( $model, $attr );
return static::fmInstance()->create($model, $attr);
}

/**
Expand All @@ -63,9 +63,9 @@ public static function create( $model, $attr = array() )
*
* @return mixed Returns the model instance.
*/
public static function instance( $model, $attr = array() )
public static function instance($model, $attr = array())
{
return static::fmInstance()->instance( $model, $attr );
return static::fmInstance()->instance($model, $attr);
}

/**
Expand All @@ -80,8 +80,8 @@ public static function instance( $model, $attr = array() )
*
* @return array Returns an attributes array.
*/
public static function attributesFor( $model, $attr = array() )
public static function attributesFor($model, $attr = array())
{
return static::fmInstance()->attributesFor( $model, $attr );
return static::fmInstance()->attributesFor($model, $attr);
}
}
2 changes: 1 addition & 1 deletion src/Zizaco/FactoryMuff/FactoryMuff.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ private function getFactoryAttrs($model)
*
* @return mixed String or an instance of related model.
*/
public function generateAttr($kind, $model = NULL)
public function generateAttr($kind, $model = null)
{
$kind = Kind::detect($kind, $model);

Expand Down
10 changes: 5 additions & 5 deletions src/Zizaco/FactoryMuff/Kind/Closure.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

class Closure extends Kind
{
public function generate()
{
$kind = $this->kind;
public function generate()
{
$kind = $this->kind;

return $kind();
}
return $kind();
}
}
66 changes: 33 additions & 33 deletions src/Zizaco/FactoryMuff/Kind/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,40 @@

class Factory extends Kind
{
private $methods = array(
'getKey',
'pk',
);

private $properties = array(
'id',
'_id'
);

public function generate()
{
$factory = new \Zizaco\FactoryMuff\FactoryMuff;
$model = $factory->create(substr($this->kind, 8));
return $this->getId($model);
}

private function getId($model)
{
// Check to see if we can get an ID via our defined methods
foreach ($this->methods as $method) {
if (method_exists($model, $method)) {
return $model->$method();
}
private $methods = array(
'getKey',
'pk',
);

private $properties = array(
'id',
'_id'
);

public function generate()
{
$factory = new \Zizaco\FactoryMuff\FactoryMuff;
$model = $factory->create(substr($this->kind, 8));
return $this->getId($model);
}

// Check to see if we can get an ID via our defined methods
foreach ($this->properties as $property) {
if (isset($model->$property)) {
return $model->$property;
}
private function getId($model)
{
// Check to see if we can get an ID via our defined methods
foreach ($this->methods as $method) {
if (method_exists($model, $method)) {
return $model->$method();
}
}

// Check to see if we can get an ID via our defined methods
foreach ($this->properties as $property) {
if (isset($model->$property)) {
return $model->$property;
}
}

// We cannot find an ID
return null;
}

// We cannot find an ID
return null;
}
}
10 changes: 5 additions & 5 deletions src/Zizaco/FactoryMuff/Kind/Name.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

class Name extends Kind
{
public function generate()
{
$gender = $this->getOption(0, null);
public function generate()
{
$gender = $this->getOption(0, null);

return $this->faker->name($gender);
}
return $this->faker->name($gender);
}
}
16 changes: 8 additions & 8 deletions src/Zizaco/FactoryMuff/Kind/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

class Text extends Kind
{
public function generate()
{
$length = $this->getOption(0, 100);
public function generate()
{
$length = $this->getOption(0, 100);

// Generate a large amount of text. The reason for this is that
// faker uses a maximum length, and not an exact length. We then substr this
$text = $this->faker->text($length * 3);
// Generate a large amount of text. The reason for this is that
// faker uses a maximum length, and not an exact length. We then substr this
$text = $this->faker->text($length * 3);

return substr($text, 0, $length);
}
return substr($text, 0, $length);
}
}
4 changes: 3 additions & 1 deletion src/Zizaco/FactoryMuff/NoDefinedFactoryException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace Zizaco\FactoryMuff;
<?php

namespace Zizaco\FactoryMuff;

class NoDefinedFactoryException extends \Exception
{
Expand Down
4 changes: 3 additions & 1 deletion src/Zizaco/FactoryMuff/SaveException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace Zizaco\FactoryMuff;
<?php

namespace Zizaco\FactoryMuff;

class SaveException extends \Exception
{
Expand Down

0 comments on commit ff6fb6f

Please sign in to comment.