Skip to content

Commit 18f5611

Browse files
authored
Merge pull request #4806 from samsonasik/apply-rector-simplify-regex
[Rector] Apply Rector: SimplifyRegexPatternRector
2 parents 2b95624 + ca153fc commit 18f5611

File tree

4 files changed

+9
-7
lines changed

4 files changed

+9
-7
lines changed

rector.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Rector\CodeQuality\Rector\Foreach_\UnusedForeachValueToArrayKeysRector;
66
use Rector\CodeQuality\Rector\FuncCall\AddPregQuoteDelimiterRector;
77
use Rector\CodeQuality\Rector\FuncCall\ChangeArrayPushToArrayAssignRector;
8+
use Rector\CodeQuality\Rector\FuncCall\SimplifyRegexPatternRector;
89
use Rector\CodeQuality\Rector\FuncCall\SimplifyStrposLowerRector;
910
use Rector\CodeQuality\Rector\If_\CombineIfRector;
1011
use Rector\CodeQuality\Rector\If_\ShortenElseIfRector;
@@ -96,4 +97,5 @@
9697
$services->set(MoveVariableDeclarationNearReferenceRector::class);
9798
$services->set(RemoveVarTagFromClassConstantRector::class);
9899
$services->set(AddPregQuoteDelimiterRector::class);
100+
$services->set(SimplifyRegexPatternRector::class);
99101
};

system/HTTP/CURLRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ protected function setResponseHeaders(array $headers = [])
534534

535535
$this->response->setHeader($title, $value);
536536
} elseif (strpos($header, 'HTTP') === 0) {
537-
preg_match('#^HTTP\/([12](?:\.[01])?) ([0-9]+) (.+)#', $header, $matches);
537+
preg_match('#^HTTP\/([12](?:\.[01])?) (\d+) (.+)#', $header, $matches);
538538

539539
if (isset($matches[1])) {
540540
$this->response->setProtocolVersion($matches[1]);

system/I18n/Time.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1312,7 +1312,7 @@ public function getCalendar()
13121312
protected static function hasRelativeKeywords(string $time): bool
13131313
{
13141314
// skip common format with a '-' in it
1315-
if (preg_match('/[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}/', $time) !== 1) {
1315+
if (preg_match('/\d{4}-\d{1,2}-\d{1,2}/', $time) !== 1) {
13161316
return preg_match(static::$relativePattern, $time) > 0;
13171317
}
13181318

system/Validation/FormatRules.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ public function string($str = null): bool
126126
*/
127127
public function decimal(?string $str = null): bool
128128
{
129-
// @see https://regex101.com/r/HULifl/1/
130-
return (bool) preg_match('/\A[-+]?[0-9]{0,}\.?[0-9]+\z/', $str);
129+
// @see https://regex101.com/r/HULifl/2/
130+
return (bool) preg_match('/\A[-+]?\d{0,}\.?\d+\z/', $str);
131131
}
132132

133133
/**
@@ -151,7 +151,7 @@ public function hex(?string $str = null): bool
151151
*/
152152
public function integer(?string $str = null): bool
153153
{
154-
return (bool) preg_match('/\A[\-+]?[0-9]+\z/', $str);
154+
return (bool) preg_match('/\A[\-+]?\d+\z/', $str);
155155
}
156156

157157
/**
@@ -187,8 +187,8 @@ public function is_natural_no_zero(?string $str = null): bool
187187
*/
188188
public function numeric(?string $str = null): bool
189189
{
190-
// @see https://regex101.com/r/bb9wtr/1
191-
return (bool) preg_match('/\A[\-+]?[0-9]*\.?[0-9]+\z/', $str);
190+
// @see https://regex101.com/r/bb9wtr/2
191+
return (bool) preg_match('/\A[\-+]?\d*\.?\d+\z/', $str);
192192
}
193193

194194
/**

0 commit comments

Comments
 (0)