Skip to content

Commit c97c97a

Browse files
sreichelhirale
authored andcommitted
rector: ClassOnThisVariableObjectRector & ClassOnObjectRector (OpenMage#4878)
* rector: `ClassOnThisVariableObjectRector` & `ClassOnObjectRector` - see https://getrector.com/rule-detail/class-on-this-variable-object-rector - see https://getrector.com/rule-detail/class-on-object-rector * fix * sprintf
1 parent 844d121 commit c97c97a

File tree

30 files changed

+41
-38
lines changed

30 files changed

+41
-38
lines changed

.rector.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,7 @@
124124
Php80\Class_\AnnotationToAttributeRector::class, # todo: wait for php80
125125
Php80\Class_\ClassPropertyAssignToConstructorPromotionRector::class, # todo: wait for php80
126126
Php80\Class_\StringableForToStringRector::class, # todo: wait for php80
127-
Php80\ClassConstFetch\ClassOnThisVariableObjectRector::class, # todo: TMP
128127
Php80\ClassMethod\AddParamBasedOnParentClassMethodRector::class, # todo: TMP
129-
Php80\FuncCall\ClassOnObjectRector::class, # todo: TMP
130128
Php81\Array_\FirstClassCallableRector::class, # todo: TMP
131129
Php81\FuncCall\NullToStrictStringFuncCallArgRector::class, # todo: check later
132130
Strict\Empty_\DisallowedEmptyRuleFixerRector::class, # todo: TMP

app/code/core/Mage/Api2/Model/Resource.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ public function setApiType($apiType)
376376
public function getVersion()
377377
{
378378
if ($this->_version === null) {
379-
if (preg_match('/^.+([1-9]\d*)$/', get_class($this), $matches)) {
379+
if (preg_match('/^.+([1-9]\d*)$/', static::class, $matches)) {
380380
$this->setVersion($matches[1]);
381381
} else {
382382
throw new Exception('Can not determine version from class name');

app/code/core/Mage/Catalog/Model/Resource/Abstract.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ protected function _deleteAttributes($object, $table, $info)
441441
*/
442442
protected function _getOrigObject($object)
443443
{
444-
$className = get_class($object);
444+
$className = $object::class;
445445
$origObject = new $className();
446446
$origObject->setData([]);
447447
$origObject->setStoreId($object->getStoreId());

app/code/core/Mage/Cms/Block/Widget/Block.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ protected function _beforeToHtml()
4747
{
4848
parent::_beforeToHtml();
4949
$blockId = $this->getData('block_id');
50-
$blockHash = get_class($this) . $blockId;
50+
$blockHash = static::class . $blockId;
5151

5252
if (isset(self::$_widgetUsageMap[$blockHash])) {
5353
return $this;

app/code/core/Mage/Core/Block/Abstract.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1153,7 +1153,7 @@ public function getModuleName()
11531153
{
11541154
$module = $this->getData('module_name');
11551155
if (is_null($module)) {
1156-
$class = get_class($this);
1156+
$class = static::class;
11571157
$module = substr($class, 0, strpos($class, '_Block'));
11581158
$this->setData('module_name', $module);
11591159
}

app/code/core/Mage/Core/Block/Template.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ public function fetchView($fileName)
248248
onmouseout="this.style.zIndex='998'" title="{$fileName}">{$fileName}</div>
249249
HTML;
250250
if (Mage::app()->getStore()->isAdmin() ? self::$_showTemplateHintsBlocksAdmin : self::$_showTemplateHintsBlocks) {
251-
$thisClass = get_class($this);
251+
$thisClass = static::class;
252252
echo <<<HTML
253253
<div style="position:absolute; right:0; top:0; padding:2px 5px; background:{$cacheHintStatusColor}; color:blue; font:normal 11px Arial;
254254
text-align:left !important; z-index:998;text-transform: none;" onmouseover="this.style.zIndex='999'" onmouseout="this.style.zIndex='998'"
@@ -264,7 +264,7 @@ public function fetchView($fileName)
264264
) {
265265
include $this->_viewDir . DS . $fileName;
266266
} else {
267-
$thisClass = get_class($this);
267+
$thisClass = static::class;
268268
Mage::log('Not valid template file:' . $fileName . ' class: ' . $thisClass, Zend_Log::CRIT, null, true);
269269
}
270270
} catch (Throwable $e) {

app/code/core/Mage/Core/Controller/Varien/Action.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,7 @@ protected function _isUrlInternal($url)
813813
protected function _getRealModuleName()
814814
{
815815
if (empty($this->_realModuleName)) {
816-
$class = get_class($this);
816+
$class = static::class;
817817
$this->_realModuleName = substr(
818818
$class,
819819
0,

app/code/core/Mage/Core/Helper/Abstract.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ protected function _cleanCache($tags = [])
108108
protected function _getModuleName()
109109
{
110110
if (!$this->_moduleName) {
111-
$class = get_class($this);
111+
$class = static::class;
112112
$this->_moduleName = implode('_', array_slice(explode('_', $class), 0, 2));
113113
}
114114
return $this->_moduleName;

app/code/core/Mage/Core/Helper/Security.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function validateAgainstBlockMethodBlacklist(Mage_Core_Block_Abstract $bl
3232
}
3333
if ($block instanceof $action['block'] && strtolower($action['method']) === $calledMethod) {
3434
Mage::throwException(
35-
sprintf('Action with combination block %s and method %s is forbidden.', get_class($block), $method),
35+
sprintf('Action with combination block %s and method %s is forbidden.', $block::class, $method),
3636
);
3737
}
3838
}

app/code/core/Mage/Core/Model/App.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1439,7 +1439,7 @@ protected function _callObserverMethod($object, $method, $observer, $observerNam
14391439
$object->$method($observer);
14401440
} elseif (Mage::getIsDeveloperMode()) {
14411441
if (is_object($object)) {
1442-
$message = 'Method "' . $method . '" is not defined in "' . get_class($object) . '"';
1442+
$message = 'Method "' . $method . '" is not defined in "' . $object::class . '"';
14431443
} else {
14441444
$message = 'Class from observer "' . $observerName . '" is not initialized';
14451445
}

0 commit comments

Comments
 (0)