From 2816de7a52055300f85a5530715c1a325c16b7be Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sun, 14 Feb 2016 12:04:21 +0000 Subject: [PATCH] Keep the method exists checks too --- src/FactoryMuffin.php | 2 +- src/Generators/FactoryGenerator.php | 2 +- src/Stores/ModelStore.php | 4 ++-- src/Stores/RepositoryStore.php | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/FactoryMuffin.php b/src/FactoryMuffin.php index c8d44ca..6be1663 100644 --- a/src/FactoryMuffin.php +++ b/src/FactoryMuffin.php @@ -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; diff --git a/src/Generators/FactoryGenerator.php b/src/Generators/FactoryGenerator.php index 349823d..9f5f703 100644 --- a/src/Generators/FactoryGenerator.php +++ b/src/Generators/FactoryGenerator.php @@ -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(); } } diff --git a/src/Stores/ModelStore.php b/src/Stores/ModelStore.php index 9707769..140a496 100644 --- a/src/Stores/ModelStore.php +++ b/src/Stores/ModelStore.php @@ -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); } @@ -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); } diff --git a/src/Stores/RepositoryStore.php b/src/Stores/RepositoryStore.php index 7f92641..b5adde9 100644 --- a/src/Stores/RepositoryStore.php +++ b/src/Stores/RepositoryStore.php @@ -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); } @@ -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); } @@ -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); }