Skip to content

Commit

Permalink
Merge pull request #214 from envms/fix/invalid-method-calls
Browse files Browse the repository at this point in the history
Add fatal user error if invalid method is called
  • Loading branch information
cbornhoft committed Oct 13, 2017
2 parents b172d58 + 7d70c3a commit 2bb54b2
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions FluentPDO/CommonQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
*/
abstract class CommonQuery extends BaseQuery
{
/** @var array - methods which are allowed to be call by the magic method __call() */
private $validMethods = ['from', 'fullJoin', 'group', 'groupBy', 'having', 'innerJoin', 'join', 'leftJoin',
'limit', 'offset', 'order', 'orderBy', 'outerJoin', 'rightJoin', 'select'];

/** @var array - Query tables (also include table from clause FROM) */
protected $joins = array();
Expand Down Expand Up @@ -102,13 +105,17 @@ public function where($condition, $parameters = array()) {
}

/**
* @param $clause
* @param array $parameters - first is $statement followed by $parameters
* @param string $name
* @param array $parameters - first is $statement followed by $parameters
*
* @return $this|\SelectQuery
* @return $this|SelectQuery
*/
public function __call($clause, $parameters = array()) {
$clause = FluentUtils::toUpperWords($clause);
public function __call($name, $parameters = array()) {
if (!in_array($name, $this->validMethods)) {
trigger_error("Call to invalid method " . get_class($this) . "::{$name}()", E_USER_ERROR);
}

$clause = FluentUtils::toUpperWords($name);

if ($clause == 'GROUP') {
$clause = 'GROUP BY';
Expand Down

0 comments on commit 2bb54b2

Please sign in to comment.