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] Mage_Admin (L7) and re-added composer patches #3660

Closed
wants to merge 19 commits into from
Closed
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
6 changes: 3 additions & 3 deletions app/code/core/Mage/Admin/Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function loadAclResources(Mage_Admin_Model_Acl $acl, $resource = null, $p
}

foreach ($children as $res) {
if ($res->disabled == 1) {
if ((string)$res->disabled === '1') {
continue;
}
$this->loadAclResources($acl, $res, $resourceName);
Expand All @@ -117,7 +117,7 @@ public function loadAclResources(Mage_Admin_Model_Acl $acl, $resource = null, $p
*/
public function getAclAssert($name = '')
{
$asserts = $this->getNode("admin/acl/asserts");
$asserts = $this->getNode('admin/acl/asserts');
if ($name === '') {
return $asserts;
}
Expand All @@ -133,7 +133,7 @@ public function getAclAssert($name = '')
*/
public function getAclPrivilegeSet($name = '')
{
$sets = $this->getNode("admin/acl/privilegeSets");
$sets = $this->getNode('admin/acl/privilegeSets');
if ($name === '') {
return $sets;
}
Expand Down
13 changes: 9 additions & 4 deletions app/code/core/Mage/Admin/Model/Resource/Acl.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public function loadAcl()

$rolesArr = $adapter->fetchAll($select);

assert(is_array($rolesArr));
$this->loadRoles($acl, $rolesArr);

$select = $adapter->select()
Expand All @@ -67,6 +68,7 @@ public function loadAcl()

$rulesArr = $adapter->fetchAll($select);

assert(is_array($rulesArr));
$this->loadRules($acl, $rulesArr);

return $acl;
Expand All @@ -93,7 +95,7 @@ public function loadRoles(Mage_Admin_Model_Acl $acl, array $rolesArr)
$roleId = $role['role_type'] . $role['user_id'];
if (!$acl->hasRole($roleId)) {
$acl->addRole(Mage::getModel('admin/acl_role_user', $roleId), $parent);
} else {
} elseif ($parent !== null) {
$acl->addRoleParent($roleId, $parent);
}
break;
Expand All @@ -118,9 +120,12 @@ public function loadRules(Mage_Admin_Model_Acl $acl, array $rulesArr)
$privileges = !empty($rule['privileges']) ? explode(',', $rule['privileges']) : null;

$assert = null;
if ($rule['assert_id'] != 0) {
$assertClass = Mage::getSingleton('admin/config')->getAclAssert($rule['assert_type'])->getClassName();
$assert = new $assertClass(unserialize($rule['assert_data'], ['allowed_classes' => false]));
if ($rule['assert_id'] !== '0') {
$assertType = Mage::getSingleton('admin/config')->getAclAssert($rule['assert_type']);
if ($assertType instanceof Mage_Core_Model_Config_Element) {
$assertClass = $assertType->getClassName();
$assert = new $assertClass(unserialize($rule['assert_data'], ['allowed_classes' => false]));
}
}
try {
if ($rule['permission'] == 'allow') {
Expand Down
36 changes: 18 additions & 18 deletions app/code/core/Mage/Admin/Model/Resource/Roles.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,48 +46,48 @@ protected function _construct()
/**
* Process role before saving
*
* @param Mage_Core_Model_Abstract|Mage_Admin_Model_Roles $role
* @param Mage_Admin_Model_Roles $object
* @return $this
*/
protected function _beforeSave(Mage_Core_Model_Abstract $role)
protected function _beforeSave(Mage_Core_Model_Abstract $object)
{
if ($role->getId() == '') {
if ($role->getIdFieldName()) {
$role->unsetData($role->getIdFieldName());
if ($object->getId() == '') {
if ($object->getIdFieldName()) {
$object->unsetData($object->getIdFieldName());
} else {
$role->unsetData('id');
$object->unsetData('id');
}
}

if ($role->getPid() > 0) {
if ($object->getPid() > 0) {
$select = $this->_getReadAdapter()->select()
->from($this->getMainTable(), ['tree_level'])
->where("{$this->getIdFieldName()} = :pid");

$binds = [
'pid' => (int) $role->getPid(),
'pid' => (int) $object->getPid(),
];

$treeLevel = $this->_getReadAdapter()->fetchOne($select, $binds);
$treeLevel = (int) $this->_getReadAdapter()->fetchOne($select, $binds);
} else {
$treeLevel = 0;
}

$role->setTreeLevel($treeLevel + 1);
$role->setRoleName($role->getName());
$object->setTreeLevel($treeLevel + 1);
$object->setRoleName($object->getName());

return $this;
}

/**
* Process role after saving
*
* @param Mage_Core_Model_Abstract $role
* @param Mage_Admin_Model_Roles $object
* @return $this
*/
protected function _afterSave(Mage_Core_Model_Abstract $role)
protected function _afterSave(Mage_Core_Model_Abstract $object)
{
$this->_updateRoleUsersAcl($role);
$this->_updateRoleUsersAcl($object);
Mage::app()->getCache()->clean(
Zend_Cache::CLEANING_MODE_MATCHING_TAG,
[Mage_Adminhtml_Block_Page_Menu::CACHE_TAGS]
Expand All @@ -98,14 +98,14 @@ protected function _afterSave(Mage_Core_Model_Abstract $role)
/**
* Process role after deleting
*
* @param Mage_Core_Model_Abstract $role
* @param Mage_Admin_Model_Roles $object
* @return $this
*/
protected function _afterDelete(Mage_Core_Model_Abstract $role)
protected function _afterDelete(Mage_Core_Model_Abstract $object)
{
$adapter = $this->_getWriteAdapter();
$adapter->delete($this->getMainTable(), ['parent_id = ?' => (int) $role->getId()]);
$adapter->delete($this->_ruleTable, ['role_id = ?' => (int) $role->getId()]);
$adapter->delete($this->getMainTable(), ['parent_id = ?' => (int) $object->getId()]);
$adapter->delete($this->_ruleTable, ['role_id = ?' => (int) $object->getId()]);
return $this;
}

Expand Down
65 changes: 27 additions & 38 deletions app/code/core/Mage/Admin/Model/Resource/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function recordLogin(Mage_Admin_Model_User $user)
* Load data by specified username
*
* @param string $username
* @return false|array
* @return array
*/
public function loadByUsername($username)
{
Expand Down Expand Up @@ -124,42 +124,31 @@ public function hasAssigned2Role($user)
}
}

/**
* Encrypt password
*
* @param string $pwStr
* @return string
*/
private function _encryptPassword($pwStr)
{
return Mage::helper('core')->getHash($pwStr, Mage_Admin_Model_User::HASH_SALT_LENGTH);
}

/**
* Set created/modified values before user save
*
* @param Mage_Admin_Model_User $user
* @param Mage_Admin_Model_User $object
* @inheritDoc
*/
protected function _beforeSave(Mage_Core_Model_Abstract $user)
protected function _beforeSave(Mage_Core_Model_Abstract $object)
{
if ($user->isObjectNew()) {
$user->setCreated($this->formatDate(true));
if ($object->isObjectNew()) {
$object->setCreated($this->formatDate(true));
}
$user->setModified($this->formatDate(true));
$object->setModified($this->formatDate(true));

return parent::_beforeSave($user);
return parent::_beforeSave($object);
}

/**
* Unserialize user extra data after user save
*
* @param Mage_Core_Model_Abstract $user
* @param Mage_Admin_Model_User $object
* @return $this
*/
protected function _afterSave(Mage_Core_Model_Abstract $user)
protected function _afterSave(Mage_Core_Model_Abstract $object)
{
$this->_unserializeExtraData($user);
$this->_unserializeExtraData($object);
return $this;
}

Expand All @@ -168,24 +157,24 @@ protected function _afterSave(Mage_Core_Model_Abstract $user)
*
* @inheritDoc
*/
protected function _afterLoad(Mage_Core_Model_Abstract $user)
protected function _afterLoad(Mage_Core_Model_Abstract $object)
{
return parent::_afterLoad($this->_unserializeExtraData($user));
return parent::_afterLoad($this->_unserializeExtraData($object));
}

/**
* Delete user role record with user
*
* @param Mage_Core_Model_Abstract $user
* @param Mage_Admin_Model_User $object
* @return $this
* @throws Exception
*/
public function delete(Mage_Core_Model_Abstract $user)
public function delete(Mage_Core_Model_Abstract $object)
{
$this->_beforeDelete($user);
$this->_beforeDelete($object);
$adapter = $this->_getWriteAdapter();

$uid = $user->getId();
$uid = $object->getId();
$adapter->beginTransaction();
try {
$conditions = [
Expand All @@ -199,14 +188,14 @@ public function delete(Mage_Core_Model_Abstract $user)
$adapter->rollBack();
throw $e;
}
$this->_afterDelete($user);
$this->_afterDelete($object);
return $this;
}

/**
* TODO: unify _saveRelations() and add() methods, they make same things
*
* @param Mage_Core_Model_Abstract|Mage_Admin_Model_User $user
* @param Mage_Admin_Model_User $user
* @return $this|Mage_Core_Model_Abstract
*/
public function _saveRelations(Mage_Core_Model_Abstract $user)
Expand Down Expand Up @@ -265,7 +254,7 @@ public function _saveRelations(Mage_Core_Model_Abstract $user)
/**
* Get user roles
*
* @param Mage_Core_Model_Abstract $user
* @param Mage_Admin_Model_User $user
* @return array
*/
public function getRoles(Mage_Core_Model_Abstract $user)
Expand Down Expand Up @@ -301,15 +290,15 @@ public function getRoles(Mage_Core_Model_Abstract $user)
/**
* Save user roles
*
* @param Mage_Core_Model_Abstract|Mage_Admin_Model_User $user
* @param Mage_Admin_Model_User $user
* @return $this
*/
public function add(Mage_Core_Model_Abstract $user)
{
$dbh = $this->_getWriteAdapter();
$aRoles = $this->hasAssigned2Role($user);
if (count($aRoles)) {
foreach ($aRoles as $idx => $data) {
if ($aRoles !== null && count($aRoles)) {
foreach ($aRoles as $data) {
$dbh->delete(
$this->getTable('admin/role'),
['role_id = ?' => $data['role_id']]
Expand Down Expand Up @@ -346,7 +335,7 @@ public function add(Mage_Core_Model_Abstract $user)
/**
* Delete user role
*
* @param Mage_Core_Model_Abstract|Mage_Admin_Model_User $user
* @param Mage_Admin_Model_User $user
* @return $this
*/
public function deleteFromRole(Mage_Core_Model_Abstract $user)
Expand All @@ -372,7 +361,7 @@ public function deleteFromRole(Mage_Core_Model_Abstract $user)
/**
* Check if role user exists
*
* @param Mage_Core_Model_Abstract|Mage_Admin_Model_User $user
* @param Mage_Admin_Model_User $user
* @return array
*/
public function roleUserExists(Mage_Core_Model_Abstract $user)
Expand Down Expand Up @@ -400,7 +389,7 @@ public function roleUserExists(Mage_Core_Model_Abstract $user)
/**
* Check if user exists
*
* @param Mage_Core_Model_Abstract|Mage_Admin_Model_User $user
* @param Mage_Admin_Model_User $user
* @return array|false
*/
public function userExists(Mage_Core_Model_Abstract $user)
Expand All @@ -424,7 +413,7 @@ public function userExists(Mage_Core_Model_Abstract $user)
/**
* Save user extra data
*
* @param Mage_Core_Model_Abstract $object
* @param Mage_Admin_Model_User $object
* @param string $data
* @return $this
*/
Expand All @@ -444,7 +433,7 @@ public function saveExtra($object, $data)
/**
* Set reload ACL flag
*
* @param Mage_Core_Model_Abstract $object
* @param Mage_Admin_Model_User $object
* @param int $flag
* @return $this
*/
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Admin/Model/Roles.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ protected function _buildResourcesArray(
//check children and run recursion if they exists
$children = $resource->children();
foreach ($children as $key => $child) {
if ($child->disabled == 1) {
if ((string)$child->disabled === '1') {
$resource->{$key} = null;
continue;
}
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 @@ -720,7 +720,7 @@ public function cleanPasswordsValidationData()
/**
* Simple sql format date
*
* @param string|bool $dayOnly
* @param bool $dayOnly
* @return string
*/
protected function _getDateNow($dayOnly = false)
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Core/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ public function jsonEncode($valueToEncode, $cycleCheck = false, $options = [])
*
* switch added to prevent exceptions in json_decode
*
* @param string $encodedValue
* @param null|bool|string $encodedValue
* @param int $objectDecodeType
* @return mixed
* @throws Zend_Json_Exception
Expand Down
Loading
Loading