mirror of
https://github.com/codeigniter4/CodeIgniter4.git
synced 2025-02-20 11:44:28 +08:00
refactor: Use strtolower
with str_contains
/str_**_with
as replacement for stripos
(#9414)
* Use `modernize_stripos` option * Fix impossible conditional in test
This commit is contained in:
parent
512cd924c8
commit
119330c56f
@ -40,17 +40,7 @@ $finder = Finder::create()
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
$overrides = [
|
$overrides = [
|
||||||
'get_class_to_class_keyword' => true,
|
'modernize_strpos' => ['modernize_stripos' => true],
|
||||||
'trailing_comma_in_multiline' => [
|
|
||||||
'after_heredoc' => true,
|
|
||||||
'elements' => [
|
|
||||||
'arguments',
|
|
||||||
'array_destructuring',
|
|
||||||
'arrays',
|
|
||||||
'match',
|
|
||||||
'parameters',
|
|
||||||
],
|
|
||||||
],
|
|
||||||
];
|
];
|
||||||
|
|
||||||
$options = [
|
$options = [
|
||||||
|
@ -1061,7 +1061,7 @@ class Forge
|
|||||||
protected function _attributeAutoIncrement(array &$attributes, array &$field)
|
protected function _attributeAutoIncrement(array &$attributes, array &$field)
|
||||||
{
|
{
|
||||||
if (! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === true
|
if (! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === true
|
||||||
&& stripos($field['type'], 'int') !== false
|
&& str_contains(strtolower($field['type']), 'int')
|
||||||
) {
|
) {
|
||||||
$field['auto_increment'] = ' AUTO_INCREMENT';
|
$field['auto_increment'] = ' AUTO_INCREMENT';
|
||||||
}
|
}
|
||||||
|
@ -184,7 +184,7 @@ class Forge extends BaseForge
|
|||||||
protected function _attributeAutoIncrement(array &$attributes, array &$field)
|
protected function _attributeAutoIncrement(array &$attributes, array &$field)
|
||||||
{
|
{
|
||||||
if (! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === true
|
if (! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === true
|
||||||
&& stripos($field['type'], 'NUMBER') !== false
|
&& str_contains(strtolower($field['type']), 'number')
|
||||||
&& version_compare($this->db->getVersion(), '12.1', '>=')
|
&& version_compare($this->db->getVersion(), '12.1', '>=')
|
||||||
) {
|
) {
|
||||||
$field['auto_increment'] = ' GENERATED BY DEFAULT ON NULL AS IDENTITY';
|
$field['auto_increment'] = ' GENERATED BY DEFAULT ON NULL AS IDENTITY';
|
||||||
|
@ -154,7 +154,7 @@ class Forge extends BaseForge
|
|||||||
protected function _attributeType(array &$attributes)
|
protected function _attributeType(array &$attributes)
|
||||||
{
|
{
|
||||||
// Reset field lengths for data types that don't support it
|
// Reset field lengths for data types that don't support it
|
||||||
if (isset($attributes['CONSTRAINT']) && stripos($attributes['TYPE'], 'int') !== false) {
|
if (isset($attributes['CONSTRAINT']) && str_contains(strtolower($attributes['TYPE']), 'int')) {
|
||||||
$attributes['CONSTRAINT'] = null;
|
$attributes['CONSTRAINT'] = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -360,7 +360,7 @@ class Forge extends BaseForge
|
|||||||
protected function _attributeType(array &$attributes)
|
protected function _attributeType(array &$attributes)
|
||||||
{
|
{
|
||||||
// Reset field lengths for data types that don't support it
|
// Reset field lengths for data types that don't support it
|
||||||
if (isset($attributes['CONSTRAINT']) && stripos($attributes['TYPE'], 'int') !== false) {
|
if (isset($attributes['CONSTRAINT']) && str_contains(strtolower($attributes['TYPE']), 'int')) {
|
||||||
$attributes['CONSTRAINT'] = null;
|
$attributes['CONSTRAINT'] = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -412,7 +412,7 @@ class Forge extends BaseForge
|
|||||||
*/
|
*/
|
||||||
protected function _attributeAutoIncrement(array &$attributes, array &$field)
|
protected function _attributeAutoIncrement(array &$attributes, array &$field)
|
||||||
{
|
{
|
||||||
if (! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === true && stripos($field['type'], 'INT') !== false) {
|
if (! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === true && str_contains(strtolower($field['type']), strtolower('INT'))) {
|
||||||
$field['auto_increment'] = ' IDENTITY(1,1)';
|
$field['auto_increment'] = ' IDENTITY(1,1)';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -226,7 +226,7 @@ class Forge extends BaseForge
|
|||||||
if (
|
if (
|
||||||
! empty($attributes['AUTO_INCREMENT'])
|
! empty($attributes['AUTO_INCREMENT'])
|
||||||
&& $attributes['AUTO_INCREMENT'] === true
|
&& $attributes['AUTO_INCREMENT'] === true
|
||||||
&& stripos($field['type'], 'int') !== false
|
&& str_contains(strtolower($field['type']), 'int')
|
||||||
) {
|
) {
|
||||||
$field['type'] = 'INTEGER PRIMARY KEY';
|
$field['type'] = 'INTEGER PRIMARY KEY';
|
||||||
$field['default'] = '';
|
$field['default'] = '';
|
||||||
|
@ -49,10 +49,10 @@ if (! function_exists('form_open')) {
|
|||||||
|
|
||||||
$attributes = stringify_attributes($attributes);
|
$attributes = stringify_attributes($attributes);
|
||||||
|
|
||||||
if (stripos($attributes, 'method=') === false) {
|
if (! str_contains(strtolower($attributes), 'method=')) {
|
||||||
$attributes .= ' method="post"';
|
$attributes .= ' method="post"';
|
||||||
}
|
}
|
||||||
if (stripos($attributes, 'accept-charset=') === false) {
|
if (! str_contains(strtolower($attributes), 'accept-charset=')) {
|
||||||
$config = config(App::class);
|
$config = config(App::class);
|
||||||
$attributes .= ' accept-charset="' . strtolower($config->charset) . '"';
|
$attributes .= ' accept-charset="' . strtolower($config->charset) . '"';
|
||||||
}
|
}
|
||||||
@ -62,7 +62,7 @@ if (! function_exists('form_open')) {
|
|||||||
// Add CSRF field if enabled, but leave it out for GET requests and requests to external websites
|
// Add CSRF field if enabled, but leave it out for GET requests and requests to external websites
|
||||||
$before = service('filters')->getFilters()['before'];
|
$before = service('filters')->getFilters()['before'];
|
||||||
|
|
||||||
if ((in_array('csrf', $before, true) || array_key_exists('csrf', $before)) && str_contains($action, base_url()) && stripos($form, 'method="get"') === false) {
|
if ((in_array('csrf', $before, true) || array_key_exists('csrf', $before)) && str_contains($action, base_url()) && ! str_contains(strtolower($form), strtolower('method="get"'))) {
|
||||||
$form .= csrf_field($csrfId ?? null);
|
$form .= csrf_field($csrfId ?? null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -223,11 +223,11 @@ if (! function_exists('form_textarea')) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Unsets default rows and cols if defined in extra field as array or string.
|
// Unsets default rows and cols if defined in extra field as array or string.
|
||||||
if ((is_array($extra) && array_key_exists('rows', $extra)) || (is_string($extra) && stripos(preg_replace('/\s+/', '', $extra), 'rows=') !== false)) {
|
if ((is_array($extra) && array_key_exists('rows', $extra)) || (is_string($extra) && str_contains(strtolower(preg_replace('/\s+/', '', $extra)), 'rows='))) {
|
||||||
unset($defaults['rows']);
|
unset($defaults['rows']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((is_array($extra) && array_key_exists('cols', $extra)) || (is_string($extra) && stripos(preg_replace('/\s+/', '', $extra), 'cols=') !== false)) {
|
if ((is_array($extra) && array_key_exists('cols', $extra)) || (is_string($extra) && str_contains(strtolower(preg_replace('/\s+/', '', $extra)), 'cols='))) {
|
||||||
unset($defaults['cols']);
|
unset($defaults['cols']);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -248,7 +248,7 @@ if (! function_exists('form_multiselect')) {
|
|||||||
{
|
{
|
||||||
$extra = stringify_attributes($extra);
|
$extra = stringify_attributes($extra);
|
||||||
|
|
||||||
if (stripos($extra, 'multiple') === false) {
|
if (! str_contains(strtolower($extra), strtolower('multiple'))) {
|
||||||
$extra .= ' multiple="multiple"';
|
$extra .= ' multiple="multiple"';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -305,7 +305,7 @@ if (! function_exists('form_dropdown')) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$extra = stringify_attributes($extra);
|
$extra = stringify_attributes($extra);
|
||||||
$multiple = (count($selected) > 1 && stripos($extra, 'multiple') === false) ? ' multiple="multiple"' : '';
|
$multiple = (count($selected) > 1 && ! str_contains(strtolower($extra), 'multiple')) ? ' multiple="multiple"' : '';
|
||||||
$form = '<select ' . rtrim(parse_form_attributes($data, $defaults)) . $extra . $multiple . ">\n";
|
$form = '<select ' . rtrim(parse_form_attributes($data, $defaults)) . $extra . $multiple . ">\n";
|
||||||
|
|
||||||
foreach ($options as $key => $val) {
|
foreach ($options as $key => $val) {
|
||||||
|
@ -516,7 +516,7 @@ abstract class CIUnitTestCase extends TestCase
|
|||||||
|
|
||||||
foreach (xdebug_get_headers() as $emittedHeader) {
|
foreach (xdebug_get_headers() as $emittedHeader) {
|
||||||
$found = $ignoreCase
|
$found = $ignoreCase
|
||||||
? (stripos($emittedHeader, $header) === 0)
|
? (str_starts_with(strtolower($emittedHeader), strtolower($header)))
|
||||||
: (str_starts_with($emittedHeader, $header));
|
: (str_starts_with($emittedHeader, $header));
|
||||||
|
|
||||||
if ($found) {
|
if ($found) {
|
||||||
|
@ -379,12 +379,12 @@ class Fabricator
|
|||||||
|
|
||||||
// Check some common partials
|
// Check some common partials
|
||||||
foreach (['email', 'name', 'title', 'text', 'date', 'url'] as $term) {
|
foreach (['email', 'name', 'title', 'text', 'date', 'url'] as $term) {
|
||||||
if (stripos($field, $term) !== false) {
|
if (str_contains(strtolower($field), strtolower($term))) {
|
||||||
return $term;
|
return $term;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stripos($field, 'phone') !== false) {
|
if (str_contains(strtolower($field), 'phone')) {
|
||||||
return 'phoneNumber';
|
return 'phoneNumber';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,8 +96,8 @@ final class CacheFactoryTest extends CIUnitTestCase
|
|||||||
|
|
||||||
$this->config->handler = 'dummy';
|
$this->config->handler = 'dummy';
|
||||||
|
|
||||||
if (stripos('win', php_uname()) === 0) {
|
if (is_windows()) {
|
||||||
$this->assertTrue(true); // can't test properly if we are on Windows
|
$this->markTestSkipped('Cannot test this properly on Windows.');
|
||||||
} else {
|
} else {
|
||||||
$this->assertInstanceOf(DummyHandler::class, $this->cacheFactory->getHandler($this->config, 'wincache', 'wincache'));
|
$this->assertInstanceOf(DummyHandler::class, $this->cacheFactory->getHandler($this->config, 'wincache', 'wincache'));
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# total 17 errors
|
# total 16 errors
|
||||||
|
|
||||||
parameters:
|
parameters:
|
||||||
ignoreErrors:
|
ignoreErrors:
|
||||||
@ -12,11 +12,6 @@ parameters:
|
|||||||
count: 2
|
count: 2
|
||||||
path: ../../tests/system/CLI/CLITest.php
|
path: ../../tests/system/CLI/CLITest.php
|
||||||
|
|
||||||
-
|
|
||||||
message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertTrue\(\) with true will always evaluate to true\.$#'
|
|
||||||
count: 1
|
|
||||||
path: ../../tests/system/Cache/CacheFactoryTest.php
|
|
||||||
|
|
||||||
-
|
-
|
||||||
message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertTrue\(\) with true will always evaluate to true\.$#'
|
message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertTrue\(\) with true will always evaluate to true\.$#'
|
||||||
count: 1
|
count: 1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user