Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

phpdoc type issue with attribute argument abstract methods Symfony\Component\Security\Core\Authorization\Voter\Voter #31245

Copy link
Copy link
Closed
@andrew-demb

Description

@andrew-demb
Issue body actions

Hello.
I emit issue with implementing voter, that extends from Symfony\Component\Security\Core\Authorization\Voter\Voter.

Symfony\Component\Security\Core\Authorization\Voter\Voter::supports() declares $attribute argument as string type, but it's not cover actual - nothing about check for type in parent vote() method no happening.

This lead to the issue.

Similar implementation of my voter

<?php
declare(strict_types=1);

use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;

final class IssueAuthorizationVoter extends Voter
{
    private $decisionManager;

    public function __construct(AccessDecisionManagerInterface $decisionManager)
    {
        $this->decisionManager = $decisionManager;
    }

    protected function supports($attribute, $subject): bool
    {
        return $this->isRequestView($attribute);
    }

    private function isRequestView(string $attribute): bool
    {
        return 'view' === $attribute;
    }

    protected function voteOnAttribute($attribute, $subject, TokenInterface $token): bool
    {
        return $this->decisionManager->decide($token, ['ROLE_RESOURCE_SUPPORT']);
    }
}

Issue: when called with Symfony\Component\Security\Core\Role\Role strict types in voter cause to fatal Type error: Argument 1 passed to IssueAuthorizationVoter::isRequestView() must be of the type string, object given

Link to voteOnAttribute()

/**
* Determines if the attribute and subject are supported by this voter.
*
* @param string $attribute An attribute
* @param mixed $subject The subject to secure, e.g. an object the user wants to access or any other PHP type
*
* @return bool True if the attribute and subject are supported, false otherwise
*/
abstract protected function supports($attribute, $subject);

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.