diff --git a/src/Service/QueryModifier/Easy/Modifier.php b/src/Service/QueryModifier/Easy/Modifier.php index e6954f5..4e113c5 100644 --- a/src/Service/QueryModifier/Easy/Modifier.php +++ b/src/Service/QueryModifier/Easy/Modifier.php @@ -21,6 +21,10 @@ class Modifier * @var UseQueryFromDotNotation */ protected $dotUseQuery; + /** + * @var array List of failed filters + */ + protected $failures = []; /** * @var ModelCriteria */ @@ -45,12 +49,27 @@ public function filterBy(string $dotProperty, $value = null, $operator = null): $property = $this->before($dotProperty); $method = $this->buildMethodName(__FUNCTION__, $property); - $this->query = call_user_func([$this->query, $method], $value, $operator); + if ($this->methodExists($method)) { + $this->query = $this->query->{$method}($value, $operator); + } else { + $this->failures[] = $method; + } $this->after(); return $this->query; } + /** + * Determine if method is callable in Query class + * + * @param $method + * @return bool + */ + public function methodExists($method) + { + return method_exists($this->query, $method); + } + /** * @param string $dotProperty * @param $order @@ -67,6 +86,16 @@ public function orderBy(string $dotProperty, $order = Criteria::ASC): ModelCrite return $this->query; } + /** + * List of failed method call + * + * @return array + */ + public function getFailures(): array + { + return $this->failures; + } + /** * @throws UseQueryFromDotNotationException */ @@ -98,12 +127,6 @@ private function before(string $dotProperty) */ private function buildMethodName(string $action, string $property): string { - # Determine if method is callable in Query class - $method = $action . $property; - if (!method_exists($this->query, $method)) { - throw new BadMethodCallException(sprintf('Call to undefined method: %s.', $method)); - } - - return $method; + return $action . $property; } } diff --git a/tests/Service/QueryModifier/Easy/ModifierTest.php b/tests/Service/QueryModifier/Easy/ModifierTest.php index a2faed2..aaa7e09 100644 --- a/tests/Service/QueryModifier/Easy/ModifierTest.php +++ b/tests/Service/QueryModifier/Easy/ModifierTest.php @@ -12,7 +12,6 @@ use Propel\Generator\Util\QuickBuilder; use Propel\Runtime\ActiveQuery\Criteria; use Propel\Runtime\ActiveQuery\ModelCriteria; -use Propel\Runtime\Exception\BadMethodCallException; use Propel\Runtime\Propel; class ModifierTest extends TestCase @@ -62,8 +61,8 @@ public function testFilterByFailure() { $query = $this->mockQueryInstance(); $modifier = new Modifier($query); - $this->expectException(BadMethodCallException::class); $modifier->filterBy('Foo'); + $this->assertTrue(in_array('filterByFoo', $modifier->getFailures())); } /**