Skip to content

[Rector] Apply Rector: SimplifyRegexPatternRector #4806

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Rector\CodeQuality\Rector\Foreach_\UnusedForeachValueToArrayKeysRector;
use Rector\CodeQuality\Rector\FuncCall\AddPregQuoteDelimiterRector;
use Rector\CodeQuality\Rector\FuncCall\ChangeArrayPushToArrayAssignRector;
use Rector\CodeQuality\Rector\FuncCall\SimplifyRegexPatternRector;
use Rector\CodeQuality\Rector\FuncCall\SimplifyStrposLowerRector;
use Rector\CodeQuality\Rector\If_\CombineIfRector;
use Rector\CodeQuality\Rector\If_\ShortenElseIfRector;
Expand Down Expand Up @@ -96,4 +97,5 @@
$services->set(MoveVariableDeclarationNearReferenceRector::class);
$services->set(RemoveVarTagFromClassConstantRector::class);
$services->set(AddPregQuoteDelimiterRector::class);
$services->set(SimplifyRegexPatternRector::class);
};
2 changes: 1 addition & 1 deletion system/HTTP/CURLRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ protected function setResponseHeaders(array $headers = [])

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

if (isset($matches[1])) {
$this->response->setProtocolVersion($matches[1]);
Expand Down
2 changes: 1 addition & 1 deletion system/I18n/Time.php
Original file line number Diff line number Diff line change
Expand Up @@ -1266,7 +1266,7 @@ public function getCalendar()
protected static function hasRelativeKeywords(string $time): bool
{
// skip common format with a '-' in it
if (preg_match('/[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}/', $time) !== 1) {
if (preg_match('/\d{4}-\d{1,2}-\d{1,2}/', $time) !== 1) {
return preg_match(static::$relativePattern, $time) > 0;
}

Expand Down
10 changes: 5 additions & 5 deletions system/Validation/FormatRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ public function string($str = null): bool
*/
public function decimal(?string $str = null): bool
{
// @see https://regex101.com/r/HULifl/1/
return (bool) preg_match('/\A[-+]?[0-9]{0,}\.?[0-9]+\z/', $str);
// @see https://regex101.com/r/HULifl/2/
return (bool) preg_match('/\A[-+]?\d{0,}\.?\d+\z/', $str);
}

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

/**
Expand Down Expand Up @@ -185,8 +185,8 @@ public function is_natural_no_zero(?string $str = null): bool
*/
public function numeric(?string $str = null): bool
{
// @see https://regex101.com/r/bb9wtr/1
return (bool) preg_match('/\A[\-+]?[0-9]*\.?[0-9]+\z/', $str);
// @see https://regex101.com/r/bb9wtr/2
return (bool) preg_match('/\A[\-+]?\d*\.?\d+\z/', $str);
}

/**
Expand Down