Skip to content

Commit

Permalink
Merge pull request #30 from mvorisek/callable_object_is_always_closure
Browse files Browse the repository at this point in the history
Simplify "ïs_callable && is_object" to "instanceof Closure"
  • Loading branch information
AllanJard authored Dec 7, 2023
2 parents 17e08d7 + 66c3467 commit ee74641
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 84 deletions.
6 changes: 3 additions & 3 deletions Database/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ public function where($key, $value = null, $op = '=', $bind = true)
{
if ($key === null) {
return $this;
} elseif (is_callable($key) && is_object($key)) { // is a closure
} elseif ($key instanceof \Closure) {
$this->_where_group(true, 'AND');
$key($this);
$this->_where_group(false, 'OR');
Expand Down Expand Up @@ -698,7 +698,7 @@ public function or_where($key, $value = null, $op = '=', $bind = true)
{
if ($key === null) {
return $this;
} elseif (is_callable($key) && is_object($key)) {
} elseif ($key instanceof \Closure) {
$this->_where_group(true, 'OR');
$key($this);
$this->_where_group(false, 'OR');
Expand Down Expand Up @@ -743,7 +743,7 @@ public function or_where($key, $value = null, $op = '=', $bind = true)
*/
public function where_group($inOut, $op = 'AND')
{
if (is_callable($inOut) && is_object($inOut)) {
if ($inOut instanceof \Closure) {
$this->_where_group(true, $op);
$inOut($this);
$this->_where_group(false, $op);
Expand Down
60 changes: 8 additions & 52 deletions Editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ class Editor extends Ext
* an Editor payload
* @param string $name The parameter name that the action should be read from.
*
* @return string `Editor::ACTION_READ`, `Editor::ACTION_CREATE`,
* `Editor::ACTION_EDIT` or `Editor::ACTION_DELETE` indicating the request
* type.
* @return static::ACTION_* `Editor::ACTION_READ`, `Editor::ACTION_CREATE`,
* `Editor::ACTION_EDIT` or `Editor::ACTION_DELETE` indicating the request
* type.
*/
public static function action($http, $name = 'action')
{
Expand Down Expand Up @@ -189,7 +189,7 @@ public function __construct($db = null, $table = null, $pkey = null)
/** @var array */
private $_out = array();

/** @var array */
/** @var array[] */
private $_events = array();

/** @var bool */
Expand All @@ -201,7 +201,7 @@ public function __construct($db = null, $table = null, $pkey = null)
/** @var string Log output path */
private $_debugLog = '';

/** @var callable */
/** @var array */
private $_validator = array();

/** @var bool Enable true / catch when processing */
Expand Down Expand Up @@ -910,7 +910,7 @@ public function where($key = null, $value = null, $op = '=')
return $this->_where;
}

if (is_callable($key) && is_object($key)) {
if ($key instanceof \Closure) {
$this->_where[] = $key;
} else {
$this->_where[] = array(
Expand Down Expand Up @@ -953,8 +953,6 @@ public function write($_writeVal = null)
* Process a request from the Editor client-side to get / set data.
*
* @param array $data Data to process
*
* @private
*/
private function _process($data)
{
Expand Down Expand Up @@ -1085,8 +1083,6 @@ private function _process($data)
* server-side processing requests from DataTables).
*
* @return array DataTables get information
*
* @private
*/
private function _get($id = null, $http = null)
{
Expand Down Expand Up @@ -1226,8 +1222,6 @@ private function _get($id = null, $http = null)

/**
* Insert a new row in the database.
*
* @private
*/
private function _insert($values)
{
Expand Down Expand Up @@ -1285,8 +1279,6 @@ private function _insert($values)
* @param string $id The DOM ID for the row that is being edited.
*
* @return array Row's data
*
* @private
*/
private function _update($id, $values)
{
Expand Down Expand Up @@ -1322,8 +1314,6 @@ private function _update($id, $values)

/**
* Delete one or more rows from the database.
*
* @private
*/
private function _remove($data)
{
Expand Down Expand Up @@ -1395,8 +1385,6 @@ private function _remove($data)
* File upload.
*
* @param array $data Upload data
*
* @private
*/
private function _upload($data)
{
Expand Down Expand Up @@ -1466,8 +1454,6 @@ private function _upload($data)
* @param number[] $ids Limit to a specific set of ids
*
* @return array File information
*
* @private
*/
private function _fileData($limitTable = null, $ids = null, $data = null)
{
Expand Down Expand Up @@ -1503,8 +1489,6 @@ private function _fileData($limitTable = null, $ids = null, $data = null)
* @param Field[] $fields Fields to get file information about
* @param string $limitTable Limit the data gathering to a single table
* only
*
* @private
*/
private function _fileDataFields(&$files, $fields, $limitTable, $idsIn = null, $data = null)
{
Expand Down Expand Up @@ -1563,8 +1547,6 @@ private function _fileDataFields(&$files, $fields, $limitTable, $idsIn = null, $

/**
* Run the file clean up.
*
* @private
*/
private function _fileClean()
{
Expand Down Expand Up @@ -1599,8 +1581,6 @@ private function _fileClean()
* @param array $http Parameters from HTTP request
*
* @return array Server-side processing information array
*
* @private
*/
private function _ssp_query($query, $http)
{
Expand Down Expand Up @@ -1648,7 +1628,7 @@ private function _ssp_query($query, $http)
* @param array $http HTTP variables (i.e. GET or POST)
* @param int $index Index in the DataTables' submitted data
*
* @returns string DB field name
* @return string DB field name
*
* @private Note that it is actually public for PHP 5.3 - thread 39810
*/
Expand All @@ -1674,8 +1654,6 @@ public function _ssp_field($http, $index)
*
* @param \DataTables\Database\Query $query Query instance to apply sorting to
* @param array $http HTTP variables (i.e. GET or POST)
*
* @private
*/
private function _ssp_sort($query, $http)
{
Expand Down Expand Up @@ -1921,8 +1899,6 @@ private function _constructSearchBuilderConditions($query, $data)
*
* @param \DataTables\Database\Query $query Query instance to apply the WHERE conditions to
* @param array $http HTTP variables (i.e. GET or POST)
*
* @private
*/
private function _ssp_filter($query, $http)
{
Expand Down Expand Up @@ -2052,8 +2028,6 @@ private function _ssp_filter($query, $http)
*
* @param \DataTables\Database\Query $query Query instance to apply the offset / limit to
* @param array $http HTTP variables (i.e. GET or POST)
*
* @private
*/
private function _ssp_limit($query, $http)
{
Expand All @@ -2072,8 +2046,6 @@ private function _ssp_limit($query, $http)
* Add local WHERE condition to query.
*
* @param \DataTables\Database\Query $query Query instance to apply the WHERE conditions to
*
* @private
*/
private function _get_where($query)
{
Expand All @@ -2097,8 +2069,6 @@ private function _get_where($query)
* @param string $type Matching name type
*
* @return Field Field instance
*
* @private
*/
private function _find_field($name, $type)
{
Expand Down Expand Up @@ -2126,8 +2096,6 @@ private function _find_field($name, $type)
*
* @return \DataTables\Database\Result Result from the query or null if no
* query performed.
*
* @private
*/
private function _insert_or_update($id, $values)
{
Expand Down Expand Up @@ -2214,8 +2182,6 @@ private function _insert_or_update($id, $values)
*
* @return \DataTables\Database\Result Result from the query or null if no query
* performed.
*
* @private
*/
private function _insert_or_update_table($table, $values, $where = null)
{
Expand Down Expand Up @@ -2304,8 +2270,6 @@ private function _insert_or_update_table($table, $values, $where = null)
* @param string $pkey Database column name to match the ids on for the
* delete condition. If not given the instance's base primary key is
* used.
*
* @private
*/
private function _remove_table($table, $ids, $pkey = null)
{
Expand Down Expand Up @@ -2376,8 +2340,6 @@ private function _remove_table($table, $ids, $pkey = null)
* Check the validity of the set options if we are doing a join, since
* there are some conditions for this state. Will throw an error if not
* valid.
*
* @private
*/
private function _prepJoin()
{
Expand Down Expand Up @@ -2417,9 +2379,7 @@ private function _prepJoin()
* @param string $name SQL field
* @param string $type Which part to get: `alias` (default) or `orig`.
*
* @returns string Alias
*
* @private
* @return string Alias
*/
private function _alias($name, $type = 'alias')
{
Expand Down Expand Up @@ -2451,8 +2411,6 @@ private function _alias($name, $type = 'alias')
* `column`
*
* @return string Part name
*
* @private
*/
private function _part($name, $type = 'table')
{
Expand Down Expand Up @@ -2486,8 +2444,6 @@ private function _part($name, $type = 'table')

/**
* Trigger an event.
*
* @private
*/
private function _trigger($eventName, &$arg1 = null, &$arg2 = null, &$arg3 = null, &$arg4 = null, &$arg5 = null)
{
Expand Down
14 changes: 6 additions & 8 deletions Editor/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public function __construct($dbField = null, $name = null)
/** @var mixed */
private $_setValue;

/** @var mixed */
/** @var array[] */
private $_validator = array();

/** @var Upload */
Expand Down Expand Up @@ -315,7 +315,7 @@ public function options($table = null, $value = null, $label = null, $condition
// Options class
$this->_optsFn = null;
$this->_opts = $table;
} elseif (is_callable($table) && is_object($table)) {
} elseif ($table instanceof \Closure) {
// Function
$this->_opts = null;
$this->_optsFn = $table;
Expand Down Expand Up @@ -360,7 +360,7 @@ public function searchPaneOptions($spInput = null)
// Options class
$this->_spoptsFn = null;
$this->_spopts = $spInput;
} elseif (is_callable($spInput) && is_object($spInput)) {
} elseif ($spInput instanceof \Closure) {
// Function
$this->_spopts = null;
$this->_spoptsFn = $spInput;
Expand All @@ -387,7 +387,7 @@ public function searchBuilderOptions($sbInput = null)
// Options class
$this->_sboptsFn = null;
$this->_sbopts = $sbInput;
} elseif (is_callable($sbInput) && is_object($sbInput)) {
} elseif ($spInput instanceof \Closure) {

Check failure on line 390 in Editor/Field.php

View workflow job for this annotation

GitHub Actions / Unit (latest, StaticAnalysis)

Undefined variable: $spInput
// Function
$this->_sbopts = null;
$this->_sboptsFn = $sbInput;
Expand Down Expand Up @@ -871,7 +871,7 @@ public function xssSafety($val)
* (get or set).
*
* @param mixed $val Value to be formatted
* @param mixed $data Full row data
* @param array $data Full row data
* @param callable $formatter Formatting function to be called
* @param array $opts Array of options to be passed to the formatter
*
Expand Down Expand Up @@ -918,7 +918,7 @@ private function _format($val, $data, $formatter, $opts)
*/
private function _getAssignedValue($val)
{
return is_callable($val) && is_object($val) ?
return $val instanceof \Closure ?
$val() :
$val;
}
Expand All @@ -932,8 +932,6 @@ private function _getAssignedValue($val)
* @param array $data Data source array to read from
*
* @return bool `true` if present, `false` otherwise
*
* @private
*/
private function _inData($name, $data)
{
Expand Down
Loading

0 comments on commit ee74641

Please sign in to comment.