Added phpstan template annotations to Voters to fix phpstan issues

This commit is contained in:
Jan Böhmer 2024-02-19 00:01:16 +01:00
parent e9d03a0c95
commit 49034fabf2
16 changed files with 43 additions and 0 deletions

View file

@ -45,6 +45,9 @@ use Symfony\Component\Security\Core\Authorization\Voter\Voter;
use function in_array;
/**
* @phpstan-extends Voter<non-empty-string, Attachment|class-string>
*/
final class AttachmentVoter extends Voter
{
private const ALLOWED_ATTRIBUTES = ['read', 'view', 'edit', 'delete', 'create', 'show_private', 'show_history'];

View file

@ -29,6 +29,9 @@ use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
/**
* @phpstan-extends Voter<non-empty-string, ProjectBOMEntry|class-string>
*/
class BOMEntryVoter extends Voter
{

View file

@ -28,6 +28,9 @@ use App\Services\UserSystem\VoterHelper;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
/**
* @phpstan-extends Voter<non-empty-string, Group|class-string>
*/
final class GroupVoter extends Voter
{

View file

@ -32,6 +32,7 @@ use Symfony\Component\Security\Core\Authorization\Voter\Voter;
/**
* This voter implements a virtual role, which can be used if the user has any permission set to allowed.
* We use this to restrict access to the homepage.
* @phpstan-extends Voter<non-empty-string, null>
*/
final class HasAccessPermissionsVoter extends Voter
{

View file

@ -30,6 +30,11 @@ use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* This voter implements a virtual role, which can be used if the user has any permission set to allowed.
* We use this to restrict access to the homepage.
* @phpstan-extends Voter<non-empty-string, User>
*/
final class ImpersonateUserVoter extends Voter
{

View file

@ -47,6 +47,9 @@ use App\Services\UserSystem\VoterHelper;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
/**
* @phpstan-extends Voter<non-empty-string, LabelProfile|class-string>
*/
final class LabelProfileVoter extends Voter
{
protected const MAPPING = [

View file

@ -31,6 +31,9 @@ use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
/**
* @phpstan-extends Voter<non-empty-string, AbstractLogEntry>
*/
final class LogEntryVoter extends Voter
{
final public const ALLOWED_OPS = ['read', 'show_details', 'delete'];

View file

@ -51,6 +51,9 @@ use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
/**
* @phpstan-extends Voter<non-empty-string, Orderdetail|class-string>
*/
final class OrderdetailVoter extends Voter
{
public function __construct(private readonly Security $security, private readonly VoterHelper $helper)

View file

@ -44,6 +44,9 @@ use RuntimeException;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
/**
* @phpstan-extends Voter<non-empty-string, AbstractParameter|class-string>
*/
final class ParameterVoter extends Voter
{

View file

@ -51,6 +51,7 @@ use Symfony\Component\Security\Core\Authorization\Voter\Voter;
/**
* This voter handles permissions for part associations.
* The permissions are inherited from the part.
* @phpstan-extends Voter<non-empty-string, PartAssociation|class-string>
*/
final class PartAssociationVoter extends Voter
{

View file

@ -51,6 +51,9 @@ use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
/**
* @phpstan-extends Voter<non-empty-string, PartLot|class-string>
*/
final class PartLotVoter extends Voter
{
public function __construct(private readonly Security $security, private readonly VoterHelper $helper)

View file

@ -32,6 +32,8 @@ use Symfony\Component\Security\Core\Authorization\Voter\Voter;
* A Voter that votes on Part entities.
*
* See parts permissions for valid operations.
*
* @phpstan-extends Voter<non-empty-string, Part|class-string>
*/
final class PartVoter extends Voter
{

View file

@ -31,6 +31,7 @@ use Symfony\Component\Security\Core\Authorization\Voter\Voter;
* This voter allows you to directly check permissions from the permission structure, without passing an object.
* This use the syntax like "@permission.op"
* However you should use the "normal" object based voters if possible, because they are needed for a future ACL system.
* @phpstan-extends Voter<non-empty-string, null>
*/
final class PermissionVoter extends Voter
{

View file

@ -52,6 +52,9 @@ use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
/**
* @phpstan-extends Voter<non-empty-string, Pricedetail|class-string>
*/
final class PricedetailVoter extends Voter
{
public function __construct(private readonly Security $security, private readonly VoterHelper $helper)

View file

@ -39,6 +39,9 @@ use Symfony\Component\Security\Core\Authorization\Voter\Voter;
use function get_class;
use function is_object;
/**
* @phpstan-extends Voter<non-empty-string, AttachmentType|Category|Project|Footprint|Manufacturer|StorageLocation|Supplier|Currency|MeasurementUnit|class-string>
*/
final class StructureVoter extends Voter
{
protected const OBJ_PERM_MAP = [

View file

@ -30,6 +30,9 @@ use Symfony\Component\Security\Core\Authorization\Voter\Voter;
use function in_array;
/**
* @phpstan-extends Voter<non-empty-string, User|class-string>
*/
final class UserVoter extends Voter
{
public function __construct(private readonly VoterHelper $helper, private readonly PermissionManager $resolver)