diff --git a/.rector.php b/.rector.php index eeff764371e..63c5ea7188b 100644 --- a/.rector.php +++ b/.rector.php @@ -124,9 +124,7 @@ Php80\Class_\AnnotationToAttributeRector::class, # todo: wait for php80 Php80\Class_\ClassPropertyAssignToConstructorPromotionRector::class, # todo: wait for php80 Php80\Class_\StringableForToStringRector::class, # todo: wait for php80 - Php80\ClassConstFetch\ClassOnThisVariableObjectRector::class, # todo: TMP Php80\ClassMethod\AddParamBasedOnParentClassMethodRector::class, # todo: TMP - Php80\FuncCall\ClassOnObjectRector::class, # todo: TMP Php81\Array_\FirstClassCallableRector::class, # todo: TMP Php81\FuncCall\NullToStrictStringFuncCallArgRector::class, # todo: check later Strict\Empty_\DisallowedEmptyRuleFixerRector::class, # todo: TMP diff --git a/app/code/core/Mage/Api2/Model/Resource.php b/app/code/core/Mage/Api2/Model/Resource.php index a6e7a554ca3..8ac666b7337 100644 --- a/app/code/core/Mage/Api2/Model/Resource.php +++ b/app/code/core/Mage/Api2/Model/Resource.php @@ -376,7 +376,7 @@ public function setApiType($apiType) public function getVersion() { if ($this->_version === null) { - if (preg_match('/^.+([1-9]\d*)$/', get_class($this), $matches)) { + if (preg_match('/^.+([1-9]\d*)$/', static::class, $matches)) { $this->setVersion($matches[1]); } else { throw new Exception('Can not determine version from class name'); diff --git a/app/code/core/Mage/Catalog/Model/Resource/Abstract.php b/app/code/core/Mage/Catalog/Model/Resource/Abstract.php index e6e4b4bb22d..dcfe234bbaf 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Abstract.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Abstract.php @@ -441,7 +441,7 @@ protected function _deleteAttributes($object, $table, $info) */ protected function _getOrigObject($object) { - $className = get_class($object); + $className = $object::class; $origObject = new $className(); $origObject->setData([]); $origObject->setStoreId($object->getStoreId()); diff --git a/app/code/core/Mage/Cms/Block/Widget/Block.php b/app/code/core/Mage/Cms/Block/Widget/Block.php index b613093f807..3f2e99467be 100644 --- a/app/code/core/Mage/Cms/Block/Widget/Block.php +++ b/app/code/core/Mage/Cms/Block/Widget/Block.php @@ -47,7 +47,7 @@ protected function _beforeToHtml() { parent::_beforeToHtml(); $blockId = $this->getData('block_id'); - $blockHash = get_class($this) . $blockId; + $blockHash = static::class . $blockId; if (isset(self::$_widgetUsageMap[$blockHash])) { return $this; diff --git a/app/code/core/Mage/Core/Block/Abstract.php b/app/code/core/Mage/Core/Block/Abstract.php index bc179904276..47378a1434c 100644 --- a/app/code/core/Mage/Core/Block/Abstract.php +++ b/app/code/core/Mage/Core/Block/Abstract.php @@ -1153,7 +1153,7 @@ public function getModuleName() { $module = $this->getData('module_name'); if (is_null($module)) { - $class = get_class($this); + $class = static::class; $module = substr($class, 0, strpos($class, '_Block')); $this->setData('module_name', $module); } diff --git a/app/code/core/Mage/Core/Block/Template.php b/app/code/core/Mage/Core/Block/Template.php index 979cfecd9a9..55e3a81492a 100644 --- a/app/code/core/Mage/Core/Block/Template.php +++ b/app/code/core/Mage/Core/Block/Template.php @@ -248,7 +248,7 @@ public function fetchView($fileName) onmouseout="this.style.zIndex='998'" title="{$fileName}">{$fileName} HTML; if (Mage::app()->getStore()->isAdmin() ? self::$_showTemplateHintsBlocksAdmin : self::$_showTemplateHintsBlocks) { - $thisClass = get_class($this); + $thisClass = static::class; echo <<_viewDir . DS . $fileName; } else { - $thisClass = get_class($this); + $thisClass = static::class; Mage::log('Not valid template file:' . $fileName . ' class: ' . $thisClass, Zend_Log::CRIT, null, true); } } catch (Throwable $e) { diff --git a/app/code/core/Mage/Core/Controller/Varien/Action.php b/app/code/core/Mage/Core/Controller/Varien/Action.php index 82d8803dbcd..3b3444ff430 100644 --- a/app/code/core/Mage/Core/Controller/Varien/Action.php +++ b/app/code/core/Mage/Core/Controller/Varien/Action.php @@ -813,7 +813,7 @@ protected function _isUrlInternal($url) protected function _getRealModuleName() { if (empty($this->_realModuleName)) { - $class = get_class($this); + $class = static::class; $this->_realModuleName = substr( $class, 0, diff --git a/app/code/core/Mage/Core/Helper/Abstract.php b/app/code/core/Mage/Core/Helper/Abstract.php index 7ca70686270..4ab1b817a71 100644 --- a/app/code/core/Mage/Core/Helper/Abstract.php +++ b/app/code/core/Mage/Core/Helper/Abstract.php @@ -108,7 +108,7 @@ protected function _cleanCache($tags = []) protected function _getModuleName() { if (!$this->_moduleName) { - $class = get_class($this); + $class = static::class; $this->_moduleName = implode('_', array_slice(explode('_', $class), 0, 2)); } return $this->_moduleName; diff --git a/app/code/core/Mage/Core/Helper/Security.php b/app/code/core/Mage/Core/Helper/Security.php index 7162ce70233..8dc569b9fd1 100644 --- a/app/code/core/Mage/Core/Helper/Security.php +++ b/app/code/core/Mage/Core/Helper/Security.php @@ -32,7 +32,7 @@ public function validateAgainstBlockMethodBlacklist(Mage_Core_Block_Abstract $bl } if ($block instanceof $action['block'] && strtolower($action['method']) === $calledMethod) { Mage::throwException( - sprintf('Action with combination block %s and method %s is forbidden.', get_class($block), $method), + sprintf('Action with combination block %s and method %s is forbidden.', $block::class, $method), ); } } diff --git a/app/code/core/Mage/Core/Model/App.php b/app/code/core/Mage/Core/Model/App.php index ed0ef886e79..fcb848ad14b 100644 --- a/app/code/core/Mage/Core/Model/App.php +++ b/app/code/core/Mage/Core/Model/App.php @@ -1439,7 +1439,7 @@ protected function _callObserverMethod($object, $method, $observer, $observerNam $object->$method($observer); } elseif (Mage::getIsDeveloperMode()) { if (is_object($object)) { - $message = 'Method "' . $method . '" is not defined in "' . get_class($object) . '"'; + $message = 'Method "' . $method . '" is not defined in "' . $object::class . '"'; } else { $message = 'Class from observer "' . $observerName . '" is not initialized'; } diff --git a/app/code/core/Mage/Core/Model/Convert.php b/app/code/core/Mage/Core/Model/Convert.php index f9b5cc7d179..a9246d70c7a 100644 --- a/app/code/core/Mage/Core/Model/Convert.php +++ b/app/code/core/Mage/Core/Model/Convert.php @@ -16,7 +16,7 @@ class Mage_Core_Model_Convert extends Mage_Dataflow_Model_Convert_Profile_Collec { public function __construct() { - $classArr = explode('_', get_class($this)); + $classArr = explode('_', static::class); $moduleName = $classArr[0] . '_' . $classArr[1]; $etcDir = Mage::getConfig()->getModuleDir('etc', $moduleName); diff --git a/app/code/core/Mage/Core/Model/Layout.php b/app/code/core/Mage/Core/Model/Layout.php index fbe0bf291cb..5cfb2657f83 100644 --- a/app/code/core/Mage/Core/Model/Layout.php +++ b/app/code/core/Mage/Core/Model/Layout.php @@ -357,7 +357,7 @@ protected function validateAgainstBlacklist(Mage_Core_Block_Abstract $block, $me foreach ($this->invalidActions as $action) { if ($block instanceof $action['block'] && $action['method'] === strtolower($method)) { Mage::throwException( - sprintf('Action with combination block %s and method %s is forbidden.', get_class($block), $method), + sprintf('Action with combination block %s and method %s is forbidden.', $block::class, $method), ); } } @@ -502,7 +502,7 @@ protected function _getBlockInstance($block, array $attributes = []) } } if (!$block instanceof Mage_Core_Block_Abstract) { - $block = is_object($block) ? get_class($block) : $block; + $block = is_object($block) ? $block::class : $block; Mage::throwException(Mage::helper('core')->__('Invalid block type: %s (not instance of Mage_Core_Block_Abstract)', $block)); } return $block; diff --git a/app/code/core/Mage/Dataflow/Model/Convert/Action/Abstract.php b/app/code/core/Mage/Dataflow/Model/Convert/Action/Abstract.php index 72970cf2ae7..4c93d33c09e 100644 --- a/app/code/core/Mage/Dataflow/Model/Convert/Action/Abstract.php +++ b/app/code/core/Mage/Dataflow/Model/Convert/Action/Abstract.php @@ -200,7 +200,7 @@ public function run(array $args = []) ); } - $this->getContainer()->addException('Starting ' . get_class($this->getContainer()) . ' :: ' . $method); + $this->getContainer()->addException('Starting ' . $this->getContainer()::class . ' :: ' . $method); if ($this->getParam('from')) { $this->getContainer()->setData($this->getContainer($this->getParam('from'))->getData()); diff --git a/app/code/core/Mage/Eav/Model/Entity/Abstract.php b/app/code/core/Mage/Eav/Model/Entity/Abstract.php index e4fd2f459fd..f6147080bba 100644 --- a/app/code/core/Mage/Eav/Model/Entity/Abstract.php +++ b/app/code/core/Mage/Eav/Model/Entity/Abstract.php @@ -1088,7 +1088,7 @@ public function save(Varien_Object $object) */ protected function _getOrigObject($object) { - $className = get_class($object); + $className = $object::class; $origObject = new $className(); $origObject->setData([]); $this->load($origObject, $object->getData($this->getEntityIdField())); diff --git a/app/code/core/Mage/Eav/Model/Entity/Collection/Abstract.php b/app/code/core/Mage/Eav/Model/Entity/Collection/Abstract.php index 3d7ec9cf4fc..136b44bc2ae 100644 --- a/app/code/core/Mage/Eav/Model/Entity/Collection/Abstract.php +++ b/app/code/core/Mage/Eav/Model/Entity/Collection/Abstract.php @@ -225,7 +225,7 @@ public function getResource() public function setObject($object = null) { if (is_object($object)) { - $this->setItemObjectClass(get_class($object)); + $this->setItemObjectClass($object::class); } else { $this->setItemObjectClass($object); } @@ -240,7 +240,7 @@ public function setObject($object = null) */ public function addItem(Varien_Object $object) { - if (get_class($object) !== $this->_itemObjectClass) { + if ($object::class !== $this->_itemObjectClass) { throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Attempt to add an invalid object')); } return parent::addItem($object); @@ -305,7 +305,7 @@ public function addAttributeToFilter($attribute, $condition = null, $joinType = if (!empty($conditionSql)) { $this->getSelect()->where($conditionSql, null, Varien_Db_Select::TYPE_CONDITION); } else { - Mage::throwException('Invalid attribute identifier for filter (' . get_class($attribute) . ')'); + Mage::throwException('Invalid attribute identifier for filter (' . $attribute::class . ')'); } return $this; diff --git a/app/code/core/Mage/Index/Model/Event.php b/app/code/core/Mage/Index/Model/Event.php index d4ae9c78269..1d2a2006094 100644 --- a/app/code/core/Mage/Index/Model/Event.php +++ b/app/code/core/Mage/Index/Model/Event.php @@ -205,7 +205,7 @@ public function cleanNewData() if ($processStatus == Mage_Index_Model_Process::EVENT_STATUS_DONE) { $process = Mage::getSingleton('index/indexer')->getProcessById($processId); if ($process) { - $namespace = get_class($process->getIndexer()); + $namespace = $process->getIndexer()::class; if (array_key_exists($namespace, $newData)) { unset($newData[$namespace]); } diff --git a/app/code/core/Mage/Index/Model/Process.php b/app/code/core/Mage/Index/Model/Process.php index 43e854fa7b8..a907daa2740 100644 --- a/app/code/core/Mage/Index/Model/Process.php +++ b/app/code/core/Mage/Index/Model/Process.php @@ -96,7 +96,7 @@ protected function _construct() */ protected function _setEventNamespace(Mage_Index_Model_Event $event) { - $namespace = get_class($this->getIndexer()); + $namespace = $this->getIndexer()::class; $event->setDataNamespace($namespace); $event->setProcess($this); return $this; diff --git a/app/code/core/Mage/Paypal/Model/Express/Checkout.php b/app/code/core/Mage/Paypal/Model/Express/Checkout.php index b70d94eb6b1..1ec4e942070 100644 --- a/app/code/core/Mage/Paypal/Model/Express/Checkout.php +++ b/app/code/core/Mage/Paypal/Model/Express/Checkout.php @@ -839,7 +839,7 @@ protected function _prepareShippingOptions( // Magento will transfer only first 10 cheapest shipping options if there are more than 10 available. if (count($options) > 10) { - usort($options, [get_class($this),'cmpShippingOptions']); + usort($options, [static::class,'cmpShippingOptions']); array_splice($options, 10); // User selected option will be always included in options list if (!is_null($userSelectedOption) && !in_array($userSelectedOption, $options)) { diff --git a/app/code/core/Mage/Paypal/Model/Payflow/Request.php b/app/code/core/Mage/Paypal/Model/Payflow/Request.php index 2c7169051ea..fbbdc0d7524 100644 --- a/app/code/core/Mage/Paypal/Model/Payflow/Request.php +++ b/app/code/core/Mage/Paypal/Model/Payflow/Request.php @@ -34,7 +34,7 @@ public function __call($method, $args) 'set' => $this->setData($key, $args[0] ?? null), 'uns' => $this->unsetData($key), 'has' => isset($this->_data[$key]), - default => throw new Varien_Exception('Invalid method ' . get_class($this) . '::' . $method . '(' . print_r($args, true) . ')'), + default => throw new Varien_Exception('Invalid method ' . static::class . '::' . $method . '(' . print_r($args, true) . ')'), }; } } diff --git a/app/code/core/Mage/Persistent/Model/Observer.php b/app/code/core/Mage/Persistent/Model/Observer.php index e20f8a4889f..894081107ef 100644 --- a/app/code/core/Mage/Persistent/Model/Observer.php +++ b/app/code/core/Mage/Persistent/Model/Observer.php @@ -59,7 +59,7 @@ public function applyBlockPersistentData($observer) return $this; } - $xPath = '//instances/blocks/*[block_type="' . get_class($block) . '"]'; + $xPath = '//instances/blocks/*[block_type="' . $block::class . '"]'; $configFilePath = $observer->getEvent()->getConfigFilePath(); /** @var Mage_Persistent_Model_Persistent_Config $persistentConfig */ diff --git a/app/code/core/Mage/Persistent/Model/Persistent/Config.php b/app/code/core/Mage/Persistent/Model/Persistent/Config.php index 222e02b9aca..09fa2a2fbc7 100644 --- a/app/code/core/Mage/Persistent/Model/Persistent/Config.php +++ b/app/code/core/Mage/Persistent/Model/Persistent/Config.php @@ -100,6 +100,7 @@ public function fire() * @param array $info * @param Mage_Core_Block_Abstract|false $instance * @return $this + * @throws Mage_Core_Exception */ public function fireOne($info, $instance = false) { @@ -116,7 +117,11 @@ public function fireOne($info, $instance = false) if (method_exists($object, $method)) { $object->$method($instance); } elseif (Mage::getIsDeveloperMode()) { - Mage::throwException('Method "' . $method . '" is not defined in "' . get_class($object) . '"'); + if (!$object instanceof Mage_Core_Model_Abstract) { + Mage::throwException(sprintf('Model "%s" is not defined"', $info['class'])); + } else { + Mage::throwException(sprintf('Method "%s" is not defined in "%s"', $method, $object::class)); + } } return $this; diff --git a/app/code/core/Mage/Sales/Model/Order/Payment/Transaction.php b/app/code/core/Mage/Sales/Model/Order/Payment/Transaction.php index cff16ca70ad..0ffacd432e5 100644 --- a/app/code/core/Mage/Sales/Model/Order/Payment/Transaction.php +++ b/app/code/core/Mage/Sales/Model/Order/Payment/Transaction.php @@ -197,7 +197,7 @@ public function getParentTransaction($shouldLoad = true) $this->_parentTransaction = false; $parentId = $this->getParentId(); if ($parentId) { - $class = get_class($this); + $class = static::class; $this->_parentTransaction = new $class(); if ($shouldLoad) { $this->_parentTransaction diff --git a/app/code/core/Mage/Uploader/Model/Config/Abstract.php b/app/code/core/Mage/Uploader/Model/Config/Abstract.php index 8863da20663..fe7051c9883 100644 --- a/app/code/core/Mage/Uploader/Model/Config/Abstract.php +++ b/app/code/core/Mage/Uploader/Model/Config/Abstract.php @@ -42,7 +42,7 @@ public function __call($method, $args) 'set' => $this->setData($key, $args[0] ?? null), 'uns' => $this->unsetData($key), 'has' => isset($this->_data[$key]), - default => throw new Varien_Exception('Invalid method ' . get_class($this) . '::' . $method . '(' . print_r($args, true) . ')'), + default => throw new Varien_Exception('Invalid method ' . static::class . '::' . $method . '(' . print_r($args, true) . ')'), }; } } diff --git a/lib/Varien/Convert/Action/Abstract.php b/lib/Varien/Convert/Action/Abstract.php index 17170693bcb..eec495ae3ab 100644 --- a/lib/Varien/Convert/Action/Abstract.php +++ b/lib/Varien/Convert/Action/Abstract.php @@ -158,7 +158,7 @@ public function run() $this->addException('Unable to run action method: ' . $method, Varien_Convert_Exception::FATAL); } - $this->getContainer()->addException('Starting ' . get_class($this->getContainer()) . ' :: ' . $method); + $this->getContainer()->addException('Starting ' . $this->getContainer()::class . ' :: ' . $method); if ($this->getParam('from')) { $this->getContainer()->setData($this->getContainer($this->getParam('from'))->getData()); diff --git a/lib/Varien/Data/Collection.php b/lib/Varien/Data/Collection.php index f60807accb9..3d4c067d5cb 100644 --- a/lib/Varien/Data/Collection.php +++ b/lib/Varien/Data/Collection.php @@ -345,7 +345,7 @@ public function addItem(Varien_Object $item) if (!is_null($itemId)) { if (isset($this->_items[$itemId])) { - throw new Exception('Item (' . get_class($item) . ') with the same id "' . $item->getId() . '" already exist'); + throw new Exception('Item (' . $item::class . ') with the same id "' . $item->getId() . '" already exist'); } $this->_items[$itemId] = $item; } else { diff --git a/lib/Varien/Db/Adapter/Pdo/Mysql.php b/lib/Varien/Db/Adapter/Pdo/Mysql.php index 8c9fab095eb..bba6c6bb454 100644 --- a/lib/Varien/Db/Adapter/Pdo/Mysql.php +++ b/lib/Varien/Db/Adapter/Pdo/Mysql.php @@ -2170,7 +2170,7 @@ public function insertIgnore($table, array $bind) /** @see Zend_Db_Adapter_Exception */ #require_once 'Zend/Db/Adapter/Exception.php'; throw new Zend_Db_Adapter_Exception( - get_class($this) . " doesn't support positional or named binding", + static::class . " doesn't support positional or named binding", ); } } diff --git a/lib/Varien/Debug.php b/lib/Varien/Debug.php index 5a41fc98700..f6d87ff0ddc 100644 --- a/lib/Varien/Debug.php +++ b/lib/Varien/Debug.php @@ -86,8 +86,8 @@ public static function trace(array $trace, $return = false, $html = true, $withA // prepare method's name $methodName = ''; if (isset($data['class']) && isset($data['function'])) { - if (isset($data['object']) && get_class($data['object']) != $data['class']) { - $className = get_class($data['object']) . '[' . $data['class'] . ']'; + if (isset($data['object']) && $data['object']::class != $data['class']) { + $className = $data['object']::class . '[' . $data['class'] . ']'; } else { $className = $data['class']; } @@ -146,7 +146,7 @@ protected static function _formatCalledArgument($arg) { $out = ''; if (is_object($arg)) { - $out .= sprintf('&%s#%s#', get_class($arg), spl_object_hash($arg)); + $out .= sprintf('&%s#%s#', $arg::class, spl_object_hash($arg)); } elseif (is_resource($arg)) { $out .= '#[' . get_resource_type($arg) . ']'; } elseif (is_array($arg)) { diff --git a/lib/Varien/Event/Observer.php b/lib/Varien/Event/Observer.php index 02a8bf36341..9d353778cdb 100644 --- a/lib/Varien/Event/Observer.php +++ b/lib/Varien/Event/Observer.php @@ -38,7 +38,7 @@ public function dispatch(Varien_Event $event) $callback = $this->getCallback(); $this->setEvent($event); - $profilerKey = 'OBSERVER: ' . (is_object($callback[0]) ? get_class($callback[0]) : (string) $callback[0]) . ' -> ' . $callback[1]; + $profilerKey = 'OBSERVER: ' . (is_object($callback[0]) ? $callback[0]::class : (string) $callback[0]) . ' -> ' . $callback[1]; Varien_Profiler::start($profilerKey); call_user_func($callback, $this); Varien_Profiler::stop($profilerKey); diff --git a/lib/Varien/Filter/Object.php b/lib/Varien/Filter/Object.php index 3a680d84f52..014239ecc50 100644 --- a/lib/Varien/Filter/Object.php +++ b/lib/Varien/Filter/Object.php @@ -41,7 +41,7 @@ public function filter($object) if (!$object instanceof Varien_Object) { throw new Exception('Expecting an instance of Varien_Object'); } - $class = get_class($object); + $class = $object::class; $out = new $class(); foreach ($object->getData() as $column => $value) { $value = parent::filter($value); diff --git a/lib/Varien/Object.php b/lib/Varien/Object.php index bc7b37e1467..fd9ec6314e5 100644 --- a/lib/Varien/Object.php +++ b/lib/Varien/Object.php @@ -616,7 +616,7 @@ public function __call($method, $args) return isset($this->_data[$key]); } throw new Varien_Exception( - 'Invalid method ' . get_class($this) . '::' . $method . '(' . print_r($args, true) . ')', + 'Invalid method ' . static::class . '::' . $method . '(' . print_r($args, true) . ')', ); } @@ -747,7 +747,7 @@ public function debug($data = null, &$objects = []) } elseif (is_array($value)) { $debug[$key] = $this->debug($value, $objects); } elseif ($value instanceof Varien_Object) { - $debug[$key . ' (' . get_class($value) . ')'] = $value->debug(null, $objects); + $debug[$key . ' (' . $value::class . ')'] = $value->debug(null, $objects); } } return $debug; diff --git a/lib/Varien/Object/Cache.php b/lib/Varien/Object/Cache.php index ff37e1f8599..e12dd6b386b 100644 --- a/lib/Varien/Object/Cache.php +++ b/lib/Varien/Object/Cache.php @@ -150,7 +150,7 @@ public function save($object, $idx = null, $tags = null) } if (isset($this->_objects[$idx])) { - throw new Varien_Exception('Object already exists in registry (' . $idx . '). Old object class: ' . get_class($this->_objects[$idx]) . ', new object class: ' . get_class($object)); + throw new Varien_Exception('Object already exists in registry (' . $idx . '). Old object class: ' . $this->_objects[$idx]::class . ', new object class: ' . $object::class); } $this->_objects[$idx] = $object; diff --git a/tests/unit/Mage/Core/Helper/SecurityTest.php b/tests/unit/Mage/Core/Helper/SecurityTest.php index 085be5fbc47..f79bd977608 100644 --- a/tests/unit/Mage/Core/Helper/SecurityTest.php +++ b/tests/unit/Mage/Core/Helper/SecurityTest.php @@ -120,7 +120,7 @@ public function testValidateAgainstBlockMethodBlacklistThrowsException( string $method, array $args ): void { - $this->expectExceptionMessage(sprintf('Action with combination block %s and method %s is forbidden.', get_class($block), $method)); + $this->expectExceptionMessage(sprintf('Action with combination block %s and method %s is forbidden.', $block::class, $method)); self::$subject->validateAgainstBlockMethodBlacklist($block, $method, $args); } }