@@ -21,6 +21,10 @@ class Modifier
2121 * @var UseQueryFromDotNotation
2222 */
2323 protected $ dotUseQuery ;
24+ /**
25+ * @var array List of failed filters
26+ */
27+ protected $ failures = [];
2428 /**
2529 * @var ModelCriteria
2630 */
@@ -45,12 +49,27 @@ public function filterBy(string $dotProperty, $value = null, $operator = null):
4549
4650 $ property = $ this ->before ($ dotProperty );
4751 $ method = $ this ->buildMethodName (__FUNCTION__ , $ property );
48- $ this ->query = call_user_func ([$ this ->query , $ method ], $ value , $ operator );
52+ if ($ this ->methodExists ($ method )) {
53+ $ this ->query = $ this ->query ->{$ method }($ value , $ operator );
54+ } else {
55+ $ this ->failures [] = $ method ;
56+ }
4957 $ this ->after ();
5058
5159 return $ this ->query ;
5260 }
5361
62+ /**
63+ * Determine if method is callable in Query class
64+ *
65+ * @param $method
66+ * @return bool
67+ */
68+ public function methodExists ($ method )
69+ {
70+ return method_exists ($ this ->query , $ method );
71+ }
72+
5473 /**
5574 * @param string $dotProperty
5675 * @param $order
@@ -67,6 +86,16 @@ public function orderBy(string $dotProperty, $order = Criteria::ASC): ModelCrite
6786 return $ this ->query ;
6887 }
6988
89+ /**
90+ * List of failed method call
91+ *
92+ * @return array
93+ */
94+ public function getFailures (): array
95+ {
96+ return $ this ->failures ;
97+ }
98+
7099 /**
71100 * @throws UseQueryFromDotNotationException
72101 */
@@ -98,12 +127,6 @@ private function before(string $dotProperty)
98127 */
99128 private function buildMethodName (string $ action , string $ property ): string
100129 {
101- # Determine if method is callable in Query class
102- $ method = $ action . $ property ;
103- if (!method_exists ($ this ->query , $ method )) {
104- throw new BadMethodCallException (sprintf ('Call to undefined method: %s. ' , $ method ));
105- }
106-
107- return $ method ;
130+ return $ action . $ property ;
108131 }
109132}
0 commit comments