Skip to content

Commit

Permalink
Fix PHPStan error in Acl component
Browse files Browse the repository at this point in the history
We must add integer to the allowed types of optional $pluginID arg.
Else PHPstan level 5 check fails with:

------ --------------------------------------------------------------------
  Line   Bootstrap/Acl.php
 ------ --------------------------------------------------------------------
  53     Parameter #4 $pluginID of method
         Shopware_Components_Acl::createResource() expects null, int given.
 ------ --------------------------------------------------------------------
  • Loading branch information
myfluxi committed Dec 12, 2020
1 parent 3e558df commit 46aaced
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions engine/Shopware/Components/Acl.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ public function initAclRoles()
$repository = $this->em->getRepository(Role::class);
$roles = $repository->findAll();

/** @var \Shopware\Models\User\Role $role */
/** @var Role $role */
foreach ($roles as $role) {
/** @var \Shopware\Models\User\Role|null $parent */
/** @var Role|null $parent */
$parent = $role->getParent();

// Parent exist and not already added?
Expand Down Expand Up @@ -104,7 +104,7 @@ public function initAclRoleConditions()
{
$rules = $this->em->getRepository(Rule::class)->findAll();

/** @var \Shopware\Models\User\Rule $rule */
/** @var Rule $rule */
foreach ($rules as $rule) {
$role = $rule->getRole();

Expand Down Expand Up @@ -144,12 +144,14 @@ public function hasResourceInDatabase($resourceName)
* @param string $resourceName - unique identifier or resource key
* @param array|null $privileges - optionally array [a,b,c] of new privileges
* @param null $menuItemName - optionally s_core_menu.name item to link to this resource
* @param null $pluginID - optionally pluginID that implements this resource
*
* @throws Enlight_Exception
* @param int|null $pluginID - optionally pluginID that implements this resource
*/
public function createResource($resourceName, array $privileges = null, $menuItemName = null, $pluginID = null)
{
public function createResource(
$resourceName,
array $privileges = null,
/* @noinspection PhpUnusedParameterInspection */ $menuItemName = null,
$pluginID = null
){
// Check if resource already exists
if ($this->hasResourceInDatabase($resourceName)) {
throw new Enlight_Exception(sprintf('Resource "%s" already exists', $resourceName));
Expand Down Expand Up @@ -206,14 +208,14 @@ public function deleteResource($resourceName)
{
$repository = $this->em->getRepository(Resource::class);

/** @var \Shopware\Models\User\Resource|null $resource */
/** @var Resource|null $resource */
$resource = $repository->findOneBy(['name' => $resourceName]);
if ($resource === null) {
return false;
}

// The mapping table s_core_acl_roles must be cleared manually.
$this->em->getConnection()->executeUpdate(
$this->em->getConnection()->executeStatement(
'DELETE FROM s_core_acl_roles WHERE resourceID = ?',
[$resource->getId()]
);
Expand Down

0 comments on commit 46aaced

Please sign in to comment.