Skip to content

rector: SimplifyRegexPatternRector #4882

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
1 change: 0 additions & 1 deletion .rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
CodeQuality\Expression\InlineIfToExplicitIfRector::class, # todo: TMP (!?!)
CodeQuality\Expression\TernaryFalseExpressionToIfRector::class, # todo: TMP (!?!)
CodeQuality\Foreach_\ForeachItemsAssignToEmptyArrayToAssignRector::class, # todo: TMP
CodeQuality\FuncCall\SimplifyRegexPatternRector::class, # todo: TMP
CodeQuality\FunctionLike\SimplifyUselessVariableRector::class, # todo: TMP
CodeQuality\Identical\SimplifyBoolIdenticalTrueRector::class, # todo: TMP
CodeQuality\Identical\SimplifyConditionsRector::class, # todo: TMP
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ public function renderProperty()

if ($this->getColumn()->hasData('width')) {
$customWidth = $this->getColumn()->getData('width');
if (($customWidth === null) || (preg_match('/^[0-9]+%?$/', (string) $customWidth))) {
if (($customWidth === null) || (preg_match('/^\d+%?$/', (string) $customWidth))) {
$width = $customWidth;
} elseif (preg_match('/^([0-9]+)px$/', $customWidth, $matches)) {
} elseif (preg_match('/^(\d+)px$/', $customWidth, $matches)) {
$width = (int) $matches[1];
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function saveAction()
$i = 1;
foreach ($options as $key => $optionCode) {
$optionModel = Mage::getModel('rating/rating_option');
if (!preg_match('/^add_([0-9]*?)$/', $key)) {
if (!preg_match('/^add_(\d*?)$/', $key)) {
$optionModel->setId($key);
}

Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Catalog/Helper/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ public function getProduct($productId, $store, $identifierType = null)

$expectedIdType = false;
if ($identifierType === null) {
if (is_string($productId) && !preg_match('/^[+-]?[1-9][0-9]*$|^0$/', $productId)) {
if (is_string($productId) && !preg_match('/^[+-]?[1-9]\d*$|^0$/', $productId)) {
$expectedIdType = 'sku';
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ public function getEditableOptionValue($optionValue)
public function parseOptionValue($optionValue, $productOptionValues)
{
// search quote item option Id in option value
if (preg_match('/\[([0-9]+)\]/', $optionValue, $matches)) {
if (preg_match('/\[(\d+)\]/', $optionValue, $matches)) {
$confItemOptionId = $matches[1];
$option = Mage::getModel('sales/quote_item_option')->load($confItemOptionId);
try {
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Checkout/Model/Resource/Agreement.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected function _beforeSave(Mage_Core_Model_Abstract $object)
if (!$height) {
$height = '';
}
if ($height && preg_match('/[0-9]$/', $height)) {
if ($height && preg_match('/\d$/', $height)) {
$height .= 'px';
}
$object->setContentHeight($height);
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Cms/Model/Resource/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ public function getIsUniquePageToStores(Mage_Core_Model_Abstract $object)
*/
protected function isNumericPageIdentifier(Mage_Core_Model_Abstract $object)
{
return preg_match('/^[0-9]+$/', $object->getData('identifier'));
return preg_match('/^\d+$/', $object->getData('identifier'));
}

/**
Expand Down
8 changes: 4 additions & 4 deletions app/code/core/Mage/Core/Model/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,15 +232,15 @@ public function parseDateTime($dateTimeString, $dateTimeFormat)
$formats = [
// priority is important!
'%m/%d/%y %I:%M' => [
'/^([0-9]{1,2})\/([0-9]{1,2})\/([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2})/',
'/^(\d{1,2})\/(\d{1,2})\/(\d{1,2}) (\d{1,2}):(\d{1,2})/',
['y' => 3, 'm' => 1, 'd' => 2, 'h' => 4, 'i' => 5],
],
'm/d/y h:i' => [
'/^([0-9]{1,2})\/([0-9]{1,2})\/([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2})/',
'/^(\d{1,2})\/(\d{1,2})\/(\d{1,2}) (\d{1,2}):(\d{1,2})/',
['y' => 3, 'm' => 1, 'd' => 2, 'h' => 4, 'i' => 5],
],
'%m/%d/%y' => ['/^([0-9]{1,2})\/([0-9]{1,2})\/([0-9]{1,2})/', ['y' => 3, 'm' => 1, 'd' => 2]],
'm/d/y' => ['/^([0-9]{1,2})\/([0-9]{1,2})\/([0-9]{1,2})/', ['y' => 3, 'm' => 1, 'd' => 2]],
'%m/%d/%y' => ['/^(\d{1,2})\/(\d{1,2})\/(\d{1,2})/', ['y' => 3, 'm' => 1, 'd' => 2]],
'm/d/y' => ['/^(\d{1,2})\/(\d{1,2})\/(\d{1,2})/', ['y' => 3, 'm' => 1, 'd' => 2]],
];

foreach ($formats as $supportedFormat => $regRule) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function formatDate($date)
return null;
}
// unix timestamp given - simply instantiate date object
if (preg_match('/^[0-9]+$/', $date)) {
if (preg_match('/^\d+$/', $date)) {
$date = new Zend_Date((int) $date);
} elseif (preg_match('#^\d{4}-\d{2}-\d{2}( \d{2}:\d{2}:\d{2})?$#', $date)) {
// international format
Expand Down
24 changes: 12 additions & 12 deletions app/code/core/Mage/Payment/Model/Method/Cc.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ public function validate()
// Solo only
'SO' => '/(^(6334)[5-9](\d{11}$|\d{13,14}$))|(^(6767)(\d{12}$|\d{14,15}$))/',
// Visa
'VI' => '/^4[0-9]{12}([0-9]{3})?$/',
'VI' => '/^4\d{12}(\d{3})?$/',
// Master Card
'MC' => '/^(5[1-5][0-9]{14}|2(22[1-9][0-9]{12}|2[3-9][0-9]{13}|[3-6][0-9]{14}|7[0-1][0-9]{13}|720[0-9]{12}))$/',
'MC' => '/^(5[1-5]\d{14}|2(22[1-9]\d{12}|2[3-9]\d{13}|[3-6]\d{14}|7[0-1]\d{13}|720\d{12}))$/',
// American Express
'AE' => '/^3[47][0-9]{13}$/',
'AE' => '/^3[47]\d{13}$/',
// Discover Network
'DI' => $discoverNetworkRegexp,
// Dinners Club (Belongs to Discover Network)
Expand Down Expand Up @@ -177,15 +177,15 @@ public function hasVerification()
public function getVerificationRegEx()
{
return [
'VI' => '/^[0-9]{3}$/', // Visa
'MC' => '/^[0-9]{3}$/', // Master Card
'AE' => '/^[0-9]{4}$/', // American Express
'DI' => '/^[0-9]{3}$/', // Discovery
'SS' => '/^[0-9]{3,4}$/',
'SM' => '/^[0-9]{3,4}$/', // Switch or Maestro
'SO' => '/^[0-9]{3,4}$/', // Solo
'OT' => '/^[0-9]{3,4}$/',
'JCB' => '/^[0-9]{3,4}$/', //JCB
'VI' => '/^\d{3}$/', // Visa
'MC' => '/^\d{3}$/', // Master Card
'AE' => '/^\d{4}$/', // American Express
'DI' => '/^\d{3}$/', // Discovery
'SS' => '/^\d{3,4}$/',
'SM' => '/^\d{3,4}$/', // Switch or Maestro
'SO' => '/^\d{3,4}$/', // Solo
'OT' => '/^\d{3,4}$/',
'JCB' => '/^\d{3,4}$/', //JCB
];
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Varien/Data/Form/Element/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function setValue($value, $format = null, $locale = null)
$this->_value = $value;
return $this;
}
if (preg_match('/^[0-9]+$/', $value)) {
if (preg_match('/^\d+$/', $value)) {
$this->_value = new Zend_Date($this->_toTimestamp($value));
//$this->_value = new Zend_Date((int)value);
return $this;
Expand Down
Loading