Skip to content

Commit 8ffe2e4

Browse files
committed
Modifier doesn't throw Exception anymore
1 parent b85d72a commit 8ffe2e4

File tree

2 files changed

+32
-10
lines changed

2 files changed

+32
-10
lines changed

src/Service/QueryModifier/Easy/Modifier.php

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

tests/Service/QueryModifier/Easy/ModifierTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use Propel\Generator\Util\QuickBuilder;
1313
use Propel\Runtime\ActiveQuery\Criteria;
1414
use Propel\Runtime\ActiveQuery\ModelCriteria;
15-
use Propel\Runtime\Exception\BadMethodCallException;
1615
use Propel\Runtime\Propel;
1716

1817
class ModifierTest extends TestCase
@@ -62,8 +61,8 @@ public function testFilterByFailure()
6261
{
6362
$query = $this->mockQueryInstance();
6463
$modifier = new Modifier($query);
65-
$this->expectException(BadMethodCallException::class);
6664
$modifier->filterBy('Foo');
65+
$this->assertTrue(in_array('filterByFoo', $modifier->getFailures()));
6766
}
6867

6968
/**

0 commit comments

Comments
 (0)