Skip to content
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

PhpStan L5 fixes for Mage/Admin #2761

Merged
merged 2 commits into from
Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
41 changes: 18 additions & 23 deletions app/Mage.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,49 +68,49 @@ final class Mage
*
* @var array
*/
static private $_registry = [];
private static $_registry = [];

/**
* Application root absolute path
*
* @var string
*/
static private $_appRoot;
private static $_appRoot;

/**
* Application model
*
* @var Mage_Core_Model_App
*/
static private $_app;
private static $_app;

/**
* Config Model
*
* @var Mage_Core_Model_Config
*/
static private $_config;
private static $_config;

/**
* Event Collection Object
*
* @var Varien_Event_Collection
*/
static private $_events;
private static $_events;

/**
* Object cache instance
*
* @var Varien_Object_Cache
*/
static private $_objects;
private static $_objects;

/**
* Is developer mode flag
*
* @var bool
*/
static private $_isDeveloperMode = false;
private static $_isDeveloperMode = false;

/**
* Is allow throw Exception about headers already sent
Expand All @@ -124,7 +124,7 @@ final class Mage
*
* @var bool
*/
static private $_isInstalled;
private static $_isInstalled;

/**
* Magento edition constants
Expand All @@ -140,7 +140,7 @@ final class Mage
* @var string
* @static
*/
static private $_currentEdition = self::EDITION_COMMUNITY;
private static $_currentEdition = self::EDITION_COMMUNITY;

/**
* Gets the current Magento version string
Expand Down Expand Up @@ -182,9 +182,9 @@ public static function getOpenMageVersion()
{
$i = self::getOpenMageVersionInfo();
$versionString = "{$i['major']}.{$i['minor']}.{$i['patch']}";
if ( $i['stability'] || $i['number'] ) {
if ($i['stability'] || $i['number']) {
$versionString .= "-";
if ( $i['stability'] && $i['number'] ) {
if ($i['stability'] && $i['number']) {
$versionString .= implode('.', [$i['stability'], $i['number']]);
} else {
$versionString .= implode('', [$i['stability'], $i['number']]);
Expand Down Expand Up @@ -240,7 +240,7 @@ public static function getOpenMageVersionInfo()
*/
public static function getEdition()
{
return self::$_currentEdition;
return self::$_currentEdition;
}

/**
Expand Down Expand Up @@ -508,7 +508,7 @@ public static function dispatchEvent($name, array $data = [])
*
* @link Mage_Core_Model_Config::getModelInstance
* @param string $modelClass
* @param array|object $arguments
* @param array|string|object $arguments
* @return Mage_Core_Model_Abstract|false
*/
public static function getModel($modelClass = '', $arguments = [])
Expand Down Expand Up @@ -845,8 +845,7 @@ public static function log($message, $level = null, $file = '', $forceLog = fals
if (empty($file)) {
$file = self::getStoreConfig('dev/log/file');
}
}
catch (Exception $e) {
} catch (Exception $e) {
$logActive = true;
}

Expand Down Expand Up @@ -878,7 +877,7 @@ public static function log($message, $level = null, $file = '', $forceLog = fals
',',
(string) self::getConfig()->getNode('dev/log/allowedFileExtensions', Mage_Core_Model_Store::DEFAULT_CODE)
);
if ( ! ($extension = pathinfo($file, PATHINFO_EXTENSION)) || ! in_array($extension, $_allowedFileExtensions)) {
if (! ($extension = pathinfo($file, PATHINFO_EXTENSION)) || ! in_array($extension, $_allowedFileExtensions)) {
return;
}

Expand All @@ -900,8 +899,7 @@ public static function log($message, $level = null, $file = '', $forceLog = fals
$writerModel = (string)self::getConfig()->getNode('global/log/core/writer_model');
if (!self::$_app || !$writerModel) {
$writer = new Zend_Log_Writer_Stream($logFile);
}
else {
} else {
$writer = new $writerModel($logFile);
}
$writer->setFormatter($formatter);
Expand All @@ -914,8 +912,7 @@ public static function log($message, $level = null, $file = '', $forceLog = fals

$message = addcslashes($message, '<?');
$loggers[$file]->log($message, $level);
}
catch (Exception $e) {
} catch (Exception $e) {
}
}

Expand Down Expand Up @@ -973,7 +970,6 @@ public static function printException(Throwable $e, $extra = '')
print $e->getTraceAsString();
print '</pre>';
} else {

$reportData = [
(!empty($extra) ? $extra . "\n\n" : '') . $e->getMessage(),
$e->getTraceAsString()
Expand All @@ -993,8 +989,8 @@ public static function printException(Throwable $e, $extra = '')
try {
$storeCode = self::app()->getStore()->getCode();
$reportData['skin'] = $storeCode;
} catch (Exception $e) {
}
catch (Exception $e) {}

require_once(self::getBaseDir() . DS . 'errors' . DS . 'report.php');
}
Expand Down Expand Up @@ -1059,6 +1055,5 @@ public static function getScriptSystemUrl($folder, $exitIfNot = false)
*/
public static function setIsDownloader()
{

}
}
3 changes: 1 addition & 2 deletions app/code/core/Mage/Admin/Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public function __construct()
parent::__construct();
$this->setCacheId('adminhtml_acl_menu_config');

/** @var Varien_Simplexml_Config $adminhtmlConfig */
$adminhtmlConfig = Mage::app()->loadCache($this->getCacheId());
if ($adminhtmlConfig) {
$this->_adminhtmlConfig = new Varien_Simplexml_Config($adminhtmlConfig);
Expand Down Expand Up @@ -80,7 +79,7 @@ public function __construct()
* Load Acl resources from config
*
* @param Mage_Admin_Model_Acl $acl
* @param Mage_Core_Model_Config_Element $resource
* @param Mage_Core_Model_Config_Element|Varien_Simplexml_Element $resource
* @param string $parentName
* @return $this
*/
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Admin/Model/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function actionPreDispatchAdmin($observer)
$session->login($username, $password, $request);
$request->setPost('login', null);
} else {
if ($request && !$request->getParam('messageSent')) {
if (!$request->getParam('messageSent')) {
Mage::getSingleton('adminhtml/session')->addError(
Mage::helper('adminhtml')->__('Invalid Form Key. Please refresh the page.')
);
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Admin/Model/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class Mage_Admin_Model_Session extends Mage_Core_Model_Session_Abstract
/**
* Whether it is the first page after successfull login
*
* @var bool
* @var bool|null
*/
protected $_isFirstPageAfterLogin;

Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Admin/Model/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ protected function _getHelper($helperName)
/**
* Find first menu item that user is able to access
*
* @param Mage_Core_Model_Config_Element $parent
* @param Mage_Core_Model_Config_Element|Varien_Simplexml_Element $parent
* @param string $path
* @param int $level
* @return string
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/AdminNotification/Model/Feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public function getFrequency()
/**
* Retrieve Last update time
*
* @return int
* @return string|false
*/
public function getLastUpdate()
{
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Core/Model/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -1162,7 +1162,7 @@ public function getCache()
* Loading cache data
*
* @param string $id
* @return mixed
* @return string|false
*/
public function loadCache($id)
{
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Core/Model/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ public function getFrontend()
* Load data from cache by id
*
* @param string $id
* @return string
* @return string|false
*/
public function load($id)
{
Expand Down
4 changes: 2 additions & 2 deletions app/code/core/Mage/Core/Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -1013,9 +1013,9 @@ public function determineOmittedNamespace($name, $asFullModuleName = false)
* specidied xml file name to one object
*
* @param string $fileName
* @param null|Mage_Core_Model_Config_Base $mergeToObject
* @param null|Mage_Core_Model_Config_Base|Varien_Simplexml_Config $mergeToObject
* @param null $mergeModel
* @return Mage_Core_Model_Config_Base
* @return Mage_Core_Model_Config_Base|Varien_Simplexml_Config
*/
public function loadModulesConfiguration($fileName, $mergeToObject = null, $mergeModel = null)
{
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Log/Model/Visitor/Online.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function prepare()
/**
* Retrieve last prepare at timestamp
*
* @return int
* @return string|false
*/
public function getPrepareAt()
{
Expand Down
4 changes: 2 additions & 2 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@
umask(0);

/* Store or website code */
$mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : '';
$mageRunCode = $_SERVER['MAGE_RUN_CODE'] ?? '';

/* Run store or run website */
$mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'store';
$mageRunType = $_SERVER['MAGE_RUN_TYPE'] ?? 'store';

if (file_exists($maintenanceFile)) {
$maintenanceBypass = false;
Expand Down
2 changes: 1 addition & 1 deletion lib/Varien/Cache/Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public function load($id, $doNotTestCacheValidity = false, $doNotUnserialize = f
// Seems we've got chunked data

$arr = explode('|', $data);
$chunks = isset($arr[1]) ? $arr[1] : false;
$chunks = $arr[1] ?? false;
$chunkData = [];

if ($chunks && is_numeric($chunks)) {
Expand Down