Merge pull request #4837 from paulbalandan/unary-op

Define rules on unary operators
This commit is contained in:
John Paul E. Balandan, CPA 2021-06-17 00:25:35 +08:00 committed by GitHub
commit 361590b0df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
29 changed files with 73 additions and 68 deletions

View File

@ -403,7 +403,7 @@ class CLI
while ($time > 0) {
static::fwrite(STDOUT, $time . '... ');
sleep(1);
$time --;
$time--;
}
static::write();
@ -442,7 +442,7 @@ class CLI
public static function newLine(int $num = 1)
{
// Do it once or more, write with empty string gives us a new line
for ($i = 0; $i < $num; $i ++) {
for ($i = 0; $i < $num; $i++) {
static::write();
}
}
@ -998,7 +998,7 @@ class CLI
$maxColsLengths = [];
// Read row by row and define the longest columns
for ($row = 0; $row < $totalRows; $row ++) {
for ($row = 0; $row < $totalRows; $row++) {
$column = 0; // Current column index
foreach ($tableRows[$row] as $col) {
@ -1013,13 +1013,13 @@ class CLI
}
// We can go check the size of the next column...
$column ++;
$column++;
}
}
// Read row by row and add spaces at the end of the columns
// to match the exact column length
for ($row = 0; $row < $totalRows; $row ++) {
for ($row = 0; $row < $totalRows; $row++) {
$column = 0;
foreach ($tableRows[$row] as $col) {
@ -1029,14 +1029,14 @@ class CLI
$tableRows[$row][$column] = $tableRows[$row][$column] . str_repeat(' ', $diff);
}
$column ++;
$column++;
}
}
$table = '';
// Joins columns and append the well formatted rows to the table
for ($row = 0; $row < $totalRows; $row ++) {
for ($row = 0; $row < $totalRows; $row++) {
// Set the table border-top
if ($row === 0) {
$cols = '+';

View File

@ -653,7 +653,7 @@ class BaseBuilder
$joints = $joints[0];
array_unshift($joints, ['', 0]);
for ($i = count($joints) - 1, $pos = strlen($cond); $i >= 0; $i --) {
for ($i = count($joints) - 1, $pos = strlen($cond); $i >= 0; $i--) {
$joints[$i][1] += strlen($joints[$i][0]); // offset
$conditions[$i] = substr($cond, $joints[$i][1], $pos - $joints[$i][1]);
$pos = $joints[$i][1] - strlen($joints[$i][0]);
@ -1419,7 +1419,7 @@ class BaseBuilder
$this->QBWhereGroupStarted = true;
$prefix = empty($this->$clause) ? '' : $type;
$where = [
'condition' => $prefix . $not . str_repeat(' ', ++ $this->QBWhereGroupCount) . ' (',
'condition' => $prefix . $not . str_repeat(' ', ++$this->QBWhereGroupCount) . ' (',
'escape' => false,
];
@ -1999,7 +1999,7 @@ class BaseBuilder
$sql = $this->_insertBatch($this->db->protectIdentifiers($table, true, $escape, false), $this->QBKeys, array_slice($this->QBSet, $i, $batchSize));
if ($this->testMode) {
++$affectedRows;
$affectedRows++;
} else {
$this->db->query($sql, $this->binds, false);
$affectedRows += $this->db->affectedRows();

View File

@ -821,7 +821,7 @@ abstract class BaseConnection implements ConnectionInterface
// When transactions are nested we only begin/commit/rollback the outermost ones
if ($this->transDepth > 0) {
$this->transDepth ++;
$this->transDepth++;
return true;
}
@ -836,7 +836,7 @@ abstract class BaseConnection implements ConnectionInterface
$this->transFailure = ($testMode === true);
if ($this->_transBegin()) {
$this->transDepth ++;
$this->transDepth++;
return true;
}
@ -859,7 +859,7 @@ abstract class BaseConnection implements ConnectionInterface
// When transactions are nested we only begin/commit/rollback the outermost ones
if ($this->transDepth > 1 || $this->_transCommit()) {
$this->transDepth --;
$this->transDepth--;
return true;
}
@ -882,7 +882,7 @@ abstract class BaseConnection implements ConnectionInterface
// When transactions are nested we only begin/commit/rollback the outermost ones
if ($this->transDepth > 1 || $this->_transRollback()) {
$this->transDepth --;
$this->transDepth--;
return true;
}

View File

@ -140,7 +140,7 @@ abstract class BaseResult implements ResultInterface
}
if ($_data !== null) {
for ($i = 0; $i < $c; $i ++) {
for ($i = 0; $i < $c; $i++) {
$this->customResultObject[$className][$i] = new $className();
foreach ($this->{$_data}[$i] as $key => $value) {
@ -444,7 +444,7 @@ abstract class BaseResult implements ResultInterface
return null;
}
return isset($result[$this->currentRow + 1]) ? $result[++ $this->currentRow] : null;
return isset($result[$this->currentRow + 1]) ? $result[++$this->currentRow] : null;
}
//--------------------------------------------------------------------
@ -464,7 +464,7 @@ abstract class BaseResult implements ResultInterface
}
if (isset($result[$this->currentRow - 1])) {
-- $this->currentRow;
$this->currentRow--;
}
return $result[$this->currentRow];

View File

@ -57,7 +57,7 @@ abstract class BaseUtils
*/
public function __construct(ConnectionInterface &$db)
{
$this->db = & $db;
$this->db = &$db;
}
//--------------------------------------------------------------------
@ -91,7 +91,7 @@ abstract class BaseUtils
return $this->db->dataCache['db_names'];
}
for ($i = 0, $query = $query->getResultArray(), $c = count($query); $i < $c; $i ++) {
for ($i = 0, $query = $query->getResultArray(), $c = count($query); $i < $c; $i++) {
$this->db->dataCache['db_names'][] = current($query[$i]);
}

View File

@ -207,9 +207,9 @@ class Forge extends BaseForge
{
$sql = '';
for ($i = 0, $c = count($this->keys); $i < $c; $i ++) {
for ($i = 0, $c = count($this->keys); $i < $c; $i++) {
if (is_array($this->keys[$i])) {
for ($i2 = 0, $c2 = count($this->keys[$i]); $i2 < $c2; $i2 ++) {
for ($i2 = 0, $c2 = count($this->keys[$i]); $i2 < $c2; $i2++) {
if (! isset($this->fields[$this->keys[$i][$i2]])) {
unset($this->keys[$i][$i2]);

View File

@ -294,7 +294,7 @@ class Connection extends BaseConnection
$retVal = [];
for ($i = 0, $c = count($query); $i < $c; $i ++) {
for ($i = 0, $c = count($query); $i < $c; $i++) {
$retVal[$i] = new stdClass();
$retVal[$i]->name = $query[$i]->column_name;

View File

@ -112,7 +112,7 @@ class PreparedQuery extends BasePreparedQuery
$count = 0;
return preg_replace_callback('/\?/', static function () use (&$count) {
$count ++;
$count++;
return "\${$count}";
}, $sql);

View File

@ -41,7 +41,7 @@ class Result extends BaseResult
{
$fieldNames = [];
for ($i = 0, $c = $this->getFieldCount(); $i < $c; $i ++) {
for ($i = 0, $c = $this->getFieldCount(); $i < $c; $i++) {
$fieldNames[] = pg_field_name($this->resultID, $i);
}
@ -59,7 +59,7 @@ class Result extends BaseResult
{
$retVal = [];
for ($i = 0, $c = $this->getFieldCount(); $i < $c; $i ++) {
for ($i = 0, $c = $this->getFieldCount(); $i < $c; $i++) {
$retVal[$i] = new stdClass();
$retVal[$i]->name = pg_field_name($this->resultID, $i);
$retVal[$i]->type = pg_field_type_oid($this->resultID, $i);

View File

@ -141,12 +141,13 @@ class Builder extends BaseBuilder
$joints = $joints[0];
array_unshift($joints, ['', 0]);
for ($i = count($joints) - 1, $pos = strlen($cond); $i >= 0; $i --) {
for ($i = count($joints) - 1, $pos = strlen($cond); $i >= 0; $i--) {
$joints[$i][1] += strlen($joints[$i][0]); // offset
$conditions[$i] = substr($cond, $joints[$i][1], $pos - $joints[$i][1]);
$pos = $joints[$i][1] - strlen($joints[$i][0]);
$joints[$i] = $joints[$i][0];
}
ksort($conditions);
} else {
$conditions = [$cond];

View File

@ -43,7 +43,7 @@ class Result extends BaseResult
{
$fieldNames = [];
for ($i = 0, $c = $this->getFieldCount(); $i < $c; $i ++) {
for ($i = 0, $c = $this->getFieldCount(); $i < $c; $i++) {
$fieldNames[] = $this->resultID->columnName($i); // @phpstan-ignore-line
}
@ -70,7 +70,7 @@ class Result extends BaseResult
$retVal = [];
$this->resultID->fetchArray(SQLITE3_NUM); // @phpstan-ignore-line
for ($i = 0, $c = $this->getFieldCount(); $i < $c; $i ++) {
for ($i = 0, $c = $this->getFieldCount(); $i < $c; $i++) {
$retVal[$i] = new stdClass();
$retVal[$i]->name = $this->resultID->columnName($i); // @phpstan-ignore-line
$type = $this->resultID->columnType($i); // @phpstan-ignore-line

View File

@ -75,9 +75,8 @@ class Iterator
$start = microtime(true);
$startMem = $maxMemory = memory_get_usage(true);
for ($i = 0; $i < $iterations; $i ++) {
$result = $test();
for ($i = 0; $i < $iterations; $i++) {
$result = $test();
$maxMemory = max($maxMemory, memory_get_usage(true));
unset($result);

View File

@ -691,7 +691,7 @@ class Email
fclose($fp);
} else {
$fileContent = & $file; // buffered file
$fileContent = &$file; // buffered file
}
// declare names on their own, to make phpcbf happy
@ -1042,7 +1042,7 @@ class Email
$body = preg_match('/\<body.*?\>(.*)\<\/body\>/si', $this->body, $match) ? $match[1] : $this->body;
$body = str_replace("\t", '', preg_replace('#<!--(.*)--\>#', '', trim(strip_tags($body))));
for ($i = 20; $i >= 3; $i --) {
for ($i = 20; $i >= 3; $i--) {
$body = str_replace(str_repeat("\n", $i), "\n\n", $body);
}
@ -1080,7 +1080,7 @@ class Email
$unwrap = [];
if (preg_match_all('|\{unwrap\}(.+?)\{/unwrap\}|s', $str, $matches)) {
for ($i = 0, $c = count($matches[0]); $i < $c; $i ++) {
for ($i = 0, $c = count($matches[0]); $i < $c; $i++) {
$unwrap[] = $matches[1][$i];
$str = str_replace($matches[0][$i], '{{unwrapped' . $i . '}}', $str);
}
@ -1488,7 +1488,7 @@ class Email
// Loop through each character in the line to add soft-wrap
// characters at the end of a line " =\r\n" and add the newly
// processed line(s) to the output (see comment on $crlf class property)
for ($i = 0; $i < $length; $i ++) {
for ($i = 0; $i < $length; $i++) {
// Grab the next character
$char = $line[$i];
$ascii = ord($char);
@ -1577,7 +1577,7 @@ class Email
$output = '=?' . $this->charset . '?Q?';
for ($i = 0, $length = static::strlen($output); $i < $chars; $i ++) {
for ($i = 0, $length = static::strlen($output); $i < $chars; $i++) {
$chr = ($this->charset === 'UTF-8' && extension_loaded('iconv')) ? '=' . implode('=', str_split(strtoupper(bin2hex(iconv_substr($str, $i, 1, $this->charset))), 2)) : '=' . strtoupper(bin2hex($str[$i]));
// RFC 2045 sets a limit of 76 characters per line.
@ -1679,7 +1679,7 @@ class Email
}
}
for ($i = 0, $c = count($chunk); $i < $c; $i ++) {
for ($i = 0, $c = count($chunk); $i < $c; $i++) {
unset($this->headers['Bcc']);
$bcc = $this->cleanEmail($this->stringToArray($chunk[$i]));

View File

@ -198,13 +198,13 @@ class File extends SplFileInfo
if (is_numeric(end($parts))) {
$i = end($parts);
array_pop($parts);
$parts[] = ++ $i;
$parts[] = ++$i;
$destination = $info['dirname'] . '/' . implode($delimiter, $parts) . $extension;
} else {
$destination = $info['dirname'] . '/' . $info['filename'] . $delimiter . ++ $i . $extension;
$destination = $info['dirname'] . '/' . $info['filename'] . $delimiter . ++$i . $extension;
}
} else {
$destination = $info['dirname'] . '/' . $info['filename'] . $delimiter . ++ $i . $extension;
$destination = $info['dirname'] . '/' . $info['filename'] . $delimiter . ++$i . $extension;
}
}

View File

@ -112,7 +112,7 @@ trait RequestTrait
// Make sure we're have the "full" IPv6 format
$ip = explode(':', str_replace('::', str_repeat(':', 9 - substr_count($this->ipAddress, ':')), $this->ipAddress));
for ($j = 0; $j < 8; $j ++) {
for ($j = 0; $j < 8; $j++) {
$ip[$j] = intval($ip[$j], 16);
}

View File

@ -579,7 +579,7 @@ class URI
{
// The segment should treat the array as 1-based for the user
// but we still have to deal with a zero-based array.
$number -= 1;
$number--;
if ($number > count($this->segments) && ! $this->silent) {
throw HTTPException::forURISegmentOutOfRange($number);
@ -601,7 +601,7 @@ class URI
{
// The segment should treat the array as 1-based for the user
// but we still have to deal with a zero-based array.
$number -= 1;
$number--;
if ($number > count($this->segments) + 1) {
if ($this->silent) {

View File

@ -275,7 +275,7 @@ if (! function_exists('number_to_roman')) {
break;
}
if ($num > 10) {
$return = $_number_to_roman($num / 10, ++ $th) . $return;
$return = $_number_to_roman($num / 10, ++$th) . $return;
}
return $return;

View File

@ -102,7 +102,7 @@ if (! function_exists('ascii_to_entities')) {
{
$out = '';
for ($i = 0, $s = strlen($str) - 1, $count = 1, $temp = []; $i <= $s; $i ++) {
for ($i = 0, $s = strlen($str) - 1, $count = 1, $temp = []; $i <= $s; $i++) {
$ordinal = ord($str[$i]);
if ($ordinal < 128) {
@ -156,7 +156,7 @@ if (! function_exists('entities_to_ascii')) {
function entities_to_ascii(string $str, bool $all = true): string
{
if (preg_match_all('/\&#(\d+)\;/', $str, $matches)) {
for ($i = 0, $s = count($matches[0]); $i < $s; $i ++) {
for ($i = 0, $s = count($matches[0]); $i < $s; $i++) {
$digits = $matches[1][$i];
$out = '';
if ($digits < 128) {
@ -235,7 +235,7 @@ if (! function_exists('word_censor')) {
} elseif (preg_match_all("/{$delim}(" . $badword . "){$delim}/i", $str, $matches, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE)) {
$matches = $matches[1];
for ($i = count($matches) - 1; $i >= 0; $i --) {
for ($i = count($matches) - 1; $i >= 0; $i--) {
$length = strlen($matches[$i][0]);
$str = substr_replace(
$str, str_repeat('#', $length), $matches[$i][1], $length
@ -410,7 +410,7 @@ if (! function_exists('word_wrap')) {
$unwrap = [];
if (preg_match_all('|\{unwrap\}(.+?)\{/unwrap\}|s', $str, $matches)) {
for ($i = 0, $c = count($matches[0]); $i < $c; $i ++) {
for ($i = 0, $c = count($matches[0]); $i < $c; $i++) {
$unwrap[] = $matches[1][$i];
$str = str_replace($matches[0][$i], '{{unwrapped' . $i . '}}', $str);
}
@ -765,7 +765,7 @@ if (! function_exists('excerpt')) {
if ((strlen($e) + $count + 1) < $radius) {
$prev = ' ' . $e . $prev;
}
$count = ++ $count + strlen($e);
$count = ++$count + strlen($e);
}
$count = 0;
@ -774,7 +774,7 @@ if (! function_exists('excerpt')) {
if ((strlen($s) + $count + 1) < $radius) {
$post .= $s . ' ';
}
$count = ++ $count + strlen($s);
$count = ++$count + strlen($s);
}
$ellPre = $phrase ? $ellipsis : '';

View File

@ -356,7 +356,7 @@ if (! function_exists('safe_mailto')) {
$x = str_split('<a href="mailto:', 1);
for ($i = 0, $l = strlen($email); $i < $l; $i ++) {
for ($i = 0, $l = strlen($email); $i < $l; $i++) {
$x[] = '|' . ord($email[$i]);
}
@ -367,14 +367,14 @@ if (! function_exists('safe_mailto')) {
foreach ($attributes as $key => $val) {
$x[] = ' ' . $key . '="';
for ($i = 0, $l = strlen($val); $i < $l; $i ++) {
for ($i = 0, $l = strlen($val); $i < $l; $i++) {
$x[] = '|' . ord($val[$i]);
}
$x[] = '"';
}
} else {
for ($i = 0, $l = mb_strlen($attributes); $i < $l; $i ++) {
for ($i = 0, $l = mb_strlen($attributes); $i < $l; $i++) {
$x[] = mb_substr($attributes, $i, 1);
}
}
@ -384,7 +384,7 @@ if (! function_exists('safe_mailto')) {
$temp = [];
for ($i = 0, $l = strlen($title); $i < $l; $i ++) {
for ($i = 0, $l = strlen($title); $i < $l; $i++) {
$ordinal = ord($title[$i]);
if ($ordinal < 128) {

View File

@ -271,7 +271,7 @@ class PagerRenderer
$uri = clone $this->uri;
for ($i = $this->first; $i <= $this->last; $i ++) {
for ($i = $this->first; $i <= $this->last; $i++) {
$uri = $this->segment === 0 ? $uri->addQuery($this->pageSelector, $i) : $uri->setSegment($this->segment, $i);
$links[] = [
'uri' => URI::createURIString($uri->getScheme(), $uri->getAuthority(), $uri->getPath(), $uri->getQuery(), $uri->getFragment()),

View File

@ -1365,7 +1365,7 @@ class RouteCollection implements RouteCollectionInterface
// Get a constant string to work with.
$to = preg_replace('/(\$\d+)/', '$X', $to);
for ($i = (int) $options['offset'] + 1; $i < (int) $options['offset'] + 7; $i ++) {
for ($i = (int) $options['offset'] + 1; $i < (int) $options['offset'] + 7; $i++) {
$to = preg_replace_callback(
'/\$X/', static function ($m) use ($i) {
return '$' . $i;

View File

@ -308,7 +308,7 @@ class MemcachedHandler extends BaseHandler
$this->lockKey = $lockKey;
break;
} while (++ $attempt < 30);
} while (++$attempt < 30);
if ($attempt === 30) {
$this->logger->error('Session: Unable to obtain lock for ' . $this->keyPrefix . $sessionID . ' after 30 attempts, aborting.');

View File

@ -329,7 +329,7 @@ class RedisHandler extends BaseHandler
$this->lockKey = $lockKey;
break;
} while (++ $attempt < 30);
} while (++$attempt < 30);
if ($attempt === 30) {
log_message('error', 'Session: Unable to obtain lock for ' . $this->keyPrefix . $sessionID . ' after 30 attempts, aborting.');

View File

@ -94,7 +94,7 @@ class Typography
// HTML comment tags don't conform to patterns of normal tags, so pull them out separately, only if needed
$htmlComments = [];
if (strpos($str, '<!--') !== false && preg_match_all('#(<!\-\-.*?\-\->)#s', $str, $matches)) {
for ($i = 0, $total = count($matches[0]); $i < $total; $i ++) {
for ($i = 0, $total = count($matches[0]); $i < $total; $i++) {
$htmlComments[] = $matches[0][$i];
$str = str_replace($matches[0][$i], '{@HC' . $i . '}', $str);
}
@ -135,7 +135,7 @@ class Typography
$str = '';
$process = true;
for ($i = 0, $c = count($chunks) - 1; $i <= $c; $i ++) {
for ($i = 0, $c = count($chunks) - 1; $i <= $c; $i++) {
// Are we dealing with a tag? If so, we'll skip the processing for this cycle.
// Well also set the "process" flag which allows us to skip <pre> tags and a few other things.
if (preg_match('#<(/*)(' . $this->blockElements . ').*?>#', $chunks[$i], $match)) {
@ -349,7 +349,7 @@ class Typography
{
$newstr = '';
for ($ex = explode('pre>', $str), $ct = count($ex), $i = 0; $i < $ct; $i ++) {
for ($ex = explode('pre>', $str), $ct = count($ex), $i = 0; $i < $ct; $i++) {
$newstr .= (($i % 2) === 0) ? nl2br($ex[$i]) : $ex[$i];
if ($ct - 1 !== $i) {

View File

@ -284,8 +284,8 @@ class CreditCardRules
$sum = 0;
$flip = 0;
for ($i = strlen($number) - 1; $i >= 0; $i --) {
$sum += $sumTable[$flip ++ & 0x1][$number[$i]];
for ($i = strlen($number) - 1; $i >= 0; $i--) {
$sum += $sumTable[$flip++ & 0x1][$number[$i]];
}
return $sum % 10 === 0;

View File

@ -345,7 +345,7 @@ class TextHelperTest extends CIUnitTestCase
$result = '';
alternator();
for ($i = 0; $i < 4; $i ++) {
for ($i = 0; $i < 4; $i++) {
$result .= alternator('I', 'you', 'we') . $phrase;
}
$this->assertEquals('I scream! you scream! we scream! I scream! ', $result);
@ -356,7 +356,7 @@ class TextHelperTest extends CIUnitTestCase
$phrase = ' scream! ';
$result = '';
for ($i = 0; $i < 4; $i ++) {
for ($i = 0; $i < 4; $i++) {
$result .= alternator() . $phrase;
}

View File

@ -1236,13 +1236,13 @@ class CreditCardRulesTest extends CIUnitTestCase
// Fill all of the remaining values with random numbers, except the last one.
while ($pos < $length - 1) {
$string[$pos ++] = random_int(0, 9);
$string[$pos++] = random_int(0, 9);
}
// Calculate the Luhn checksum of the current values.
$lenOffset = ($length + 1) % 2;
for ($pos = 0; $pos < $length - 1; $pos ++) {
for ($pos = 0; $pos < $length - 1; $pos++) {
if (($pos + $lenOffset) % 2) {
$temp = $string[$pos] * 2;
if ($temp > 9) {

View File

@ -781,7 +781,7 @@ class ParserTest extends CIUnitTestCase
$out = '';
for ($i = 1; $i <= $count; $i ++) {
for ($i = 1; $i <= $count; $i++) {
$out .= ' ' . $i * $step;
}

View File

@ -95,6 +95,7 @@ final class CodeIgniter4 extends AbstractRuleset
'function_to_constant' => true,
'heredoc_indentation' => ['indentation' => 'start_plus_one'],
'heredoc_to_nowdoc' => true,
'increment_style' => ['style' => 'post'],
'indentation_type' => true,
'lambda_not_used_import' => true,
'line_ending' => true,
@ -110,6 +111,8 @@ final class CodeIgniter4 extends AbstractRuleset
'no_trailing_comma_in_singleline_array' => true,
'no_unset_cast' => true,
'no_whitespace_before_comma_in_array' => ['after_heredoc' => true],
'not_operator_with_space' => false,
'not_operator_with_successor_space' => true,
'normalize_index_brace' => true,
'ordered_imports' => ['sort_algorithm' => 'alpha'],
'phpdoc_align' => true,
@ -183,6 +186,7 @@ final class CodeIgniter4 extends AbstractRuleset
],
'set_type_to_cast' => true,
'short_scalar_cast' => true,
'standardize_increment' => true,
'static_lambda' => true,
'switch_case_semicolon_to_colon' => true,
'switch_case_space' => true,
@ -194,6 +198,7 @@ final class CodeIgniter4 extends AbstractRuleset
],
'trim_array_spaces' => true,
'whitespace_after_comma_in_array' => true,
'unary_operator_spaces' => true,
'visibility_required' => ['elements' => ['const', 'method', 'property']],
'yoda_style' => [
'equal' => false,