Enable method_argument_space fixer

This commit is contained in:
John Paul E. Balandan, CPA 2021-06-16 00:50:52 +08:00
parent 2b323e20f4
commit a0dca3d5ba
No known key found for this signature in database
GPG Key ID: FB7B51499BC27610
37 changed files with 444 additions and 318 deletions

View File

@ -295,8 +295,10 @@ class FileLocator
if (mb_strpos($path, $namespace['path']) === 0) {
$className = '\\' . $namespace['prefix'] . '\\' .
ltrim(str_replace('/', '\\', mb_substr(
$path, mb_strlen($namespace['path']))
ltrim(str_replace(
'/',
'\\',
mb_substr($path, mb_strlen($namespace['path']))
), '\\');
// Remove the file extension (.php)

View File

@ -90,7 +90,9 @@ class MemcachedHandler extends BaseHandler
// Add server
$this->memcached->addServer(
$this->config['host'], $this->config['port'], $this->config['weight']
$this->config['host'],
$this->config['port'],
$this->config['weight']
);
// attempt to get status of servers
@ -107,7 +109,8 @@ class MemcachedHandler extends BaseHandler
// Check if we can connect to the server
$canConnect = $this->memcached->connect(
$this->config['host'], $this->config['port']
$this->config['host'],
$this->config['port']
);
// If we can't connect, throw a CriticalError exception
@ -117,16 +120,17 @@ class MemcachedHandler extends BaseHandler
// Add server, third parameter is persistence and defaults to TRUE.
$this->memcached->addServer(
$this->config['host'], $this->config['port'], true, $this->config['weight']
$this->config['host'],
$this->config['port'],
true,
$this->config['weight']
);
} else {
throw new CriticalError('Cache: Not support Memcache(d) extension.');
}
} catch (CriticalError $e) {
// If a CriticalError exception occurs, throw it up.
throw $e;
} catch (Exception $e) {
// If an \Exception occurs, convert it into a CriticalError exception and throw it.
throw new CriticalError('Cache: Memcache(d) connection refused (' . $e->getMessage() . ').');
}
}

View File

@ -92,10 +92,8 @@ class PredisHandler extends BaseHandler
{
$key = static::validateKey($key);
$data = array_combine([
'__ci_type',
'__ci_value',
],
$data = array_combine(
['__ci_type', '__ci_value'],
$this->redis->hmget($key, ['__ci_type', '__ci_value'])
);

View File

@ -513,8 +513,11 @@ if (! function_exists('force_https')) {
}
$uri = URI::createURIString(
'https', $baseURL, $request->uri->getPath(), // Absolute URIs should use a "/" for an empty path
$request->uri->getQuery(), $request->uri->getFragment()
'https',
$baseURL,
$request->uri->getPath(), // Absolute URIs should use a "/" for an empty path
$request->uri->getQuery(),
$request->uri->getFragment()
);
// Set an HSTS header

View File

@ -187,7 +187,8 @@ class DotEnv
) # end of the capturing sub-pattern
%1$s # and the closing quote
.*$ # and discard any string after the closing quote
/mx', $quote
/mx',
$quote
);
$value = preg_replace($regexPattern, '$1', $value);

View File

@ -2104,9 +2104,14 @@ class BaseBuilder
}
$sql = $this->_insert(
$this->db->protectIdentifiers(
$this->QBFrom[0], true, null, false
), array_keys($this->QBSet), array_values($this->QBSet)
$this->db->protectIdentifiers(
$this->QBFrom[0],
true,
null,
false
),
array_keys($this->QBSet),
array_values($this->QBSet)
);
if ($reset === true) {
@ -2139,9 +2144,14 @@ class BaseBuilder
}
$sql = $this->_insert(
$this->db->protectIdentifiers(
$this->QBFrom[0], true, $escape, false
), array_keys($this->QBSet), array_values($this->QBSet)
$this->db->protectIdentifiers(
$this->QBFrom[0],
true,
$escape,
false
),
array_keys($this->QBSet),
array_values($this->QBSet)
);
if (! $this->testMode) {
@ -2465,7 +2475,10 @@ class BaseBuilder
$savedQBWhere = $this->QBWhere;
for ($i = 0, $total = count($this->QBSet); $i < $total; $i += $batchSize) {
$sql = $this->_updateBatch($table, array_slice($this->QBSet, $i, $batchSize), $this->db->protectIdentifiers($index)
$sql = $this->_updateBatch(
$table,
array_slice($this->QBSet, $i, $batchSize),
$this->db->protectIdentifiers($index)
);
if ($this->testMode) {
@ -2920,7 +2933,10 @@ class BaseBuilder
// Split multiple conditions
$conditions = preg_split(
'/((?:^|\s+)AND\s+|(?:^|\s+)OR\s+)/i', $qbkey['condition'], -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY
'/((?:^|\s+)AND\s+|(?:^|\s+)OR\s+)/i',
$qbkey['condition'],
-1,
PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY
);
foreach ($conditions as &$condition) {

View File

@ -1352,15 +1352,18 @@ abstract class BaseConnection implements ConnectionInterface
// escape LIKE condition wildcards
if ($like === true) {
return str_replace([
$this->likeEscapeChar,
'%',
'_',
], [
$this->likeEscapeChar . $this->likeEscapeChar,
$this->likeEscapeChar . '%',
$this->likeEscapeChar . '_',
], $str
return str_replace(
[
$this->likeEscapeChar,
'%',
'_',
],
[
$this->likeEscapeChar . $this->likeEscapeChar,
$this->likeEscapeChar . '%',
$this->likeEscapeChar . '_',
],
$str
);
}

View File

@ -441,8 +441,11 @@ class Forge
*/
public function dropForeignKey(string $table, string $foreignName)
{
$sql = sprintf($this->dropConstraintStr, $this->db->escapeIdentifiers($this->db->DBPrefix . $table),
$this->db->escapeIdentifiers($this->db->DBPrefix . $foreignName));
$sql = sprintf(
$this->dropConstraintStr,
$this->db->escapeIdentifiers($this->db->DBPrefix . $table),
$this->db->escapeIdentifiers($this->db->DBPrefix . $foreignName)
);
if ($sql === false) { // @phpstan-ignore-line
if ($this->db->DBDebug) {
@ -557,8 +560,13 @@ class Forge
}
// createTableStr will usually have the following format: "%s %s (%s\n)"
$sql = sprintf($this->createTableStr . '%s', $sql, $this->db->escapeIdentifiers($table), $columns,
$this->_createTableAttributes($attributes));
$sql = sprintf(
$this->createTableStr . '%s',
$sql,
$this->db->escapeIdentifiers($table),
$columns,
$this->_createTableAttributes($attributes)
);
return $sql;
}
@ -625,8 +633,12 @@ class Forge
// Update table list cache
if ($query && ! empty($this->db->dataCache['table_names'])) {
$key = array_search(strtolower($this->db->DBPrefix . $tableName),
array_map('strtolower', $this->db->dataCache['table_names']), true);
$key = array_search(
strtolower($this->db->DBPrefix . $tableName),
array_map('strtolower', $this->db->dataCache['table_names']),
true
);
if ($key !== false) {
unset($this->db->dataCache['table_names'][$key]);
}
@ -691,14 +703,19 @@ class Forge
return false;
}
$result = $this->db->query(sprintf($this->renameTableStr,
$this->db->escapeIdentifiers($this->db->DBPrefix . $tableName),
$this->db->escapeIdentifiers($this->db->DBPrefix . $newTableName))
);
$result = $this->db->query(sprintf(
$this->renameTableStr,
$this->db->escapeIdentifiers($this->db->DBPrefix . $tableName),
$this->db->escapeIdentifiers($this->db->DBPrefix . $newTableName)
));
if ($result && ! empty($this->db->dataCache['table_names'])) {
$key = array_search(strtolower($this->db->DBPrefix . $tableName),
array_map('strtolower', $this->db->dataCache['table_names']), true);
$key = array_search(
strtolower($this->db->DBPrefix . $tableName),
array_map('strtolower', $this->db->dataCache['table_names']),
true
);
if ($key !== false) {
$this->db->dataCache['table_names'][$key] = $this->db->DBPrefix . $newTableName;
}

View File

@ -95,18 +95,21 @@ class Connection extends BaseConnection
if (isset($this->strictOn)) {
if ($this->strictOn) {
$this->mysqli->options(MYSQLI_INIT_COMMAND,
'SET SESSION sql_mode = CONCAT(@@sql_mode, ",", "STRICT_ALL_TABLES")');
$this->mysqli->options(
MYSQLI_INIT_COMMAND,
'SET SESSION sql_mode = CONCAT(@@sql_mode, ",", "STRICT_ALL_TABLES")'
);
} else {
$this->mysqli->options(MYSQLI_INIT_COMMAND, 'SET SESSION sql_mode =
REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(
@@sql_mode,
"STRICT_ALL_TABLES,", ""),
",STRICT_ALL_TABLES", ""),
"STRICT_ALL_TABLES", ""),
"STRICT_TRANS_TABLES,", ""),
",STRICT_TRANS_TABLES", ""),
"STRICT_TRANS_TABLES", "")'
$this->mysqli->options(
MYSQLI_INIT_COMMAND,
'SET SESSION sql_mode = REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(
@@sql_mode,
"STRICT_ALL_TABLES,", ""),
",STRICT_ALL_TABLES", ""),
"STRICT_ALL_TABLES", ""),
"STRICT_TRANS_TABLES,", ""),
",STRICT_TRANS_TABLES", ""),
"STRICT_TRANS_TABLES", "")'
);
}
}
@ -149,16 +152,25 @@ class Connection extends BaseConnection
$clientFlags += MYSQLI_CLIENT_SSL;
$this->mysqli->ssl_set(
$ssl['key'] ?? null, $ssl['cert'] ?? null, $ssl['ca'] ?? null,
$ssl['capath'] ?? null, $ssl['cipher'] ?? null
$ssl['key'] ?? null,
$ssl['cert'] ?? null,
$ssl['ca'] ?? null,
$ssl['capath'] ?? null,
$ssl['cipher'] ?? null
);
}
}
try {
if ($this->mysqli->real_connect($hostname, $this->username, $this->password,
$this->database, $port, $socket, $clientFlags)
) {
if ($this->mysqli->real_connect(
$hostname,
$this->username,
$this->password,
$this->database,
$port,
$socket,
$clientFlags
)) {
// Prior to version 5.7.3, MySQL silently downgrades to an unencrypted connection if SSL setup fails
if (($clientFlags & MYSQLI_CLIENT_SSL) && version_compare($this->mysqli->client_info, 'mysqlnd 5.7.3', '<=')
&& empty($this->mysqli->query("SHOW STATUS LIKE 'ssl_cipher'")
@ -176,8 +188,8 @@ class Connection extends BaseConnection
}
if (! $this->mysqli->set_charset($this->charset)) {
log_message('error',
"Database: Unable to set the configured connection charset ('{$this->charset}').");
log_message('error', "Database: Unable to set the configured connection charset ('{$this->charset}').");
$this->mysqli->close();
if ($this->DBDebug) {
@ -384,15 +396,10 @@ class Connection extends BaseConnection
$str = $this->_escapeString($str);
// Escape LIKE condition wildcards
return str_replace([
$this->likeEscapeChar,
'%',
'_',
], [
'\\' . $this->likeEscapeChar,
'\\' . '%',
'\\' . '_',
], $str
return str_replace(
[$this->likeEscapeChar, '%', '_'],
['\\' . $this->likeEscapeChar, '\\' . '%', '\\' . '_'],
$str
);
}

View File

@ -190,9 +190,8 @@ class Connection extends BaseConnection
return 'SELECT "NAME" FROM "SQLITE_MASTER" WHERE "TYPE" = \'table\''
. ' AND "NAME" NOT LIKE \'sqlite!_%\' ESCAPE \'!\''
. (($prefixLimit !== false && $this->DBPrefix !== '')
? ' AND "NAME" LIKE \'' . $this->escapeLikeString($this->DBPrefix) . '%\' ' . sprintf($this->likeEscapeStr,
$this->likeEscapeChar)
: '');
? ' AND "NAME" LIKE \'' . $this->escapeLikeString($this->DBPrefix) . '%\' ' . sprintf($this->likeEscapeStr, $this->likeEscapeChar)
: '');
}
//--------------------------------------------------------------------

View File

@ -478,7 +478,11 @@ class Exceptions
if (($n + $start + 1) === $lineNumber) {
preg_match_all('#<[^>]+>#', $row, $tags);
$out .= sprintf("<span class='line highlight'><span class='number'>{$format}</span> %s\n</span>%s", $n + $start + 1, strip_tags($row), implode('', $tags[0])
$out .= sprintf(
"<span class='line highlight'><span class='number'>{$format}</span> %s\n</span>%s",
$n + $start + 1,
strip_tags($row),
implode('', $tags[0])
);
} else {
$out .= sprintf('<span class="line"><span class="number">' . $format . '</span> %s', $n + $start + 1, $row) . "\n";

View File

@ -322,10 +322,10 @@ class Toolbar
$toolbar = Services::toolbar(config(Toolbar::class));
$stats = $app->getPerformanceStats();
$data = $toolbar->run(
$stats['startTime'],
$stats['totalTime'],
$request,
$response
$stats['startTime'],
$stats['totalTime'],
$request,
$response
);
helper('filesystem');

View File

@ -94,8 +94,7 @@
</tr>
</thead>
<tbody>
<?= $this->renderTimeline($collectors, $startTime, $segmentCount, $segmentDuration,
$styles) ?>
<?= $this->renderTimeline($collectors, $startTime, $segmentCount, $segmentDuration, $styles) ?>
</tbody>
</table>
</div>
@ -120,8 +119,7 @@
<?php if (isset($vars['varData'])) : ?>
<?php foreach ($vars['varData'] as $heading => $items) : ?>
<a href="javascript:void(0)" onclick="ciDebugBar.toggleDataTable('<?= strtolower(str_replace(' ',
'-', $heading)) ?>'); return false;">
<a href="javascript:void(0)" onclick="ciDebugBar.toggleDataTable('<?= strtolower(str_replace(' ', '-', $heading)) ?>'); return false;">
<h2><?= $heading ?></h2>
</a>

View File

@ -26,10 +26,12 @@ class JsonCast extends BaseCast
public static function get($value, array $params = [])
{
$associative = in_array('array', $params, true);
$tmp = ! is_null($value) ? ($associative ? [] : new stdClass) : null;
$tmp = ! is_null($value) ? ($associative ? [] : new stdClass) : null;
if (function_exists('json_decode')
&& ((is_string($value)
&& (
(is_string($value)
&& strlen($value) > 1
&& in_array($value[0], ['[', '{', '"'], true))
|| is_numeric($value)

View File

@ -196,7 +196,11 @@ class FileCollection
}
return new UploadedFile(
$array['tmp_name'] ?? null, $array['name'] ?? null, $array['type'] ?? null, $array['size'] ?? null, $array['error'] ?? null
$array['tmp_name'] ?? null,
$array['name'] ?? null,
$array['type'] ?? null,
$array['size'] ?? null,
$array['error'] ?? null
);
}

View File

@ -284,8 +284,10 @@ trait RequestTrait
// @phpstan-ignore-next-line
if (is_array($value)
&& ($filter !== FILTER_DEFAULT
|| ((is_numeric($flags) && $flags !== 0)
&& (
$filter !== FILTER_DEFAULT
|| (
(is_numeric($flags) && $flags !== 0)
|| is_array($flags) && count($flags) > 0
)
)

View File

@ -667,8 +667,11 @@ class URI
}
return static::createURIString(
$scheme, $this->getAuthority(), $path, // Absolute URIs should use a "/" for an empty path
$this->getQuery(), $this->getFragment()
$scheme,
$this->getAuthority(),
$path, // Absolute URIs should use a "/" for an empty path
$this->getQuery(),
$this->getFragment()
);
}
@ -984,9 +987,11 @@ class URI
// Encode characters
$path = preg_replace_callback(
'/(?:[^' . static::CHAR_UNRESERVED . ':@&=\+\$,\/;%]+|%(?![A-Fa-f0-9]{2}))/', static function (array $matches) {
return rawurlencode($matches[0]);
}, $path
'/(?:[^' . static::CHAR_UNRESERVED . ':@&=\+\$,\/;%]+|%(?![A-Fa-f0-9]{2}))/',
static function (array $matches) {
return rawurlencode($matches[0]);
},
$path
);
return $path;

View File

@ -225,9 +225,9 @@ if (! function_exists('get_filenames')) {
try {
foreach (new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($sourceDir, RecursiveDirectoryIterator::SKIP_DOTS),
RecursiveIteratorIterator::SELF_FIRST
) as $name => $object) {
new RecursiveDirectoryIterator($sourceDir, RecursiveDirectoryIterator::SKIP_DOTS),
RecursiveIteratorIterator::SELF_FIRST
) as $name => $object) {
$basename = pathinfo($name, PATHINFO_BASENAME);
if (! $hidden && $basename[0] === '.') {
continue;

View File

@ -228,10 +228,7 @@ if (! function_exists('humanize')) {
{
$replacement = trim($string);
return ucwords
(
preg_replace('/[' . $separator . ']+/', ' ', $replacement)
);
return ucwords(preg_replace('/[' . $separator . ']+/', ' ', $replacement));
}
}
@ -247,9 +244,9 @@ if (! function_exists('is_pluralizable')) {
*/
function is_pluralizable(string $word): bool
{
$uncountables = in_array
(
strtolower($word), [
$uncountables = in_array(
strtolower($word),
[
'advice',
'bravery',
'butter',
@ -296,7 +293,9 @@ if (! function_exists('is_pluralizable')) {
'weather',
'wisdom',
'work',
], true);
],
true
);
return ! $uncountables;
}

View File

@ -41,10 +41,13 @@ if (! function_exists('strip_image_tags')) {
*/
function strip_image_tags(string $str): string
{
return preg_replace([
'#<img[\s/]+.*?src\s*=\s*(["\'])([^\\1]+?)\\1.*?\>#i',
'#<img[\s/]+.*?src\s*=\s*?(([^\s"\'=<>`]+)).*?\>#i',
], '\\2', $str
return preg_replace(
[
'#<img[\s/]+.*?src\s*=\s*(["\'])([^\\1]+?)\\1.*?\>#i',
'#<img[\s/]+.*?src\s*=\s*?(([^\s"\'=<>`]+)).*?\>#i',
],
'\\2',
$str
);
}
}

View File

@ -173,21 +173,10 @@ if (! function_exists('entities_to_ascii')) {
}
if ($all) {
return str_replace([
'&amp;',
'&lt;',
'&gt;',
'&quot;',
'&apos;',
'&#45;',
], [
'&',
'<',
'>',
'"',
"'",
'-',
], $str
return str_replace(
['&amp;', '&lt;', '&gt;', '&quot;', '&apos;', '&#45;'],
['&', '<', '>', '"', "'", '-'],
$str
);
}
@ -230,15 +219,21 @@ if (! function_exists('word_censor')) {
if ($replacement !== '') {
$str = preg_replace(
"/({$delim})(" . $badword . ")({$delim})/i", "\\1{$replacement}\\3", $str
"/({$delim})(" . $badword . ")({$delim})/i",
"\\1{$replacement}\\3",
$str
);
} 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--) {
$length = strlen($matches[$i][0]);
$str = substr_replace(
$str, str_repeat('#', $length), $matches[$i][1], $length
$str = substr_replace(
$str,
str_repeat('#', $length),
$matches[$i][1],
$length
);
}
}
@ -269,25 +264,10 @@ if (! function_exists('highlight_code')) {
* so they don't accidentally break the string out of PHP,
* and thus, thwart the highlighting.
*/
$str = str_replace([
'&lt;',
'&gt;',
'<?',
'?>',
'<%',
'%>',
'\\',
'</script>',
], [
'<',
'>',
'phptagopen',
'phptagclose',
'asptagopen',
'asptagclose',
'backslashtmp',
'scriptclose',
], $str
$str = str_replace(
['&lt;', '&gt;', '<?', '?>', '<%', '%>', '\\', '</script>'],
['<', '>', 'phptagopen', 'phptagclose', 'asptagopen', 'asptagclose', 'backslashtmp', 'scriptclose'],
$str
);
// The highlight_string function requires that the text be surrounded
@ -295,33 +275,39 @@ if (! function_exists('highlight_code')) {
$str = highlight_string('<?php ' . $str . ' ?>', true);
// Remove our artificially added PHP, and the syntax highlighting that came with it
$str = preg_replace([
'/<span style="color: #([A-Z0-9]+)">&lt;\?php(&nbsp;| )/i',
'/(<span style="color: #[A-Z0-9]+">.*?)\?&gt;<\/span>\n<\/span>\n<\/code>/is',
'/<span style="color: #[A-Z0-9]+"\><\/span>/i',
], [
'<span style="color: #$1">',
"$1</span>\n</span>\n</code>",
'',
], $str
$str = preg_replace(
[
'/<span style="color: #([A-Z0-9]+)">&lt;\?php(&nbsp;| )/i',
'/(<span style="color: #[A-Z0-9]+">.*?)\?&gt;<\/span>\n<\/span>\n<\/code>/is',
'/<span style="color: #[A-Z0-9]+"\><\/span>/i',
],
[
'<span style="color: #$1">',
"$1</span>\n</span>\n</code>",
'',
],
$str
);
// Replace our markers back to PHP tags.
return str_replace([
'phptagopen',
'phptagclose',
'asptagopen',
'asptagclose',
'backslashtmp',
'scriptclose',
], [
'&lt;?',
'?&gt;',
'&lt;%',
'%&gt;',
'\\',
'&lt;/script&gt;',
], $str
return str_replace(
[
'phptagopen',
'phptagclose',
'asptagopen',
'asptagclose',
'backslashtmp',
'scriptclose',
],
[
'&lt;?',
'?&gt;',
'&lt;%',
'%&gt;',
'\\',
'&lt;/script&gt;',
],
$str
);
}
}

View File

@ -353,7 +353,8 @@ class GDHandler extends BaseHandler
if ($this->resource === null) {
// if valid image type, make corresponding image resource
$this->resource = $this->getImageResource(
$this->image()->getPathname(), $this->image()->imageType
$this->image()->getPathname(),
$this->image()->imageType
);
}
}

View File

@ -610,11 +610,10 @@ class Model extends BaseModel
{
// When useAutoIncrement feature is disabled check
// in the database if given record already exists
return parent::shouldUpdate($data) &&
($this->useAutoIncrement
return parent::shouldUpdate($data)
&& $this->useAutoIncrement
? true
: $this->where($this->primaryKey, $this->getIdValue($data))->countAllResults() === 1
);
: $this->where($this->primaryKey, $this->getIdValue($data))->countAllResults() === 1;
}
/**

View File

@ -1367,9 +1367,12 @@ class RouteCollection implements RouteCollectionInterface
for ($i = (int) $options['offset'] + 1; $i < (int) $options['offset'] + 7; $i++) {
$to = preg_replace_callback(
'/\$X/', static function ($m) use ($i) {
return '$' . $i;
}, $to, 1
'/\$X/',
static function ($m) use ($i) {
return '$' . $i;
},
$to,
1
);
}
}

View File

@ -131,7 +131,13 @@ abstract class BaseHandler implements SessionHandlerInterface
protected function destroyCookie(): bool
{
return setcookie(
$this->cookieName, '', 1, $this->cookiePath, $this->cookieDomain, $this->cookieSecure, true
$this->cookieName,
'',
1,
$this->cookiePath,
$this->cookieDomain,
$this->cookieSecure,
true
);
}

View File

@ -62,7 +62,9 @@ class SeeInDatabase extends Constraint
{
return sprintf(
"a row in the table [%s] matches the attributes \n%s\n\n%s",
$table, $this->toString(JSON_PRETTY_PRINT), $this->getAdditionalInfo($table)
$table,
$this->toString(JSON_PRETTY_PRINT),
$this->getAdditionalInfo($table)
);
}
@ -78,10 +80,9 @@ class SeeInDatabase extends Constraint
$builder = $this->db->table($table);
$similar = $builder->where(
array_key_first($this->data),
$this->data[array_key_first($this->data)]
)->limit($this->show)
->get()->getResultArray();
array_key_first($this->data),
$this->data[array_key_first($this->data)]
)->limit($this->show)->get()->getResultArray();
if ($similar !== []) {
$description = 'Found similar results: ' . json_encode($similar, JSON_PRETTY_PRINT);

View File

@ -309,7 +309,10 @@ class Parser extends View
// have something to loop over.
preg_match_all(
'#' . $this->leftDelimiter . '\s*' . preg_quote($variable, '#') . '\s*' . $this->rightDelimiter . '(.+?)' .
$this->leftDelimiter . '\s*' . '/' . preg_quote($variable, '#') . '\s*' . $this->rightDelimiter . '#s', $template, $matches, PREG_SET_ORDER
$this->leftDelimiter . '\s*' . '/' . preg_quote($variable, '#') . '\s*' . $this->rightDelimiter . '#s',
$template,
$matches,
PREG_SET_ORDER
);
/*

View File

@ -201,10 +201,11 @@ class FileLocatorTest extends CIUnitTestCase
{
$foundFiles = $this->locator->search('Language/en/Validation.php', 'php', false);
$this->assertEquals([
SYSTEMPATH . 'Language/en/Validation.php',
APPPATH . 'Language/en/Validation.php',
],
$this->assertEquals(
[
SYSTEMPATH . 'Language/en/Validation.php',
APPPATH . 'Language/en/Validation.php',
],
$foundFiles
);
}

View File

@ -102,7 +102,8 @@ class CommonFunctionsTest extends CIUnitTestCase
$response = $this->createMock(Response::class);
$routes = new RouteCollection(
Services::locator(), new Modules()
Services::locator(),
new Modules()
);
\CodeIgniter\Services::injectMock('response', $response);
\CodeIgniter\Services::injectMock('routes', $routes);

View File

@ -76,7 +76,7 @@ class ConnectTest extends CIUnitTestCase
$config = config('Database');
$config->default['DBDriver'] = 'MySQLi';
Factories::injectMock('config','Database', $config);
Factories::injectMock('config', 'Database', $config);
$db1 = Database::connect('default');
$this->assertNotInstanceOf(Connection::class, $db1);

View File

@ -22,8 +22,12 @@ class TimeTest extends CIUnitTestCase
public function testNewTimeNow()
{
$formatter = new IntlDateFormatter(
'en_US', IntlDateFormatter::SHORT, IntlDateFormatter::SHORT, 'America/Chicago', // Default for CodeIgniter
IntlDateFormatter::GREGORIAN, 'yyyy-MM-dd HH:mm:ss'
'en_US',
IntlDateFormatter::SHORT,
IntlDateFormatter::SHORT,
'America/Chicago', // Default for CodeIgniter
IntlDateFormatter::GREGORIAN,
'yyyy-MM-dd HH:mm:ss'
);
$time = new Time(null, 'America/Chicago');
@ -34,8 +38,12 @@ class TimeTest extends CIUnitTestCase
public function testTimeWithTimezone()
{
$formatter = new IntlDateFormatter(
'en_US', IntlDateFormatter::SHORT, IntlDateFormatter::SHORT, 'Europe/London', // Default for CodeIgniter
IntlDateFormatter::GREGORIAN, 'yyyy-MM-dd HH:mm:ss'
'en_US',
IntlDateFormatter::SHORT,
IntlDateFormatter::SHORT,
'Europe/London', // Default for CodeIgniter
IntlDateFormatter::GREGORIAN,
'yyyy-MM-dd HH:mm:ss'
);
$time = new Time('now', 'Europe/London');
@ -46,8 +54,12 @@ class TimeTest extends CIUnitTestCase
public function testTimeWithTimezoneAndLocale()
{
$formatter = new IntlDateFormatter(
'fr_FR', IntlDateFormatter::SHORT, IntlDateFormatter::SHORT, 'Europe/London', // Default for CodeIgniter
IntlDateFormatter::GREGORIAN, 'yyyy-MM-dd HH:mm:ss'
'fr_FR',
IntlDateFormatter::SHORT,
IntlDateFormatter::SHORT,
'Europe/London', // Default for CodeIgniter
IntlDateFormatter::GREGORIAN,
'yyyy-MM-dd HH:mm:ss'
);
$time = new Time('now', 'Europe/London', 'fr_FR');
@ -58,7 +70,12 @@ class TimeTest extends CIUnitTestCase
public function testTimeWithDateTimeZone()
{
$formatter = new IntlDateFormatter(
'fr_FR', IntlDateFormatter::SHORT, IntlDateFormatter::SHORT, 'Europe/London', IntlDateFormatter::GREGORIAN, 'yyyy-MM-dd HH:mm:ss'
'fr_FR',
IntlDateFormatter::SHORT,
IntlDateFormatter::SHORT,
'Europe/London',
IntlDateFormatter::GREGORIAN,
'yyyy-MM-dd HH:mm:ss'
);
$time = new Time('now', new \DateTimeZone('Europe/London'), 'fr_FR');

View File

@ -318,16 +318,16 @@ class PagerTest extends CIUnitTestCase
$uri = current_url(true);
$this->assertEquals(
$this->pager->only($onlyQueries)
->getPreviousPageURI(), (string) $uri->setQuery('search=foo&order=asc&page=1')
$this->pager->only($onlyQueries)->getPreviousPageURI(),
(string) $uri->setQuery('search=foo&order=asc&page=1')
);
$this->assertEquals(
$this->pager->only($onlyQueries)
->getNextPageURI(), (string) $uri->setQuery('search=foo&order=asc&page=3')
$this->pager->only($onlyQueries)->getNextPageURI(),
(string) $uri->setQuery('search=foo&order=asc&page=3')
);
$this->assertEquals(
$this->pager->only($onlyQueries)
->getPageURI(4), (string) $uri->setQuery('search=foo&order=asc&page=4')
$this->pager->only($onlyQueries)->getPageURI(4),
(string) $uri->setQuery('search=foo&order=asc&page=4')
);
}
@ -353,37 +353,48 @@ class PagerTest extends CIUnitTestCase
public function testMakeLinks()
{
$this->assertStringContainsString(
'<ul class="pagination">', $this->pager->makeLinks(4, 10, 50)
'<ul class="pagination">',
$this->pager->makeLinks(4, 10, 50)
);
$this->assertStringContainsString(
'<ul class="pagination">', $this->pager->makeLinks(4, 10, 50, 'default_full')
'<ul class="pagination">',
$this->pager->makeLinks(4, 10, 50, 'default_full')
);
$this->assertStringContainsString(
'<ul class="pager">', $this->pager->makeLinks(4, 10, 50, 'default_simple')
'<ul class="pager">',
$this->pager->makeLinks(4, 10, 50, 'default_simple')
);
$this->assertStringContainsString(
'<link rel="canonical"', $this->pager->makeLinks(4, 10, 50, 'default_head')
'<link rel="canonical"',
$this->pager->makeLinks(4, 10, 50, 'default_head')
);
$this->assertStringContainsString(
'?page=1', $this->pager->makeLinks(1, 10, 1, 'default_full', 0)
'?page=1',
$this->pager->makeLinks(1, 10, 1, 'default_full', 0)
);
$this->assertStringContainsString(
'?page=1', $this->pager->makeLinks(1, 10, 1, 'default_full', 0, '')
'?page=1',
$this->pager->makeLinks(1, 10, 1, 'default_full', 0, '')
);
$this->assertStringContainsString(
'?page=1', $this->pager->makeLinks(1, 10, 1, 'default_full', 0, 'default')
'?page=1',
$this->pager->makeLinks(1, 10, 1, 'default_full', 0, 'default')
);
$this->assertStringContainsString(
'?page_custom=1', $this->pager->makeLinks(1, 10, 1, 'default_full', 0, 'custom')
'?page_custom=1',
$this->pager->makeLinks(1, 10, 1, 'default_full', 0, 'custom')
);
$this->assertStringContainsString(
'?page_custom=1', $this->pager->makeLinks(1, null, 1, 'default_full', 0, 'custom')
'?page_custom=1',
$this->pager->makeLinks(1, null, 1, 'default_full', 0, 'custom')
);
$this->assertStringContainsString(
'/1', $this->pager->makeLinks(1, 10, 1, 'default_full', 1)
'/1',
$this->pager->makeLinks(1, 10, 1, 'default_full', 1)
);
$this->assertStringContainsString(
'<li class="active">', $this->pager->makeLinks(1, 10, 1, 'default_full', 1)
'<li class="active">',
$this->pager->makeLinks(1, 10, 1, 'default_full', 1)
);
}

View File

@ -257,9 +257,10 @@ class RouteCollectionTest extends CIUnitTestCase
$routes = $this->getCollector();
$routes->group(
'admin', static function ($routes) {
$routes->add('users/list', '\Users::list');
}
'admin',
static function ($routes) {
$routes->add('users/list', '\Users::list');
}
);
$expected = [
@ -276,9 +277,10 @@ class RouteCollectionTest extends CIUnitTestCase
$routes = $this->getCollector();
$routes->group(
'<script>admin', static function ($routes) {
$routes->add('users/list', '\Users::list');
}
'<script>admin',
static function ($routes) {
$routes->add('users/list', '\Users::list');
}
);
$expected = [
@ -295,9 +297,11 @@ class RouteCollectionTest extends CIUnitTestCase
$routes = $this->getCollector();
$routes->group(
'admin', ['namespace' => 'Admin'], static function ($routes) {
$routes->add('users/list', 'Users::list');
}
'admin',
['namespace' => 'Admin'],
static function ($routes) {
$routes->add('users/list', 'Users::list');
}
);
$expected = [
@ -314,9 +318,10 @@ class RouteCollectionTest extends CIUnitTestCase
$routes = $this->getCollector();
$routes->group(
'', static function ($routes) {
$routes->add('users/list', '\Users::list');
}
'',
static function ($routes) {
$routes->add('users/list', '\Users::list');
}
);
$expected = [
@ -336,13 +341,15 @@ class RouteCollectionTest extends CIUnitTestCase
$routes->group('admin', static function ($routes) {
$routes->group(
'', static function ($routes) {
'',
static function ($routes) {
$routes->add('users/list', '\Users::list');
$routes->group('delegate', static function ($routes) {
$routes->add('foo', '\Users::foo');
});
});
}
);
});
$expected = [
@ -794,15 +801,17 @@ class RouteCollectionTest extends CIUnitTestCase
$expected = ['here' => '\there'];
$routes->environment(
'testing', static function ($routes) {
$routes->get('here', 'there');
}
'testing',
static function ($routes) {
$routes->get('here', 'there');
}
);
$routes->environment(
'badenvironment', static function ($routes) {
$routes->get('from', 'to');
}
'badenvironment',
static function ($routes) {
$routes->get('from', 'to');
}
);
$this->assertEquals($expected, $routes->getRoutes());
@ -938,12 +947,14 @@ class RouteCollectionTest extends CIUnitTestCase
$routes->get('user/insert', 'myController::goto/$1/$2', ['as' => 'namedRoute1']);
$routes->post(
'user/insert', static function () {
}, ['as' => 'namedRoute2']
'user/insert',
static function () {},
['as' => 'namedRoute2']
);
$routes->put(
'user/insert', static function () {
}, ['as' => 'namedRoute3']
'user/insert',
static function () {},
['as' => 'namedRoute3']
);
$match1 = $routes->reverseRoute('namedRoute1');
@ -1286,8 +1297,9 @@ class RouteCollectionTest extends CIUnitTestCase
'foo' => 'baz',
];
$routes->add(
'administrator', static function () {
}, $options
'administrator',
static function () {},
$options
);
$options = $routes->getRoutesOptions('administrator');
@ -1312,16 +1324,19 @@ class RouteCollectionTest extends CIUnitTestCase
'bar' => 'baz',
];
$routes->get(
'administrator', static function () {
}, $options1
'administrator',
static function () {},
$options1
);
$routes->post(
'administrator', static function () {
}, $options2
'administrator',
static function () {},
$options2
);
$routes->add(
'administrator', static function () {
}, $options3
'administrator',
static function () {},
$options3
);
$options = $routes->getRoutesOptions('administrator');
@ -1343,9 +1358,11 @@ class RouteCollectionTest extends CIUnitTestCase
$routes = $this->getCollector();
$routes->group(
'admin', ['filter' => 'role'], static function ($routes) {
$routes->add('users', '\Users::list');
}
'admin',
['filter' => 'role'],
static function ($routes) {
$routes->add('users', '\Users::list');
}
);
$this->assertTrue($routes->isFiltered('admin/users'));
@ -1360,9 +1377,11 @@ class RouteCollectionTest extends CIUnitTestCase
$routes = $this->getCollector();
$routes->group(
'admin', ['filter' => 'role:admin,manager'], static function ($routes) {
$routes->add('users', '\Users::list');
}
'admin',
['filter' => 'role:admin,manager'],
static function ($routes) {
$routes->add('users', '\Users::list');
}
);
$this->assertTrue($routes->isFiltered('admin/users'));
@ -1396,8 +1415,7 @@ class RouteCollectionTest extends CIUnitTestCase
$routes->set404Override(static function () {
echo 'Explode now';
}
);
});
$this->assertTrue(is_callable($routes->get404Override()));
}

View File

@ -258,10 +258,11 @@ class SessionTest extends CIUnitTestCase
$session->set('hobbies', ['cooking' => 'baking']);
$session->push('hobbies', ['sport' => 'tennis']);
$this->assertEquals([
'cooking' => 'baking',
'sport' => 'tennis',
],
$this->assertEquals(
[
'cooking' => 'baking',
'sport' => 'tennis',
],
$session->get('hobbies')
);
}

View File

@ -21,7 +21,8 @@ class ReflectionHelperTest extends CIUnitTestCase
public function testGetPrivatePropertyWithStatic()
{
$actual = $this->getPrivateProperty(
__TestForReflectionHelper::class, 'static_private'
__TestForReflectionHelper::class,
'static_private'
);
$this->assertEquals('xyz', $actual);
}
@ -30,7 +31,9 @@ class ReflectionHelperTest extends CIUnitTestCase
{
$obj = new __TestForReflectionHelper();
$this->setPrivateProperty(
$obj, 'private', 'open'
$obj,
'private',
'open'
);
$this->assertEquals('open', $obj->getPrivate());
}
@ -38,10 +41,13 @@ class ReflectionHelperTest extends CIUnitTestCase
public function testSetPrivatePropertyWithStatic()
{
$this->setPrivateProperty(
__TestForReflectionHelper::class, 'static_private', 'abc'
__TestForReflectionHelper::class,
'static_private',
'abc'
);
$this->assertEquals(
'abc', __TestForReflectionHelper::getStaticPrivate()
'abc',
__TestForReflectionHelper::getStaticPrivate()
);
}
@ -49,20 +55,24 @@ class ReflectionHelperTest extends CIUnitTestCase
{
$obj = new __TestForReflectionHelper();
$method = $this->getPrivateMethodInvoker(
$obj, 'privateMethod'
$obj,
'privateMethod'
);
$this->assertEquals(
'private param1param2', $method('param1', 'param2')
'private param1param2',
$method('param1', 'param2')
);
}
public function testGetPrivateMethodInvokerWithStatic()
{
$method = $this->getPrivateMethodInvoker(
__TestForReflectionHelper::class, 'privateStaticMethod'
__TestForReflectionHelper::class,
'privateStaticMethod'
);
$this->assertEquals(
'private_static param1param2', $method('param1', 'param2')
'private_static param1param2',
$method('param1', 'param2')
);
}
}

View File

@ -50,12 +50,13 @@ class TableTest extends CIUnitTestCase
$this->table->setHeading('name', 'color', 'size');
$this->assertEquals([
['data' => 'name'],
['data' => 'color'],
['data' => 'size'],
],
$this->table->heading
$this->assertEquals(
[
['data' => 'name'],
['data' => 'color'],
['data' => 'size'],
],
$this->table->heading
);
}
@ -69,11 +70,12 @@ class TableTest extends CIUnitTestCase
$this->table->setFooting('Subtotal', $subtotal);
$this->assertEquals([
['data' => 'Subtotal'],
['data' => $subtotal],
],
$this->table->footing
$this->assertEquals(
[
['data' => 'Subtotal'],
['data' => $subtotal],
],
$this->table->footing
);
}
@ -92,12 +94,13 @@ class TableTest extends CIUnitTestCase
$this->assertCount(3, $this->table->rows);
$this->assertEquals([
['data' => 'your'],
['data' => 'pony'],
['data' => 'stinks'],
],
$this->table->rows[1]
$this->assertEquals(
[
['data' => 'your'],
['data' => 'pony'],
['data' => 'stinks'],
],
$this->table->rows[1]
);
}
@ -113,8 +116,8 @@ class TableTest extends CIUnitTestCase
];
$this->assertEquals(
$expected,
$this->table->prepArgs(['name', 'color', 'size'])
$expected,
$this->table->prepArgs(['name', 'color', 'size'])
);
// with cell attributes
@ -125,8 +128,8 @@ class TableTest extends CIUnitTestCase
];
$this->assertEquals(
$expected,
$this->table->prepArgs(['name', 'color', 'size', ['data' => 'weight', 'class' => 'awesome']])
$expected,
$this->table->prepArgs(['name', 'color', 'size', ['data' => 'weight', 'class' => 'awesome']])
);
}
@ -196,24 +199,17 @@ class TableTest extends CIUnitTestCase
// No column count - no changes to the array
$this->assertEquals(
$fiveValues,
$this->table->makeColumns($fiveValues)
$fiveValues,
$this->table->makeColumns($fiveValues)
);
// Column count of 3 leaves us with one &nbsp;
$this->assertEquals([
$this->assertEquals(
[
'Laura',
'Red',
'15',
['Laura', 'Red', '15'],
['Katie', 'Blue', '&nbsp;'],
],
[
'Katie',
'Blue',
'&nbsp;',
],
],
$this->table->makeColumns($fiveValues, 3)
$this->table->makeColumns($fiveValues, 3)
);
}

View File

@ -89,25 +89,30 @@ final class CodeIgniter4 extends AbstractRuleset
'phpstan-ignore-next-line',
],
],
'compact_nullable_typehint' => true,
'concat_space' => ['spacing' => 'one'],
'constant_case' => ['case' => 'lower'],
'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,
'linebreak_after_opening_tag' => true,
'list_syntax' => ['syntax' => 'short'],
'logical_operators' => true,
'lowercase_cast' => true,
'lowercase_keywords' => true,
'lowercase_static_reference' => true,
'magic_constant_casing' => true,
'magic_method_casing' => true,
'mb_str_functions' => false,
'compact_nullable_typehint' => true,
'concat_space' => ['spacing' => 'one'],
'constant_case' => ['case' => 'lower'],
'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,
'linebreak_after_opening_tag' => true,
'list_syntax' => ['syntax' => 'short'],
'logical_operators' => true,
'lowercase_cast' => true,
'lowercase_keywords' => true,
'lowercase_static_reference' => true,
'magic_constant_casing' => true,
'magic_method_casing' => true,
'mb_str_functions' => false,
'method_argument_space' => [
'after_heredoc' => false,
'keep_multiple_spaces_after_comma' => false,
'on_multiline' => 'ensure_fully_multiline',
],
'modernize_types_casting' => true,
'multiline_comment_opening_closing' => true,
'multiline_whitespace_before_semicolons' => ['strategy' => 'no_multi_line'],