Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fatal user error if invalid method is called #214

Merged
merged 1 commit into from
Oct 13, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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