Modernize to PHP 8.0

This commit is contained in:
Yassine Guedidi
2025-04-05 13:56:56 +02:00
parent 1d5674a230
commit a107773c11
31 changed files with 97 additions and 199 deletions

View File

@ -36,14 +36,9 @@ class AdminVoter extends Voter
return false;
}
switch ($attribute) {
case self::LIST_USERS:
case self::CREATE_USERS:
case self::LIST_IGNORE_ORIGIN_INSTANCE_RULES:
case self::CREATE_IGNORE_ORIGIN_INSTANCE_RULES:
return $this->security->isGranted('ROLE_SUPER_ADMIN');
}
return false;
return match ($attribute) {
self::LIST_USERS, self::CREATE_USERS, self::LIST_IGNORE_ORIGIN_INSTANCE_RULES, self::CREATE_IGNORE_ORIGIN_INSTANCE_RULES => $this->security->isGranted('ROLE_SUPER_ADMIN'),
default => false,
};
}
}

View File

@ -35,12 +35,9 @@ class AnnotationVoter extends Voter
return false;
}
switch ($attribute) {
case self::EDIT:
case self::DELETE:
return $subject->getUser() === $user;
}
return false;
return match ($attribute) {
self::EDIT, self::DELETE => $subject->getUser() === $user,
default => false,
};
}
}

View File

@ -47,24 +47,9 @@ class EntryVoter extends Voter
return false;
}
switch ($attribute) {
case self::VIEW:
case self::EDIT:
case self::RELOAD:
case self::STAR:
case self::ARCHIVE:
case self::SHARE:
case self::UNSHARE:
case self::EXPORT:
case self::DELETE:
case self::LIST_ANNOTATIONS:
case self::CREATE_ANNOTATIONS:
case self::LIST_TAGS:
case self::TAG:
case self::UNTAG:
return $user === $subject->getUser();
}
return false;
return match ($attribute) {
self::VIEW, self::EDIT, self::RELOAD, self::STAR, self::ARCHIVE, self::SHARE, self::UNSHARE, self::EXPORT, self::DELETE, self::LIST_ANNOTATIONS, self::CREATE_ANNOTATIONS, self::LIST_TAGS, self::TAG, self::UNTAG => $user === $subject->getUser(),
default => false,
};
}
}

View File

@ -32,12 +32,9 @@ class IgnoreOriginInstanceRuleVoter extends Voter
protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token): bool
{
switch ($attribute) {
case self::EDIT:
case self::DELETE:
return $this->security->isGranted('ROLE_SUPER_ADMIN');
}
return false;
return match ($attribute) {
self::EDIT, self::DELETE => $this->security->isGranted('ROLE_SUPER_ADMIN'),
default => false,
};
}
}

View File

@ -35,12 +35,9 @@ class IgnoreOriginUserRuleVoter extends Voter
return false;
}
switch ($attribute) {
case self::EDIT:
case self::DELETE:
return $subject->getConfig()->getUser() === $user;
}
return false;
return match ($attribute) {
self::EDIT, self::DELETE => $subject->getConfig()->getUser() === $user,
default => false,
};
}
}

View File

@ -41,22 +41,9 @@ class MainVoter extends Voter
protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token): bool
{
switch ($attribute) {
case self::LIST_ENTRIES:
case self::CREATE_ENTRIES:
case self::EDIT_ENTRIES:
case self::EXPORT_ENTRIES:
case self::IMPORT_ENTRIES:
case self::DELETE_ENTRIES:
case self::LIST_TAGS:
case self::CREATE_TAGS:
case self::DELETE_TAGS:
case self::LIST_SITE_CREDENTIALS:
case self::CREATE_SITE_CREDENTIALS:
case self::EDIT_CONFIG:
return $this->security->isGranted('ROLE_USER');
}
return false;
return match ($attribute) {
self::LIST_ENTRIES, self::CREATE_ENTRIES, self::EDIT_ENTRIES, self::EXPORT_ENTRIES, self::IMPORT_ENTRIES, self::DELETE_ENTRIES, self::LIST_TAGS, self::CREATE_TAGS, self::DELETE_TAGS, self::LIST_SITE_CREDENTIALS, self::CREATE_SITE_CREDENTIALS, self::EDIT_CONFIG => $this->security->isGranted('ROLE_USER'),
default => false,
};
}
}

View File

@ -35,12 +35,9 @@ class SiteCredentialVoter extends Voter
return false;
}
switch ($attribute) {
case self::EDIT:
case self::DELETE:
return $user === $subject->getUser();
}
return false;
return match ($attribute) {
self::EDIT, self::DELETE => $user === $subject->getUser(),
default => false,
};
}
}

View File

@ -42,13 +42,9 @@ class TagVoter extends Voter
return false;
}
switch ($attribute) {
case self::VIEW:
case self::EDIT:
case self::DELETE:
return $this->security->isGranted('ROLE_USER');
}
return false;
return match ($attribute) {
self::VIEW, self::EDIT, self::DELETE => $this->security->isGranted('ROLE_USER'),
default => false,
};
}
}

View File

@ -35,12 +35,9 @@ class TaggingRuleVoter extends Voter
return false;
}
switch ($attribute) {
case self::EDIT:
case self::DELETE:
return $subject->getConfig()->getUser() === $user;
}
return false;
return match ($attribute) {
self::EDIT, self::DELETE => $subject->getConfig()->getUser() === $user,
default => false,
};
}
}