diff --git a/.rector.php b/.rector.php index d06fe0126fe..b6bb7ea9530 100644 --- a/.rector.php +++ b/.rector.php @@ -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 diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Abstract.php b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Abstract.php index 0c03b09d115..100cce4d313 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Abstract.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Abstract.php @@ -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]; } } diff --git a/app/code/core/Mage/Adminhtml/controllers/RatingController.php b/app/code/core/Mage/Adminhtml/controllers/RatingController.php index f2bc59acd73..8da47a4768d 100644 --- a/app/code/core/Mage/Adminhtml/controllers/RatingController.php +++ b/app/code/core/Mage/Adminhtml/controllers/RatingController.php @@ -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); } diff --git a/app/code/core/Mage/Catalog/Helper/Product.php b/app/code/core/Mage/Catalog/Helper/Product.php index 22099e9a83f..8b921b49dcf 100644 --- a/app/code/core/Mage/Catalog/Helper/Product.php +++ b/app/code/core/Mage/Catalog/Helper/Product.php @@ -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'; } } diff --git a/app/code/core/Mage/Catalog/Model/Product/Option/Type/File.php b/app/code/core/Mage/Catalog/Model/Product/Option/Type/File.php index 4cc2864166f..7d0a91150b1 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Option/Type/File.php +++ b/app/code/core/Mage/Catalog/Model/Product/Option/Type/File.php @@ -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 { diff --git a/app/code/core/Mage/Checkout/Model/Resource/Agreement.php b/app/code/core/Mage/Checkout/Model/Resource/Agreement.php index 008927d8f57..50e59c5e5af 100644 --- a/app/code/core/Mage/Checkout/Model/Resource/Agreement.php +++ b/app/code/core/Mage/Checkout/Model/Resource/Agreement.php @@ -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); diff --git a/app/code/core/Mage/Cms/Model/Resource/Page.php b/app/code/core/Mage/Cms/Model/Resource/Page.php index aa5a0897a0a..fe70583a913 100644 --- a/app/code/core/Mage/Cms/Model/Resource/Page.php +++ b/app/code/core/Mage/Cms/Model/Resource/Page.php @@ -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')); } /** diff --git a/app/code/core/Mage/Core/Model/Date.php b/app/code/core/Mage/Core/Model/Date.php index 23546299ef7..92d04fc75f7 100644 --- a/app/code/core/Mage/Core/Model/Date.php +++ b/app/code/core/Mage/Core/Model/Date.php @@ -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) { diff --git a/app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Datetime.php b/app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Datetime.php index d3128a0de52..8d521402438 100644 --- a/app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Datetime.php +++ b/app/code/core/Mage/Eav/Model/Entity/Attribute/Backend/Datetime.php @@ -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 diff --git a/app/code/core/Mage/Payment/Model/Method/Cc.php b/app/code/core/Mage/Payment/Model/Method/Cc.php index fd7bbb8713c..268508e21bd 100644 --- a/app/code/core/Mage/Payment/Model/Method/Cc.php +++ b/app/code/core/Mage/Payment/Model/Method/Cc.php @@ -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) @@ -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 ]; } diff --git a/lib/Varien/Data/Form/Element/Date.php b/lib/Varien/Data/Form/Element/Date.php index 9e15728cdbe..a927acfef64 100644 --- a/lib/Varien/Data/Form/Element/Date.php +++ b/lib/Varien/Data/Form/Element/Date.php @@ -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;