diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index f7ceeac..77408fa 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -4,7 +4,7 @@ ->in(array(__DIR__)) ->ignoreDotFiles(false) ->ignoreVCS(true) - ->exclude(array('vendor')); + ->exclude(array('vendor', 'HtmLawed')); $config = new PhpCsFixer\Config(); @@ -66,6 +66,7 @@ 'single_line_comment_style' => false, 'phpdoc_annotation_without_dot' => false, 'declare_strict_types' => false, + 'static_lambda' => false, // needs PHP 5.4+ 'strict_comparison' => false, 'strict_param' => false, // TODO 'final_internal_class' => false, diff --git a/Database.php b/Database.php index 3079374..ed5787b 100644 --- a/Database.php +++ b/Database.php @@ -109,7 +109,7 @@ public function any($table, $where = null) * * Use with {@see Database->transaction()} and {@see Database->rollback()}. * - * @return self + * @return $this */ public function commit() { @@ -146,8 +146,7 @@ public function count($table, $field = 'id', $where = null) * * @param bool $set Debug mode state. If not given, then used as a getter. * - * @return bool|self Debug mode state if no parameter is given, or - * self if used as a setter. + * @return ($set is null ? bool : $this) Debug mode state if no parameter is given. */ public function debug($set = null) { @@ -312,7 +311,7 @@ public function resource() * * Use with {@see Database->transaction()} and {@see Database->commit()}. * - * @return self + * @return $this */ public function rollback() { @@ -410,7 +409,7 @@ public function sql($sql) * * Use with {@see Database->commit()} and {@see Database->rollback()}. * - * @return self + * @return $this */ public function transaction() { @@ -457,8 +456,8 @@ public function update($table, $set = null, $where = null) /** * Get debug query information. * - * @return Database Information about the queries used. When this method is - * called it will reset the query cache. + * @return $this Information about the queries used. When this method is + * called it will reset the query cache. * * @internal */ diff --git a/Database/Driver/PostgresQuery.php b/Database/Driver/PostgresQuery.php index 15964b7..85d835d 100644 --- a/Database/Driver/PostgresQuery.php +++ b/Database/Driver/PostgresQuery.php @@ -93,12 +93,12 @@ protected function _prepare($sql) // Get the pkey field name $pkRes = $resource->prepare( - "SELECT a.attname + 'SELECT a.attname FROM pg_index i JOIN pg_attribute a ON a.attrelid = i.indrelid AND a.attnum = ANY(i.indkey) WHERE i.indrelid = (:tableName)::regclass - AND i.indisprimary" + AND i.indisprimary' ); $pkRes->bindValue('tableName', $table[0]); $pkRes->execute(); diff --git a/Database/Query.php b/Database/Query.php index 40355fd..63bf004 100644 --- a/Database/Query.php +++ b/Database/Query.php @@ -196,7 +196,7 @@ public static function commit($dbh) * @param string $host Host name * @param string $db Database name * - * @return Query + * @return \PDO */ public static function connect($user, $pass = '', $host = '', $port = '', $db = '', $dsn = '') { @@ -262,7 +262,7 @@ public static function dsnPostfix($dsn) * @param mixed $type Data type. See the PHP PDO documentation: * http://php.net/manual/en/pdo.constants.php * - * @return Query + * @return $this */ public function bind($name, $value, $type = null) { @@ -291,7 +291,7 @@ public function database() * * @param bool $dis Optional * - * @return Query + * @return $this */ public function distinct($dis) { @@ -334,7 +334,7 @@ public function exec($sql = null) * @param string|string[] ...$get Fields to get - can be specified as * individual fields or an array of fields. * - * @return self + * @return $this */ public function get($get) { @@ -374,7 +374,7 @@ public function get($get) * @param string $condition JOIN condition * @param string $type JOIN type * - * @return self + * @return $this */ public function join($table, $condition, $type = '', $bind = true) { @@ -402,6 +402,8 @@ public function join($table, $condition, $type = '', $bind = true) /** * Add a left join, with common logic for handling binding or not. + * + * @return $this */ public function left_join($joins) { @@ -439,7 +441,7 @@ public function left_join($joins) * * @param int $lim The number of records to limit the result to. * - * @return self + * @return $this */ public function limit($lim) { @@ -453,7 +455,7 @@ public function limit($lim) * * @param string $group_by The field of which the values are to be grouped * - * @return self + * @return $this */ public function group_by($group_by) { @@ -468,7 +470,7 @@ public function group_by($group_by) * * @param string[] $pkey Primary keys * - * @return Query|string[] + * @return ($pkey is null ? string[] : $this) */ public function pkey($pkey = null) { @@ -488,7 +490,7 @@ public function pkey($pkey = null) * individual names, an array of names, a string of comma separated * names or any combination of those. * - * @return self + * @return $this */ public function table($table) { @@ -518,7 +520,7 @@ public function table($table) * * @param int $off The number of records to offset the result by. * - * @return self + * @return $this */ public function offset($off) { @@ -534,7 +536,7 @@ public function offset($off) * be specified as individual names, an array of names, a string of comma * separated names or any combination of those. * - * @return self + * @return $this */ public function order($order) { @@ -577,7 +579,7 @@ public function order($order) * name and this is the field's value. * @param bool $bind Should the value be bound or not * - * @return self + * @return $this */ public function set($set, $val = null, $bind = true) { @@ -618,7 +620,7 @@ public function set($set, $val = null, $bind = true) * @param string $op Condition operator: <, >, = etc * @param bool $bind Escape the value (true, default) or not (false). * - * @return self + * @return $this * * @example * The following will produce @@ -669,7 +671,7 @@ public function where($key, $value = null, $op = '=', $bind = true) * @param string $op Condition operator: <, >, = etc * @param bool $bind Escape the value (true, default) or not (false). * - * @return self + * @return $this */ public function and_where($key, $value = null, $op = '=', $bind = true) { @@ -692,7 +694,7 @@ public function and_where($key, $value = null, $op = '=', $bind = true) * @param string $op Condition operator: <, >, = etc * @param bool $bind Escape the value (true, default) or not (false). * - * @return self + * @return $this */ public function or_where($key, $value = null, $op = '=', $bind = true) { @@ -731,7 +733,7 @@ public function or_where($key, $value = null, $op = '=', $bind = true) * @param string $op Conditional operator to use to join to the * preceding condition. Default `AND`. * - * @return self + * @return $this * * @example * ```php @@ -766,7 +768,7 @@ public function where_group($inOut, $op = 'AND') * @param string $operator Conditional operator to use to join to the * preceding condition. Default `AND`. * - * @return self + * @return $this */ public function where_in($field, $arr, $operator = 'AND') { @@ -1008,7 +1010,7 @@ protected function _build_where() if ($this->_where[$i - 1]['group'] === '(') { $condition .= '1=1'; } - // else nothing + // else nothing reindent once https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/7497 is fixed } elseif ($this->_where[$i - 1]['group'] === '(') { // Nothing } else { diff --git a/Editor.php b/Editor.php index db8198a..b8c8b52 100644 --- a/Editor.php +++ b/Editor.php @@ -224,7 +224,7 @@ public function __construct($db = null, $table = null, $pkey = null) * * @param string $_ Value to set. If not given, then used as a getter. * - * @return string|self Value, or self if used as a setter. + * @return ($_ is null ? string : $this) Value. */ public function actionName($_ = null) { @@ -251,8 +251,8 @@ public function data() * @param Database $_ DataTable's Database class instance to use for database * connectivity. If not given, then used as a getter. * - * @return Database|self The Database connection instance if no parameter - * is given, or self if used as a setter. + * @return ($_ is null ? Database : $this) The Database connection instance if no parameter + * is given. */ public function db($_ = null) { @@ -276,8 +276,7 @@ public function db($_ = null) * to the debug information sent back to the client. * @param string $path Set an output path to log debug information * - * @return bool|self Debug mode state if no parameter is given, or - * self if used as a setter or when adding a debug message. + * @return ($_ is null ? bool : $this) Debug mode state if no parameter is given. */ public function debug($_ = null, $path = null) { @@ -300,7 +299,7 @@ public function debug($_ = null, $path = null) * The list of fields designates which columns in the table that Editor will work * with (both get and set). * - * @param Field|string $_,... This parameter effects the return value of the + * @param Field|string ...$_ This parameter effects the return value of the * function: * * * `null` - Get an array of all fields assigned to the instance @@ -311,8 +310,7 @@ public function debug($_ = null, $path = null) * * `array` - An array of {@see Field} instances to add to the list * of fields. * - * @return Field|Field[]|Editor The selected field, an array of fields, or - * the Editor instance for chaining, depending on the input parameter. + * @return ($_ is null ? ($_ is string ? Field : Field[]) : $this) The selected field, an array of fields, depending on the input parameter. * * @see {@see Field} for field documentation. */ @@ -342,11 +340,11 @@ public function field($_ = null) * * An alias of {@see field}, for convenience. * - * @param Field|Field[] $_,... Instances of the {@see Field} class, given as a single + * @param Field|Field[] ...$_ Instances of the {@see Field} class, given as a single * instance of {@see Field}, an array of {@see Field} instances, or multiple * {@see Field} instance parameters for the function. * - * @return Field[]|self Array of fields, or self if used as a setter. + * @return ($_ is null ? Field[] : $this) Array of fields. * * @see {@see Field} for field documentation. */ @@ -372,8 +370,7 @@ public function fields($_ = null) * * @param string $_ Primary key's name. If not given, then used as a getter. * - * @return string|self Primary key value if no parameter is given, or - * self if used as a setter. + * @return ($_ is null ? string : $this) Primary key value if no parameter is given. */ public function idPrefix($_ = null) { @@ -401,11 +398,11 @@ public function inData() * (i.e. the one that the {@see Editor->table()} and {@see Editor->fields} * methods refer to in this class instance). * - * @param Join $_,... Instances of the {@see Join} class, given as a + * @param Join ...$_ Instances of the {@see Join} class, given as a * single instance of {@see Join}, an array of {@see Join} instances, * or multiple {@see Join} instance parameters for the function. * - * @return Join[]|self Array of joins, or self if used as a setter. + * @return ($_ is null ? Join[] : $this) Array of joins. */ public function join($_ = null) { @@ -428,8 +425,8 @@ public function join($_ = null) * (false). * @param int $options JSON encode option https://www.php.net/manual/en/json.constants.php * - * @return string|self self if printing the JSON, or JSON representation of - * the processed data if false is given as the first parameter. + * @return ($print is false ? string : $this) JSON representation of the processed data if + * false is given as the first parameter. */ public function json($print = true, $options = 0) { @@ -458,7 +455,7 @@ public function json($print = true, $options = 0) * @param string $callback The callback function name to use. If not given * or `null`, then `$_GET['callback']` is used (the jQuery default). * - * @return self Self for chaining. + * @return $this */ public function jsonp($callback = null) { @@ -507,7 +504,7 @@ public function jsonp($callback = null) * @param string $operator Join condition (`=`, '<`, etc) * @param string $field2 Field from the child table to use as the join link * - * @return self Self for chaining. + * @return $this * * @example * Simple join: @@ -553,8 +550,7 @@ public function leftJoin($table, $field1, $operator = null, $field2 = null) * * @param bool $_ Value to set. If not given, then used as a getter. * - * @return bool|self Value if no parameter is given, or - * self if used as a setter. + * @return ($_ is null ? bool : $this) Value if no parameter is given. */ public function leftJoinRemove($_ = null) { @@ -569,7 +565,7 @@ public function leftJoinRemove($_ = null) * @param callable $callback Callback function to execute when the event * occurs * - * @return self Self for chaining. + * @return $this */ public function on($name, $callback) { @@ -592,8 +588,7 @@ public function on($name, $callback) * getter. An array of column names can be given to allow composite keys to * be used. * - * @return string[]|self Primary key value if no parameter is given, or - * self if used as a setter. + * @return ($_ is null ? string[] : $this) Primary key value if no parameter is given. */ public function pkey($_ = null) { @@ -689,7 +684,7 @@ public function pkeyToArray($value, $flat = false, $pkey = null) * @param array $data Typically $_POST or $_GET as required by what is sent * by Editor * - * @return self + * @return $this */ public function process($data) { @@ -737,10 +732,10 @@ public function process($data) * a useful distinction to allow a read from a VIEW (which could make use of a * complex SELECT) while writing to a different table. * - * @param string|array $_,... Read table names given as a single string, an array + * @param string|array ...$_ Read table names given as a single string, an array * of strings or multiple string parameters for the function. * - * @return string[]|self Array of read tables names, or self if used as a setter. + * @return ($_ is null ? string[] : $this) Array of read tables names. */ public function readTable($_ = null) { @@ -762,10 +757,10 @@ public function readTable($_ = null) * names would also need to reflect the alias, just like an SQL query. For * example: `users as a`. * - * @param string|array $_,... Table names given as a single string, an array of + * @param string|array ...$_ Table names given as a single string, an array of * strings or multiple string parameters for the function. * - * @return string[]|self Array of tables names, or self if used as a setter. + * @return ($_ is null ? string[] : $this) Array of tables names. */ public function table($_ = null) { @@ -789,8 +784,7 @@ public function table($_ = null) * @param bool $_ Enable (`true`) or disabled (`false`) transactions. * If not given, then used as a getter. * - * @return bool|self Transactions enabled flag, or self if used as a - * setter. + * @return ($_ is null ? bool : $this) Transactions enabled flag. */ public function transaction($_ = null) { @@ -803,8 +797,7 @@ public function transaction($_ = null) * * @param bool $_ `true` to enable (default), otherwise false to disable * - * @return bool|Editor Value if used as a getter, otherwise `$this` when - * used as a setter. + * @return ($_ is null ? bool : $this) Value if used as a getter. */ public function tryCatch($_ = null) { @@ -870,8 +863,7 @@ public function validate(&$errors, $data) * It is passed three parameters: 1. The editor instance, 2. The action * and 3. The values. * - * @return Editor|callable Editor instance if called as a setter, or the - * validator function if not. + * @return ($_ is null ? callable : $this) The validator function. */ public function validator($_ = null) { @@ -902,7 +894,7 @@ public function validator($_ = null) * @param string $value Single field value. * @param string $op Condition operator: <, >, = etc * - * @return string[]|self Where condition array, or self if used as a setter. + * @return ($key is null ? string[] : $this) Where condition array. */ public function where($key = null, $value = null, $op = '=') { @@ -929,7 +921,7 @@ public function where($key = null, $value = null, $op = '=') * * @param bool $_ Include (`true`), or not (`false`) * - * @return bool Current value + * @return ($_ is null ? bool : $this) Current value * * @deprecated Note that `whereSet` is now deprecated and replaced with the * ability to set values for columns on create and edit. The C# libraries @@ -940,6 +932,11 @@ public function whereSet($_ = null) return $this->_getSet($this->_whereSet, $_); } + /** + * @param bool $_writeVal + * + * @return ($_writeVal is null ? bool : $this) + */ public function write($_writeVal = null) { return $this->_getSet($this->_write, $_writeVal); @@ -1536,7 +1533,7 @@ private function _fileDataFields(&$files, $fields, $limitTable, $idsIn = null, $ if ($fileData !== null) { if (isset($files[$table])) { - $files[$table] = $files[$table] + $fileData; + $files[$table] += $fileData; } else { $files[$table] = $fileData; } diff --git a/Editor/Field.php b/Editor/Field.php index d033d18..3a0f208 100644 --- a/Editor/Field.php +++ b/Editor/Field.php @@ -182,8 +182,7 @@ public function __construct($dbField = null, $name = null) * * @param string $_ Value to set if using as a setter. * - * @return string|self The name of the db field if no parameter is given, - * or self if used as a setter. + * @return ($_ is null ? string : $this) The name of the db field if no parameter is given. */ public function dbField($_ = null) { @@ -211,8 +210,7 @@ public function dbField($_ = null) * * @param bool $_ Value to set if using as a setter. * - * @return bool|self The get property if no parameter is given, or self - * if used as a setter. + * @return ($_ is null ? bool : $this) The get property if no parameter is given. */ public function get($_ = null) { @@ -238,8 +236,7 @@ public function get($_ = null) * date formatting string, or a required flag. The actual options available * depend upon the formatter used. * - * @return callable|string|self The get formatter if no parameter is given, or - * self if used as a setter. + * @return ($_ is null ? callable|string : $this) The get formatter if no parameter is given. */ public function getFormatter($_ = null, $opts = null) { @@ -257,8 +254,7 @@ public function getFormatter($_ = null, $opts = null) * @param callable|string|number $_ Value to set, or no value to use as a * getter * - * @return callable|string|self Value if used as a getter, or self if used - * as a setter. + * @return ($_ is null ? callable|string : $this) Value if used as a getter. */ public function getValue($_ = null) { @@ -275,8 +271,7 @@ public function getValue($_ = null) * * @param string $_ Value to set if using as a setter. * - * @return string|self The name property if no parameter is given, or self - * if used as a setter. + * @return ($_ is null ? string : $this) The name property if no parameter is given. */ public function name($_ = null) { @@ -302,7 +297,7 @@ public function name($_ = null) * @param callable $format Function will render each label * @param string $order SQL ordering * - * @return Field Self for chaining + * @return ($table is null ? Options : $this) */ public function options($table = null, $value = null, $label = null, $condition = null, $format = null, $order = null) { @@ -347,7 +342,7 @@ public function options($table = null, $value = null, $label = null, $condition * * @param SearchPaneOptions|callable $spInput SearchPaneOptions instance or a closure function if providing a method * - * @return self + * @return ($spInput is null ? SearchPaneOptions|null : $this) */ public function searchPaneOptions($spInput = null) { @@ -374,7 +369,7 @@ public function searchPaneOptions($spInput = null) * * @param SearchBuilderOptions|callable $sbInput SearchBuilderOptions instance or a closure function if providing a method * - * @return self + * @return ($sbInput is null ? SearchBuilderOptions|null : $this) */ public function searchBuilderOptions($sbInput = null) { @@ -387,7 +382,7 @@ public function searchBuilderOptions($sbInput = null) // Options class $this->_sboptsFn = null; $this->_sbopts = $sbInput; - } elseif ($spInput instanceof \Closure) { + } elseif ($sbInput instanceof \Closure) { // Function $this->_sbopts = null; $this->_sboptsFn = $sbInput; @@ -415,8 +410,7 @@ public function searchBuilderOptions($sbInput = null) * * `Field::SET_CREATE` - Set the database value only on create * * `Field::SET_EDIT` - Set the database value only on edit * - * @return string|self The set property if no parameter is given, or self - * if used as a setter. + * @return ($_ is null ? string : $this) The set property if no parameter is given. */ public function set($_ = null) { @@ -448,8 +442,7 @@ public function set($_ = null) * date formatting string, or a required flag. The actual options available * depend upon the formatter used. * - * @return callable|string|self The set formatter if no parameter is given, or - * self if used as a setter. + * @return ($_ is null ? callable|string : $this) The set formatter if no parameter is given. */ public function setFormatter($_ = null, $opts = null) { @@ -467,8 +460,7 @@ public function setFormatter($_ = null, $opts = null) * @param callable|string|number $_ Value to set, or no value to use as a * getter * - * @return callable|string|self Value if used as a getter, or self if used - * as a setter. + * @return ($_ is null ? callable|string : $this) Value if used as a getter. */ public function setValue($_ = null) { @@ -480,8 +472,7 @@ public function setValue($_ = null) * * @param Upload $_ Upload class if used as a setter * - * @return Upload|self Value if used as a getter, or self if used - * as a setter. + * @return ($_ is null ? Upload : $this) Value if used as a getter. */ public function upload($_ = null) { @@ -509,8 +500,7 @@ public function upload($_ = null) * date formatting string, or a required flag. The actual options available * depend upon the validation function used. * - * @return callable|string|self The validation method if no parameter is given, - * or self if used as a setter. + * @return ($_ is null ? array[] : $this) The validation method if no parameter is given. */ public function validator($_ = null, $opts = null) { @@ -544,7 +534,7 @@ public function validator($_ = null, $opts = null) * @param callable|false $xssFormatter XSS cleaner function, use `false` or * `null` to disable XSS cleaning. * - * @return Field Self for chaining. + * @return $this */ public function xss($xssFormatter) { diff --git a/Editor/Join.php b/Editor/Join.php index a6a3753..b6a1a4e 100644 --- a/Editor/Join.php +++ b/Editor/Join.php @@ -15,7 +15,6 @@ use DataTables; use DataTables\Editor; -use DataTables\Editor\Field; /** * Join table class for DataTables Editor. @@ -146,8 +145,7 @@ public function __construct($table = null, $type = 'object') * * @param string $_ Table alias to use * - * @return string|self Table alias set (which is null by default), or self if used as - * a setter. + * @return ($_ is null ? string : $this) Table alias set (which is null by default). */ public function aliasParentTable($_ = null) { @@ -160,11 +158,11 @@ public function aliasParentTable($_ = null) * The list of fields designates which columns in the table that will be read * from the joined table. * - * @param Field $_,... Instances of the {@see Field} class, given as a single + * @param Field ...$_ Instances of the {@see Field} class, given as a single * instance of {@see Field}, an array of {@see Field} instances, or multiple * {@see Field} instance parameters for the function. * - * @return Field[]|self Array of fields, or self if used as a setter. + * @return ($_ is null ? Field[] : $this) Array of fields. * * @see {@see Field} for field documentation. */ @@ -184,11 +182,11 @@ public function field($_ = null) * * An alias of {@see field}, for convenience. * - * @param Field $_,... Instances of the {@see Field} class, given as a single + * @param Field ...$_ Instances of the {@see Field} class, given as a single * instance of {@see Field}, an array of {@see Field} instances, or multiple * {@see Field} instance parameters for the function. * - * @return Field[]|self Array of fields, or self if used as a setter. + * @return ($_ is null ? Field[] : $this) Array of fields. * * @see {@see Field} for field documentation. */ @@ -210,7 +208,7 @@ public function fields($_ = null) * * @param bool $_ Value * - * @return bool|self Name + * @return ($_ is null ? bool : $this) Name */ public function get($_ = null) { @@ -241,7 +239,7 @@ public function get($_ = null) * link table. * @param string $table Join table name, if using a link table * - * @return Join This for chaining + * @return ($parent is null ? array : $this) * * @deprecated 1.5 Please use the {@see Join->link()} method rather than this * method now. @@ -267,7 +265,7 @@ public function join($parent = null, $child = null, $table = null) * @param string $operator the operation to perform on the two fields * @param string $field2 the second field to get the information from * - * @return self + * @return $this */ public function leftJoin($table, $field1, $operator, $field2) { @@ -298,7 +296,7 @@ public function leftJoin($table, $field1, $operator, $field2) * @param string $field1 Table and field name * @param string $field2 Table and field name * - * @return Join Self for chaining + * @return $this */ public function link($field1, $field2) { @@ -321,7 +319,7 @@ public function link($field1, $field2) * * @param string $_ SQL column name to order the data by * - * @return Join Self for chaining + * @return ($_ is null ? Join : $this) */ public function order($_ = null) { @@ -341,7 +339,7 @@ public function order($_ = null) * * @param string $_ Field name * - * @return string|self Name + * @return ($_ is null ? string : $this) Name */ public function name($_ = null) { @@ -357,7 +355,7 @@ public function name($_ = null) * * @param bool $_ Value * - * @return bool|self Name + * @return ($_ is null ? bool : $this) Name */ public function set($_ = null) { @@ -374,7 +372,7 @@ public function set($_ = null) * * @param string $_ Name of the table to read the join data from * - * @return string|self Name of the join table, or self if used as a setter. + * @return ($_ is null ? string : $this) Name of the join table. */ public function table($_ = null) { @@ -396,7 +394,7 @@ public function table($_ = null) * @param string $_ Join type ('object') or an array of * results ('array') for the join. * - * @return string|self Join type, or self if used as a setter. + * @return ($_ is null ? string : $this) Join type. */ public function type($_ = null) { @@ -410,7 +408,7 @@ public function type($_ = null) * against on the client-side * @param callable $fn Callback function for validation * - * @return self Chainable + * @return $this */ public function validator($fieldName, $fn) { @@ -435,7 +433,7 @@ public function validator($fieldName, $fn) * @param string|string[] $value Single field value, or an array of values. * @param string $op Condition operator: <, >, = etc * - * @return string[]|self Where condition array, or self if used as a setter. + * @return ($key is null ? string[] : $this) Where condition array. */ public function where($key = null, $value = null, $op = '=') { @@ -468,7 +466,7 @@ public function where($key = null, $value = null, $op = '=') * * @param bool $_ Include (`true`), or not (`false`) * - * @return bool Current value + * @return ($_ is null ? bool : $this) Current value */ public function whereSet($_ = null) { diff --git a/Editor/Options.php b/Editor/Options.php index 894cdee..efcbc95 100644 --- a/Editor/Options.php +++ b/Editor/Options.php @@ -102,7 +102,7 @@ class Options extends DataTables\Ext * @param string $label The label to use for the option * @param string|null $value Value for the option. If not given, the label will be used * - * @return Options Self for chaining + * @return $this */ public function add($label, $value = null) { @@ -124,8 +124,7 @@ public function add($label, $value = null) * @param string|string[]|null $_ null to get the current value, string or * array to get. * - * @return Options|string[] Self if setting for chaining, array of values if - * getting. + * @return ($_ is null ? string[] : $this) */ public function label($_ = null) { @@ -148,7 +147,7 @@ public function label($_ = null) * @param string $operator the operation to perform on the two fields * @param string $field2 the second field to get the information from * - * @return self + * @return $this */ public function leftJoin($table, $field1, $operator, $field2) { @@ -167,7 +166,7 @@ public function leftJoin($table, $field1, $operator, $field2) * * @param number|null $_ Number of rows to limit the result to * - * @return Options|string[] Self if setting for chaining, limit if getting. + * @return ($_ is null ? string[] : $this) */ public function limit($_ = null) { @@ -181,7 +180,7 @@ public function limit($_ = null) * * @param string|null $_ String to set, null to get current value * - * @return Options|string Self if setting for chaining, string if getting. + * @return ($_ is null ? string : $this) */ public function order($_ = null) { @@ -195,8 +194,7 @@ public function order($_ = null) * * @param callable|null $_ Function to set, null to get current value * - * @return Options|callable Self if setting for chaining, callable if - * getting. + * @return ($_ is null ? callable : $this) */ public function render($_ = null) { @@ -209,7 +207,7 @@ public function render($_ = null) * * @param string|null $_ String to set, null to get current value * - * @return Options|string Self if setting for chaining, string if getting. + * @return ($_ is null ? string : $this) */ public function table($_ = null) { @@ -222,7 +220,7 @@ public function table($_ = null) * * @param string|null $_ String to set, null to get current value * - * @return Options|string Self if setting for chaining, string if getting. + * @return ($_ is null ? string : $this) */ public function value($_ = null) { @@ -235,8 +233,7 @@ public function value($_ = null) * * @param callable|null $_ Function to set, null to get current value * - * @return Options|callable Self if setting for chaining, callable if - * getting. + * @return ($_ is null ? callable : $this) */ public function where($_ = null) { diff --git a/Editor/SearchBuilderOptions.php b/Editor/SearchBuilderOptions.php index 6dc42c5..e49c2dc 100644 --- a/Editor/SearchBuilderOptions.php +++ b/Editor/SearchBuilderOptions.php @@ -96,8 +96,7 @@ class SearchBuilderOptions extends DataTables\Ext * @param string|string[]|null $_ null to get the current value, string or * array to get. * - * @return Options|string[] Self if setting for chaining, array of values if - * getting. + * @return ($_ is null ? string[] : $this) */ public function label($_ = null) { @@ -119,7 +118,7 @@ public function label($_ = null) * * @param string|null $_ String to set, null to get current value * - * @return Options|string Self if setting for chaining, string if getting. + * @return ($_ is null ? string : $this) */ public function order($_ = null) { @@ -133,8 +132,7 @@ public function order($_ = null) * * @param callable|null $_ Function to set, null to get current value * - * @return Options|callable Self if setting for chaining, callable if - * getting. + * @return ($_ is null ? callable : $this) */ public function render($_ = null) { @@ -147,7 +145,7 @@ public function render($_ = null) * * @param string|null $_ String to set, null to get current value * - * @return Options|string Self if setting for chaining, string if getting. + * @return ($_ is null ? string : $this) */ public function table($_ = null) { @@ -160,7 +158,7 @@ public function table($_ = null) * * @param string|null $_ String to set, null to get current value * - * @return Options|string Self if setting for chaining, string if getting. + * @return ($_ is null ? string : $this) */ public function value($_ = null) { @@ -173,8 +171,7 @@ public function value($_ = null) * * @param callable|null $_ Function to set, null to get current value * - * @return Options|callable Self if setting for chaining, callable if - * getting. + * @return ($_ is null ? callable : $this) */ public function where($_ = null) { @@ -190,7 +187,7 @@ public function where($_ = null) * @param string $operator the operation to perform on the two fields * @param string $field2 the second field to get the information from * - * @return self + * @return $this */ public function leftJoin($table, $field1, $operator, $field2) { @@ -209,7 +206,7 @@ public function leftJoin($table, $field1, $operator, $field2) * * @param string $query the query being built * - * @return self + * @return $this */ private function _get_where($query) { diff --git a/Editor/SearchPaneOptions.php b/Editor/SearchPaneOptions.php index 4172e58..d728211 100644 --- a/Editor/SearchPaneOptions.php +++ b/Editor/SearchPaneOptions.php @@ -96,8 +96,7 @@ class SearchPaneOptions extends DataTables\Ext * @param string|string[]|null $_ null to get the current value, string or * array to get. * - * @return Options|string[] Self if setting for chaining, array of values if - * getting. + * @return ($_ is null ? string[] : $this) */ public function label($_ = null) { @@ -119,7 +118,7 @@ public function label($_ = null) * * @param string|null $_ String to set, null to get current value * - * @return Options|string Self if setting for chaining, string if getting. + * @return ($_ is null ? string : $this) */ public function order($_ = null) { @@ -133,8 +132,7 @@ public function order($_ = null) * * @param callable|null $_ Function to set, null to get current value * - * @return Options|callable Self if setting for chaining, callable if - * getting. + * @return ($_ is null ? callable : $this) */ public function render($_ = null) { @@ -147,7 +145,7 @@ public function render($_ = null) * * @param string|null $_ String to set, null to get current value * - * @return Options|string Self if setting for chaining, string if getting. + * @return ($_ is null ? string : $this) */ public function table($_ = null) { @@ -160,7 +158,7 @@ public function table($_ = null) * * @param string|null $_ String to set, null to get current value * - * @return Options|string Self if setting for chaining, string if getting. + * @return ($_ is null ? string : $this) */ public function value($_ = null) { @@ -173,8 +171,7 @@ public function value($_ = null) * * @param callable|null $_ Function to set, null to get current value * - * @return Options|callable Self if setting for chaining, callable if - * getting. + * @return ($_ is null ? callable : $this) */ public function where($_ = null) { @@ -190,7 +187,7 @@ public function where($_ = null) * @param string $operator the operation to perform on the two fields * @param string $field2 the second field to get the information from * - * @return self + * @return $this */ public function leftJoin($table, $field1, $operator, $field2) { @@ -209,7 +206,7 @@ public function leftJoin($table, $field1, $operator, $field2) * * @param string $query the query being built * - * @return self + * @return $this */ private function _get_where($query) { diff --git a/Editor/Upload.php b/Editor/Upload.php index 13a6033..d619cb9 100644 --- a/Editor/Upload.php +++ b/Editor/Upload.php @@ -172,7 +172,7 @@ public function __construct($action = null) * * @param string|callable $action Action to take - see description above. * - * @return self Current instance, used for chaining + * @return $this */ public function action($action) { @@ -193,7 +193,7 @@ public function action($action) * @param string $error Error message if a file is uploaded that doesn't * match the valid list of extensions. * - * @return self Current instance, used for chaining + * @return $this * * @deprecated Use Validate::fileExtensions */ @@ -225,7 +225,7 @@ public function allowedExtensions($extn, $error = 'This file type cannot be uplo * from the database. Only gets a single parameter passed in - the * database row for the file that is read. * - * @return self Current instance, used for chaining + * @return $this */ public function db($table, $pkey, $fields, $format = null) { @@ -247,7 +247,7 @@ public function db($table, $pkey, $fields, $format = null) * removed from the database. Any other return value (including none) * will result in the records being retained. * - * @return self Current instance, used for chaining + * @return $this */ public function dbClean($tableField, $callback = null) { @@ -266,6 +266,8 @@ public function dbClean($tableField, $callback = null) /** * Set the permissions on the file after it has been uploaded using * chmod. + * + * @return $this */ public function mode($m) { @@ -283,7 +285,7 @@ public function mode($m) * passed in for the uploaded file and the return is either a string * (validation failed and error message), or `null` (validation passed). * - * @return self Current instance, used for chaining + * @return $this */ public function validator($fn) { @@ -300,7 +302,7 @@ public function validator($fn) * * @param callable $fn Where function. * - * @return self Current instance, used for chaining + * @return $this */ public function where($fn) { diff --git a/Editor/ValidateOptions.php b/Editor/ValidateOptions.php index f2372a1..726a088 100644 --- a/Editor/ValidateOptions.php +++ b/Editor/ValidateOptions.php @@ -37,8 +37,6 @@ public function __construct($opts = null) $this->optional($opts['optional']); } } - - return $this; } /** @@ -47,7 +45,7 @@ public function __construct($opts = null) * @param string $msg Error message to use. If not given, the currently * set message will be returned. * - * @return ValidateOptions|string Self if setting, message if getting. + * @return ($msg is null ? string : $this) */ public function message($msg = null) { @@ -66,7 +64,7 @@ public function message($msg = null) * @param bool $empty `false` if the field is not allowed to be * empty. `true` if it can be. * - * @return ValidateOptions|bool Self if setting, current value if getting. + * @return ($empty is null ? bool : $this) */ public function allowEmpty($empty = null) { @@ -85,7 +83,7 @@ public function allowEmpty($empty = null) * @param bool $optional `false` if the field does not need to be * submitted. `true` if it must be. * - * @return ValidateOptions|bool Self if setting, current value if getting. + * @return ($optional is null ? bool : $this) */ public function optional($optional = null) { diff --git a/Ext.php b/Ext.php index 013d7cc..2d76d8d 100644 --- a/Ext.php +++ b/Ext.php @@ -27,18 +27,14 @@ class Ext * If using PHP 5.4 or later, simply create a 'new' instance of the * target class and chain methods as normal. * - * @return \DataTables\Editor|\DataTables\Editor\Field|\DataTables\Editor\Join|\DataTables\Editor\Upload Instantiated class - * - * @static + * @return static Instantiated class */ public static function instantiate() { $rc = new \ReflectionClass(get_called_class()); $args = func_get_args(); - return count($args) === 0 ? - $rc->newInstance() : - $rc->newInstanceArgs($args); + return $rc->newInstanceArgs($args); } /** @@ -48,18 +44,14 @@ public static function instantiate() * This method performs exactly the same actions as the 'instantiate' * static method, but is simply shorter and easier to type! * - * @return \DataTables\Editor|\DataTables\Editor\Field|\DataTables\Editor\Join|\DataTables\Editor\Upload class - * - * @static + * @return static class */ public static function inst() { $rc = new \ReflectionClass(get_called_class()); $args = func_get_args(); - return count($args) === 0 ? - $rc->newInstance() : - $rc->newInstanceArgs($args); + return $rc->newInstanceArgs($args); } /** @@ -75,8 +67,7 @@ public static function inst() * (default false). If used as an array, then values passed in are added * to the $prop array. * - * @return self|mixed Class instance if setting (allowing chaining), or - * the value requested if getting. + * @return ($prop is null ? mixed : $this) */ protected function _getSet(&$prop, $val, $array = false) { diff --git a/composer.json b/composer.json index 6757a6c..24d5dd0 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ "require-dev": { "friendsofphp/php-cs-fixer": "^3.0", "phpstan/extension-installer": "^1.1", - "phpstan/phpstan": "1.4.5", + "phpstan/phpstan": "~1.10.47", "phpstan/phpstan-deprecation-rules": "^1.0" }, "autoload": { diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 1cb96bf..9113d50 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -6,7 +6,7 @@ parameters: path: Database/Driver/Db2Query.php - - message: "#^Method DataTables\\\\Database\\\\Driver\\\\Db2Query\\:\\:connect\\(\\) should return DataTables\\\\Database\\\\Query but returns resource\\.$#" + message: "#^Method DataTables\\\\Database\\\\Driver\\\\Db2Query\\:\\:connect\\(\\) should return PDO but returns resource\\.$#" count: 1 path: Database/Driver/Db2Query.php @@ -26,7 +26,7 @@ parameters: path: Database/Driver/Db2Result.php - - message: "#^Method DataTables\\\\Database\\\\Driver\\\\FirebirdQuery\\:\\:connect\\(\\) should return DataTables\\\\Database\\\\Query but returns PDO\\.$#" + message: "#^Call to function is_array\\(\\) with non\\-empty\\-array\\ will always evaluate to true\\.$#" count: 1 path: Database/Driver/FirebirdQuery.php @@ -41,12 +41,12 @@ parameters: path: Database/Driver/FirebirdResult.php - - message: "#^Method DataTables\\\\Database\\\\Driver\\\\MysqlQuery\\:\\:connect\\(\\) should return DataTables\\\\Database\\\\Query but returns PDO\\.$#" + message: "#^Call to function is_array\\(\\) with non\\-empty\\-array\\ will always evaluate to true\\.$#" count: 1 - path: Database/Driver/MysqlQuery.php + path: Database/Driver/OracleQuery.php - - message: "#^Method DataTables\\\\Database\\\\Driver\\\\OracleQuery\\:\\:connect\\(\\) should return DataTables\\\\Database\\\\Query but returns resource\\.$#" + message: "#^Method DataTables\\\\Database\\\\Driver\\\\OracleQuery\\:\\:connect\\(\\) should return PDO but returns resource\\.$#" count: 1 path: Database/Driver/OracleQuery.php @@ -80,11 +80,6 @@ parameters: count: 1 path: Database/Driver/OracleResult.php - - - message: "#^Method DataTables\\\\Database\\\\Driver\\\\PostgresQuery\\:\\:connect\\(\\) should return DataTables\\\\Database\\\\Query but returns PDO\\.$#" - count: 1 - path: Database/Driver/PostgresQuery.php - - message: "#^Property DataTables\\\\Database\\\\Driver\\\\PostgresQuery\\:\\:\\$_identifier_limiter \\(string\\) does not accept default value of type array\\\\.$#" count: 1 @@ -95,16 +90,6 @@ parameters: count: 1 path: Database/Driver/PostgresResult.php - - - message: "#^Method DataTables\\\\Database\\\\Driver\\\\SqliteQuery\\:\\:connect\\(\\) should return DataTables\\\\Database\\\\Query but returns PDO\\.$#" - count: 1 - path: Database/Driver/SqliteQuery.php - - - - message: "#^Method DataTables\\\\Database\\\\Driver\\\\SqlserverQuery\\:\\:connect\\(\\) should return DataTables\\\\Database\\\\Query but returns PDO\\.$#" - count: 1 - path: Database/Driver/SqlserverQuery.php - - message: "#^Property DataTables\\\\Database\\\\Driver\\\\SqlserverQuery\\:\\:\\$_identifier_limiter \\(string\\) does not accept default value of type array\\\\.$#" count: 1 @@ -116,7 +101,7 @@ parameters: path: Database/Query.php - - message: "#^Method DataTables\\\\Database\\\\Query\\:\\:connect\\(\\) should return DataTables\\\\Database\\\\Query but return statement is missing\\.$#" + message: "#^Method DataTables\\\\Database\\\\Query\\:\\:connect\\(\\) should return PDO but return statement is missing\\.$#" count: 1 path: Database/Query.php @@ -162,7 +147,7 @@ parameters: - message: "#^If condition is always true\\.$#" - count: 4 + count: 3 path: Editor.php - @@ -245,11 +230,6 @@ parameters: count: 1 path: Editor.php - - - message: "#^Property DataTables\\\\Editor\\:\\:\\$_validator \\(callable\\(\\)\\: mixed\\) does not accept default value of type array\\{\\}\\.$#" - count: 1 - path: Editor.php - - message: "#^Result of && is always false\\.$#" count: 2 @@ -276,7 +256,7 @@ parameters: path: Editor.php - - message: "#^Strict comparison using \\=\\=\\= between \\(callable\\(\\)\\: mixed\\)\\|DataTables\\\\Editor\\\\Field\\|string and null will always evaluate to false\\.$#" + message: "#^Strict comparison using \\=\\=\\= between \\(callable\\(\\)\\: mixed\\)\\|string and null will always evaluate to false\\.$#" count: 1 path: Editor.php @@ -300,26 +280,6 @@ parameters: count: 1 path: Editor.php - - - message: "#^Call to function is_callable\\(\\) with callable\\(\\)\\: mixed will always evaluate to true\\.$#" - count: 2 - path: Editor/Field.php - - - - message: "#^Cannot call method value\\(\\) on array\\\\|DataTables\\\\Editor\\|DataTables\\\\Editor\\\\Join\\|string\\.$#" - count: 1 - path: Editor/Field.php - - - - message: "#^Method DataTables\\\\Editor\\\\Field\\:\\:options\\(\\) should return DataTables\\\\Editor\\\\Field but returns DataTables\\\\Editor\\\\Options\\|null\\.$#" - count: 1 - path: Editor/Field.php - - - - message: "#^Method DataTables\\\\Editor\\\\Field\\:\\:searchBuilderOptions\\(\\) should return DataTables\\\\Editor\\\\Field but returns DataTables\\\\Editor\\\\SearchBuilderOptions\\|null\\.$#" - count: 1 - path: Editor/Field.php - - message: "#^Method DataTables\\\\Editor\\\\Field\\:\\:searchBuilderOptionsExec\\(\\) has invalid return type DataTables\\\\Editor\\\\IOption\\.$#" count: 1 @@ -335,11 +295,6 @@ parameters: count: 1 path: Editor/Field.php - - - message: "#^Method DataTables\\\\Editor\\\\Field\\:\\:searchPaneOptions\\(\\) should return DataTables\\\\Editor\\\\Field but returns DataTables\\\\Editor\\\\SearchPaneOptions\\|null\\.$#" - count: 1 - path: Editor/Field.php - - message: "#^Method DataTables\\\\Editor\\\\Field\\:\\:xssSafety\\(\\) should return string but returns array\\\\.$#" count: 1 @@ -575,11 +530,6 @@ parameters: count: 1 path: Editor/SearchBuilderOptions.php - - - message: "#^Method DataTables\\\\Editor\\\\SearchBuilderOptions\\:\\:label\\(\\) should return array\\\\|DataTables\\\\Editor\\\\Options but returns \\$this\\(DataTables\\\\Editor\\\\SearchBuilderOptions\\)\\.$#" - count: 2 - path: Editor/SearchBuilderOptions.php - - message: "#^Negated boolean expression is always false\\.$#" count: 1 @@ -625,11 +575,6 @@ parameters: count: 1 path: Editor/SearchPaneOptions.php - - - message: "#^Method DataTables\\\\Editor\\\\SearchPaneOptions\\:\\:label\\(\\) should return array\\\\|DataTables\\\\Editor\\\\Options but returns \\$this\\(DataTables\\\\Editor\\\\SearchPaneOptions\\)\\.$#" - count: 2 - path: Editor/SearchPaneOptions.php - - message: "#^Property DataTables\\\\Editor\\\\SearchPaneOptions\\:\\:\\$_order is never written, only read\\.$#" count: 1 @@ -790,18 +735,3 @@ parameters: count: 1 path: Editor/Validate.php - - - message: "#^Method DataTables\\\\Editor\\\\ValidateOptions\\:\\:__construct\\(\\) with return type void returns \\$this\\(DataTables\\\\Editor\\\\ValidateOptions\\) but should not return anything\\.$#" - count: 1 - path: Editor/ValidateOptions.php - - - - message: "#^Method DataTables\\\\Ext\\:\\:inst\\(\\) should return DataTables\\\\Editor\\|DataTables\\\\Editor\\\\Field\\|DataTables\\\\Editor\\\\Join\\|DataTables\\\\Editor\\\\Upload but returns static\\(DataTables\\\\Ext\\)\\.$#" - count: 1 - path: Ext.php - - - - message: "#^Method DataTables\\\\Ext\\:\\:instantiate\\(\\) should return DataTables\\\\Editor\\|DataTables\\\\Editor\\\\Field\\|DataTables\\\\Editor\\\\Join\\|DataTables\\\\Editor\\\\Upload but returns static\\(DataTables\\\\Ext\\)\\.$#" - count: 1 - path: Ext.php -