mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-12-20 18:09:30 +00:00
Applied symplify rules to codebase.
This commit is contained in:
parent
2f20d90041
commit
388e847b17
136 changed files with 1370 additions and 789 deletions
|
|
@ -26,6 +26,7 @@ namespace App\Security\Voter;
|
|||
|
||||
use App\Entity\Attachments\Attachment;
|
||||
use App\Entity\UserSystem\User;
|
||||
use function in_array;
|
||||
|
||||
class AttachmentVoter extends ExtendedVoter
|
||||
{
|
||||
|
|
@ -54,7 +55,7 @@ class AttachmentVoter extends ExtendedVoter
|
|||
protected function supports($attribute, $subject)
|
||||
{
|
||||
if ($subject instanceof Attachment) {
|
||||
return \in_array($attribute, $this->resolver->listOperationsForPermission('parts_attachments'), false);
|
||||
return in_array($attribute, $this->resolver->listOperationsForPermission('parts_attachments'), false);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -35,13 +35,12 @@ use Symfony\Component\Security\Core\Authorization\Voter\Voter;
|
|||
*/
|
||||
abstract class ExtendedVoter extends Voter
|
||||
{
|
||||
protected $entityManager;
|
||||
/**
|
||||
* @var PermissionResolver
|
||||
*/
|
||||
protected $resolver;
|
||||
|
||||
protected $entityManager;
|
||||
|
||||
public function __construct(PermissionResolver $resolver, EntityManagerInterface $entityManager)
|
||||
{
|
||||
$this->resolver = $resolver;
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ class PermissionVoter extends ExtendedVoter
|
|||
protected function supports($attribute, $subject)
|
||||
{
|
||||
//Check if the attribute has the form @permission.operation
|
||||
if (preg_match('/^@\\w+\\.\\w+$/', $attribute)) {
|
||||
if (preg_match('#^@\\w+\\.\\w+$#', $attribute)) {
|
||||
$attribute = ltrim($attribute, '@');
|
||||
[$perm, $op] = explode('.', $attribute);
|
||||
|
||||
|
|
|
|||
|
|
@ -34,6 +34,8 @@ use App\Entity\Parts\Storelocation;
|
|||
use App\Entity\Parts\Supplier;
|
||||
use App\Entity\PriceInformations\Currency;
|
||||
use App\Entity\UserSystem\User;
|
||||
use function get_class;
|
||||
use function is_object;
|
||||
|
||||
class StructureVoter extends ExtendedVoter
|
||||
{
|
||||
|
|
@ -47,7 +49,7 @@ class StructureVoter extends ExtendedVoter
|
|||
*/
|
||||
protected function supports($attribute, $subject)
|
||||
{
|
||||
if (\is_object($subject)) {
|
||||
if (is_object($subject)) {
|
||||
$permission_name = $this->instanceToPermissionName($subject);
|
||||
//If permission name is null, then the subject is not supported
|
||||
return (null !== $permission_name) && $this->resolver->isValidOperation($permission_name, $attribute);
|
||||
|
|
@ -63,7 +65,7 @@ class StructureVoter extends ExtendedVoter
|
|||
*/
|
||||
protected function instanceToPermissionName($subject): ?string
|
||||
{
|
||||
$class_name = \get_class($subject);
|
||||
$class_name = get_class($subject);
|
||||
switch ($class_name) {
|
||||
case AttachmentType::class:
|
||||
return 'attachment_types';
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ declare(strict_types=1);
|
|||
namespace App\Security\Voter;
|
||||
|
||||
use App\Entity\UserSystem\User;
|
||||
use function in_array;
|
||||
|
||||
class UserVoter extends ExtendedVoter
|
||||
{
|
||||
|
|
@ -39,7 +40,7 @@ class UserVoter extends ExtendedVoter
|
|||
protected function supports($attribute, $subject)
|
||||
{
|
||||
if ($subject instanceof User) {
|
||||
return \in_array($attribute, array_merge(
|
||||
return in_array($attribute, array_merge(
|
||||
$this->resolver->listOperationsForPermission('users'),
|
||||
$this->resolver->listOperationsForPermission('self')),
|
||||
false
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue