Skip to content

Commit f171b08

Browse files
committed
skip SimplifyRegexPatternRector
1 parent f658272 commit f171b08

10 files changed

Lines changed: 35 additions & 34 deletions

File tree

rector.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@
112112
GetMockBuilderGetMockToCreateMockRector::class => [
113113
__DIR__ . '/tests/system/Email/EmailTest.php',
114114
],
115+
116+
SimplifyRegexPatternRector::class,
115117
]);
116118

117119
// auto import fully qualified class names

system/Database/OCI8/Connection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class Connection extends BaseConnection
5353
protected $validDSNs = [
5454
'tns' => '/^\(DESCRIPTION=(\(.+\)){2,}\)$/', // TNS
5555
// Easy Connect string (Oracle 10g+)
56-
'ec' => '/^(\/\/)?[a-z0-9.:_-]+(:[1-9]\d{0,4})?(\/[a-z0-9$_]+)?(:[^\/])?(\/[a-z0-9$_]+)?$/i',
56+
'ec' => '/^(\/\/)?[a-z0-9.:_-]+(:[1-9][0-9]{0,4})?(\/[a-z0-9$_]+)?(:[^\/])?(\/[a-z0-9$_]+)?$/i',
5757
'in' => '/^[a-z0-9$_]+$/i', // Instance name (defined in tnsnames.ora)
5858
];
5959

system/Helpers/text_helper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ function _from_random(int $length, string $pool): string
662662
*/
663663
function increment_string(string $str, string $separator = '_', int $first = 1): string
664664
{
665-
preg_match('/(.+)' . preg_quote($separator, '/') . '(\d+)$/', $str, $match);
665+
preg_match('/(.+)' . preg_quote($separator, '/') . '([0-9]+)$/', $str, $match);
666666

667667
return isset($match[2]) ? $match[1] . $separator . ((int) $match[2] + 1) : $str . $separator . $first;
668668
}

system/Router/RouteCollection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class RouteCollection implements RouteCollectionInterface
9898
'any' => '.*',
9999
'segment' => '[^/]+',
100100
'alphanum' => '[a-zA-Z0-9]+',
101-
'num' => '\d+',
101+
'num' => '[0-9]+',
102102
'alpha' => '[a-zA-Z]+',
103103
'hash' => '[^/]+',
104104
];

tests/system/Commands/Utilities/Routes/SampleURIGeneratorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function routeKeyProvider(): Generator
3838
{
3939
yield from [
4040
'root' => ['/', '/'],
41-
'placeholder num' => ['shop/product/(\d+)', 'shop/product/123'],
41+
'placeholder num' => ['shop/product/([0-9]+)', 'shop/product/123'],
4242
'placeholder segment' => ['shop/product/([^/]+)', 'shop/product/abc_123'],
4343
'placeholder any' => ['shop/product/(.*)', 'shop/product/123/abc'],
4444
'auto route' => ['home/index[/...]', 'home/index/1/2/3/4/5'],

tests/system/Database/Builder/SelectTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public function testSelectWorksWithRawSql()
105105
{
106106
$builder = new BaseBuilder('users', $this->db);
107107

108-
$sql = 'REGEXP_SUBSTR(ral_anno,"\d{1,2}([,.]\d{1,3})([,.]\d{1,3})") AS ral';
108+
$sql = 'REGEXP_SUBSTR(ral_anno,"[0-9]{1,2}([,.][0-9]{1,3})([,.][0-9]{1,3})") AS ral';
109109
$builder->select(new RawSql($sql));
110110

111111
$expected = 'SELECT ' . $sql . ' FROM "users"';
@@ -134,12 +134,12 @@ public function testSelectRegularExpressionWorksWithEscpaeFalse()
134134
$builder = new BaseBuilder('ob_human_resources', $this->db);
135135

136136
$builder->select(
137-
'REGEXP_SUBSTR(ral_anno,"\d{1,2}([,.]\d{1,3})([,.]\d{1,3})") AS ral',
137+
'REGEXP_SUBSTR(ral_anno,"[0-9]{1,2}([,.][0-9]{1,3})([,.][0-9]{1,3})") AS ral',
138138
false
139139
);
140140

141141
$expected = <<<'SQL'
142-
SELECT REGEXP_SUBSTR(ral_anno,"\d{1,2}([,.]\d{1,3})([,.]\d{1,3})") AS ral
142+
SELECT REGEXP_SUBSTR(ral_anno,"[0-9]{1,2}([,.][0-9]{1,3})([,.][0-9]{1,3})") AS ral
143143
FROM "ob_human_resources"
144144
SQL;
145145
$this->assertSame($expected, $builder->getCompiledSelect());

tests/system/Database/RawSqlTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ final class RawSqlTest extends CIUnitTestCase
2222
{
2323
public function testCanConvertToString()
2424
{
25-
$expected = 'REGEXP_SUBSTR(ral_anno,"\d{1,2}([,.]\d{1,3})([,.]\d{1,3})") AS ral';
25+
$expected = 'REGEXP_SUBSTR(ral_anno,"[0-9]{1,2}([,.][0-9]{1,3})([,.][0-9]{1,3})") AS ral';
2626
$rawSql = new RawSql($expected);
2727

2828
$this->assertSame($expected, (string) $rawSql);
@@ -47,6 +47,6 @@ public function testGetBindingKey()
4747

4848
$key = $rawSql->getBindingKey();
4949

50-
$this->assertMatchesRegularExpression('/\ARawSql\d+\z/', $key);
50+
$this->assertMatchesRegularExpression('/\ARawSql[0-9]+\z/', $key);
5151
}
5252
}

tests/system/Router/RouteCollectionTest.php

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace CodeIgniter\Router;
1313

1414
use CodeIgniter\Config\Services;
15-
use CodeIgniter\controller;
1615
use CodeIgniter\Exceptions\PageNotFoundException;
1716
use CodeIgniter\Test\CIUnitTestCase;
1817
use Config\Modules;
@@ -89,7 +88,7 @@ public function testBasicAddCallableWithParamsString()
8988

9089
$routes = $routes->getRoutes();
9190
$expects = [
92-
'product/(\d+)/(\d+)' => '\Tests\Support\Controllers\Hello::index/$2/$1',
91+
'product/([0-9]+)/([0-9]+)' => '\Tests\Support\Controllers\Hello::index/$2/$1',
9392
];
9493
$this->assertSame($expects, $routes);
9594
}
@@ -102,7 +101,7 @@ public function testBasicAddCallableWithParamsWithoutString()
102101

103102
$routes = $routes->getRoutes();
104103
$expects = [
105-
'product/(\d+)/(\d+)' => '\Tests\Support\Controllers\Hello::index/$1/$2',
104+
'product/([0-9]+)/([0-9]+)' => '\Tests\Support\Controllers\Hello::index/$1/$2',
106105
];
107106
$this->assertSame($expects, $routes);
108107
}
@@ -238,7 +237,7 @@ public function testAddRecognizesCustomNamespaces()
238237
$routes->add('home', 'controller');
239238

240239
$expects = [
241-
'home' => '\\' . controller::class,
240+
'home' => '\CodeIgniter\controller',
242241
];
243242

244243
$routes = $routes->getRoutes();
@@ -616,10 +615,10 @@ public function testResourcesWithCustomPlaceholder()
616615
$routes->resource('photos', ['placeholder' => ':num']);
617616

618617
$expected = [
619-
'photos' => '\Photos::index',
620-
'photos/new' => '\Photos::new',
621-
'photos/(\d+)/edit' => '\Photos::edit/$1',
622-
'photos/(\d+)' => '\Photos::show/$1',
618+
'photos' => '\Photos::index',
619+
'photos/new' => '\Photos::new',
620+
'photos/([0-9]+)/edit' => '\Photos::edit/$1',
621+
'photos/([0-9]+)' => '\Photos::show/$1',
623622
];
624623

625624
$this->assertSame($expected, $routes->getRoutes());
@@ -634,10 +633,10 @@ public function testResourcesWithDefaultPlaceholder()
634633
$routes->resource('photos');
635634

636635
$expected = [
637-
'photos' => '\Photos::index',
638-
'photos/new' => '\Photos::new',
639-
'photos/(\d+)/edit' => '\Photos::edit/$1',
640-
'photos/(\d+)' => '\Photos::show/$1',
636+
'photos' => '\Photos::index',
637+
'photos/new' => '\Photos::new',
638+
'photos/([0-9]+)/edit' => '\Photos::edit/$1',
639+
'photos/([0-9]+)' => '\Photos::show/$1',
641640
];
642641

643642
$this->assertSame($expected, $routes->getRoutes());
@@ -1400,7 +1399,7 @@ public function testOffsetParameters()
14001399
$routes = $this->getCollector();
14011400

14021401
$routes->get('users/(:num)', 'users/show/$1', ['offset' => 1]);
1403-
$expected = ['users/(\d+)' => '\users/show/$2'];
1402+
$expected = ['users/([0-9]+)' => '\users/show/$2'];
14041403
$this->assertSame($expected, $routes->getRoutes());
14051404
}
14061405

tests/system/Validation/FormatRulesTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function testRegexMatch(): void
6363

6464
$this->validation->setRules([
6565
'foo' => 'regex_match[/[a-z]/]',
66-
'phone' => 'regex_match[/^(01[2689]|09)\d{8}$/]',
66+
'phone' => 'regex_match[/^(01[2689]|09)[0-9]{8}$/]',
6767
]);
6868

6969
$this->assertTrue($this->validation->run($data));
@@ -78,7 +78,7 @@ public function testRegexMatchFalse(): void
7878

7979
$this->validation->setRules([
8080
'foo' => 'regex_match[\d]',
81-
'phone' => 'regex_match[/^(01[2689]|09)\d{8}$/]',
81+
'phone' => 'regex_match[/^(01[2689]|09)[0-9]{8}$/]',
8282
]);
8383

8484
$this->assertFalse($this->validation->run($data));

tests/system/Validation/ValidationTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -883,15 +883,15 @@ public function testHasError(): void
883883
public function testSplitRulesTrue(): void
884884
{
885885
$this->validation->setRules([
886-
'phone' => 'required|regex_match[/^(01[2689]|09)\d{8}$/]|numeric',
886+
'phone' => 'required|regex_match[/^(01[2689]|09)[0-9]{8}$/]|numeric',
887887
]);
888888
$this->assertTrue($this->validation->run(['phone' => '0987654321']));
889889
}
890890

891891
public function testSplitRulesFalse(): void
892892
{
893893
$this->validation->setRules([
894-
'phone' => 'required|regex_match[/^(01[2689]|09)\d{8}$/]|numeric',
894+
'phone' => 'required|regex_match[/^(01[2689]|09)[0-9]{8}$/]|numeric',
895895
]);
896896
$this->assertFalse($this->validation->run(['phone' => '09876543214']));
897897
}
@@ -909,8 +909,8 @@ public function testSplitNotRegex(): void
909909
public function testSplitRegex(): void
910910
{
911911
$method = $this->getPrivateMethodInvoker($this->validation, 'splitRules');
912-
$result = $method('required|regex_match[/^\d{4}[\-\.\[\/]\d{2}[\-\.\[\/]\d{2}/]|max_length[10]');
913-
$this->assertSame('regex_match[/^\d{4}[\-\.\[\/]\d{2}[\-\.\[\/]\d{2}/]', $result[1]);
912+
$result = $method('required|regex_match[/^[0-9]{4}[\-\.\[\/][0-9]{2}[\-\.\[\/][0-9]{2}/]|max_length[10]');
913+
$this->assertSame('regex_match[/^[0-9]{4}[\-\.\[\/][0-9]{2}[\-\.\[\/][0-9]{2}/]', $result[1]);
914914
}
915915

916916
public function testTagReplacement(): void
@@ -1365,18 +1365,18 @@ public function provideStringRulesCases(): iterable
13651365
];
13661366

13671367
yield [
1368-
'required|regex_match[/^(01[2689]|09)\d{8}$/]|numeric',
1369-
['required', 'regex_match[/^(01[2689]|09)\d{8}$/]', 'numeric'],
1368+
'required|regex_match[/^(01[2689]|09)[0-9]{8}$/]|numeric',
1369+
['required', 'regex_match[/^(01[2689]|09)[0-9]{8}$/]', 'numeric'],
13701370
];
13711371

13721372
yield [
1373-
'required|regex_match[/^\d{4}[\-\.\[\/]\d{2}[\-\.\[\/]\d{2}/]|max_length[10]',
1374-
['required', 'regex_match[/^\d{4}[\-\.\[\/]\d{2}[\-\.\[\/]\d{2}/]', 'max_length[10]'],
1373+
'required|regex_match[/^[0-9]{4}[\-\.\[\/][0-9]{2}[\-\.\[\/][0-9]{2}/]|max_length[10]',
1374+
['required', 'regex_match[/^[0-9]{4}[\-\.\[\/][0-9]{2}[\-\.\[\/][0-9]{2}/]', 'max_length[10]'],
13751375
];
13761376

13771377
yield [
1378-
'required|regex_match[/^(01|2689|09)\d{8}$/]|numeric',
1379-
['required', 'regex_match[/^(01|2689|09)\d{8}$/]', 'numeric'],
1378+
'required|regex_match[/^(01|2689|09)[0-9]{8}$/]|numeric',
1379+
['required', 'regex_match[/^(01|2689|09)[0-9]{8}$/]', 'numeric'],
13801380
];
13811381
}
13821382

0 commit comments

Comments
 (0)