Skip to content

Commit

Permalink
Keep the method exists checks too
Browse files Browse the repository at this point in the history
  • Loading branch information
GrahamCampbell committed Feb 14, 2016
1 parent f9d9b3e commit 2816de7
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/FactoryMuffin.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ protected function generate($model, array $attr = [])
$setter = 'set'.ucfirst(static::camelize($key));

// check if there is a setter and use it instead
if (is_callable([$model, $setter])) {
if (method_exists($model, $setter) && is_callable([$model, $setter])) {
$model->$setter($value);
} else {
$model->$key = $value;
Expand Down
2 changes: 1 addition & 1 deletion src/Generators/FactoryGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private function getId($model)
{
// Check to see if we can get an id via our defined methods
foreach (self::$methods as $method) {
if (is_callable([$model, $method])) {
if (method_exists($model, $method) && is_callable([$model, $method])) {
return $model->$method();
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Stores/ModelStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected function save($model)
{
$method = $this->methods['save'];

if (!is_callable([$model, $method])) {
if (!method_exists($model, $method) || !is_callable([$model, $method])) {
throw new SaveMethodNotFoundException(get_class($model), $method);
}

Expand All @@ -73,7 +73,7 @@ protected function delete($model)
{
$method = $this->methods['delete'];

if (!is_callable([$model, $method])) {
if (!method_exists($model, $method) || !is_callable([$model, $method])) {
throw new DeleteMethodNotFoundException(get_class($model), $method);
}

Expand Down
6 changes: 3 additions & 3 deletions src/Stores/RepositoryStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ protected function save($model)
{
$method = $this->methods['save'];

if (!is_callable([$this->storage, $method])) {
if (!method_exists($this->storage, $method) || !is_callable([$this->storage, $method])) {
throw new SaveMethodNotFoundException(get_class($this->storage), $method);
}

Expand All @@ -91,7 +91,7 @@ protected function flush()
{
$method = $this->methods['flush'];

if (!is_callable([$this->storage, $method])) {
if (!method_exists($this->storage, $method) || !is_callable([$this->storage, $method])) {
throw new FlushMethodNotFoundException(get_class($this->storage), $method);
}

Expand All @@ -113,7 +113,7 @@ protected function delete($model)
{
$method = $this->methods['delete'];

if (!is_callable([$this->storage, $method])) {
if (!method_exists($this->storage, $method) || !is_callable([$this->storage, $method])) {
throw new DeleteMethodNotFoundException(get_class($this->storage), $method);
}

Expand Down

0 comments on commit 2816de7

Please sign in to comment.