From 1cf8c3dad63c6307c2e924d88c5bca565372641f Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos <1697880+AngelFQC@users.noreply.github.com> Date: Sat, 13 Jul 2024 11:07:51 -0500 Subject: [PATCH] Minor: Format code --- .../Controller/PermissionsController.php | 5 +++-- .../DataFixtures/PermissionFixtures.php | 5 +++-- .../DataFixtures/SettingsCurrentFixtures.php | 3 +-- src/CoreBundle/Entity/Permission.php | 4 +++- src/CoreBundle/Entity/PermissionRelRole.php | 15 ++++++++++----- .../Schema/V200/Version20201216122012.php | 4 ++-- .../Schema/V200/Version20240709222700.php | 7 ++++--- .../Repository/PermissionRelRoleRepository.php | 1 - .../Repository/PermissionRepository.php | 1 - .../ServiceHelper/PermissionServiceHelper.php | 7 ++++--- 10 files changed, 30 insertions(+), 22 deletions(-) diff --git a/src/CoreBundle/Controller/PermissionsController.php b/src/CoreBundle/Controller/PermissionsController.php index d384020330..eaa47a3fc8 100644 --- a/src/CoreBundle/Controller/PermissionsController.php +++ b/src/CoreBundle/Controller/PermissionsController.php @@ -11,6 +11,7 @@ use Chamilo\CoreBundle\Form\PermissionType; use Chamilo\CoreBundle\Repository\PermissionRelRoleRepository; use Chamilo\CoreBundle\Repository\PermissionRepository; use Chamilo\CoreBundle\ServiceHelper\PermissionServiceHelper; +use DateTime; use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; @@ -50,7 +51,7 @@ class PermissionsController extends AbstractController $permRelRole->setRoleCode($role); } $permRelRole->setChangeable(true); - $permRelRole->setUpdatedAt(new \DateTime()); + $permRelRole->setUpdatedAt(new DateTime()); $em->persist($permRelRole); } else { if ($permRelRole) { @@ -79,7 +80,7 @@ class PermissionsController extends AbstractController return $this->render('@ChamiloCore/Permission/index.html.twig', [ 'permissions' => $permissions, 'forms' => $forms, - 'roles' => $roles + 'roles' => $roles, ]); } diff --git a/src/CoreBundle/DataFixtures/PermissionFixtures.php b/src/CoreBundle/DataFixtures/PermissionFixtures.php index 1a2619cccb..7f60c373a3 100644 --- a/src/CoreBundle/DataFixtures/PermissionFixtures.php +++ b/src/CoreBundle/DataFixtures/PermissionFixtures.php @@ -8,6 +8,7 @@ namespace Chamilo\CoreBundle\DataFixtures; use Chamilo\CoreBundle\Entity\Permission; use Chamilo\CoreBundle\Entity\PermissionRelRole; +use DateTime; use Doctrine\Bundle\FixturesBundle\Fixture; use Doctrine\Bundle\FixturesBundle\FixtureGroupInterface; use Doctrine\Persistence\ObjectManager; @@ -40,12 +41,12 @@ class PermissionFixtures extends Fixture implements FixtureGroupInterface $manager->flush(); foreach ($roles as $roleName => $roleCode) { - if (in_array($roleCode, $permissionsMapping[$permData['slug']])) { + if (\in_array($roleCode, $permissionsMapping[$permData['slug']])) { $permRelRole = new PermissionRelRole(); $permRelRole->setPermission($permission); $permRelRole->setRoleCode($roleName); $permRelRole->setChangeable(true); - $permRelRole->setUpdatedAt(new \DateTime()); + $permRelRole->setUpdatedAt(new DateTime()); $manager->persist($permRelRole); } } diff --git a/src/CoreBundle/DataFixtures/SettingsCurrentFixtures.php b/src/CoreBundle/DataFixtures/SettingsCurrentFixtures.php index 5607791b93..0fe2fc3425 100644 --- a/src/CoreBundle/DataFixtures/SettingsCurrentFixtures.php +++ b/src/CoreBundle/DataFixtures/SettingsCurrentFixtures.php @@ -2135,9 +2135,8 @@ class SettingsCurrentFixtures extends Fixture implements FixtureGroupInterface [ 'name' => 'access_to_personal_file_for_all', 'title' => 'Access to personal file for all', - 'comment' => "Allows all users to access, view, and manage their personal files within the system.", + 'comment' => 'Allows all users to access, view, and manage their personal files within the system.', ], - ], 'language' => [ [ diff --git a/src/CoreBundle/Entity/Permission.php b/src/CoreBundle/Entity/Permission.php index 62ec07990c..81646dc56f 100644 --- a/src/CoreBundle/Entity/Permission.php +++ b/src/CoreBundle/Entity/Permission.php @@ -11,7 +11,6 @@ use Doctrine\ORM\Mapping as ORM; use Stringable; use Symfony\Component\Validator\Constraints as Assert; - #[ORM\Entity(repositoryClass: PermissionRepository::class)] #[ORM\Table(name: 'permission')] /** @@ -49,6 +48,7 @@ class Permission implements Stringable public function setTitle(string $title): self { $this->title = $title; + return $this; } @@ -60,6 +60,7 @@ class Permission implements Stringable public function setSlug(string $slug): self { $this->slug = $slug; + return $this; } @@ -71,6 +72,7 @@ class Permission implements Stringable public function setDescription(?string $description): self { $this->description = $description; + return $this; } diff --git a/src/CoreBundle/Entity/PermissionRelRole.php b/src/CoreBundle/Entity/PermissionRelRole.php index 08e598e60f..1fa0fece54 100644 --- a/src/CoreBundle/Entity/PermissionRelRole.php +++ b/src/CoreBundle/Entity/PermissionRelRole.php @@ -7,14 +7,15 @@ declare(strict_types=1); namespace Chamilo\CoreBundle\Entity; use Chamilo\CoreBundle\Repository\PermissionRelRoleRepository; +use DateTime; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Validator\Constraints as Assert; #[ORM\Entity(repositoryClass: PermissionRelRoleRepository::class)] #[ORM\Table(name: 'permission_rel_role')] /** - * The PermissionRelRole entity makes the link between roles - * (defined in security.yaml) and permissions (defined by the + * The PermissionRelRole entity makes the link between roles + * (defined in security.yaml) and permissions (defined by the * Permission entity) to define which user role can do what. */ class PermissionRelRole @@ -36,7 +37,7 @@ class PermissionRelRole private bool $changeable; #[ORM\Column(type: 'datetime')] - private \DateTime $updatedAt; + private DateTime $updatedAt; public function getId(): ?int { @@ -51,6 +52,7 @@ class PermissionRelRole public function setPermission(Permission $permission): self { $this->permission = $permission; + return $this; } @@ -62,6 +64,7 @@ class PermissionRelRole public function setRoleCode(string $roleCode): self { $this->roleCode = $roleCode; + return $this; } @@ -73,17 +76,19 @@ class PermissionRelRole public function setChangeable(bool $changeable): self { $this->changeable = $changeable; + return $this; } - public function getUpdatedAt(): \DateTime + public function getUpdatedAt(): DateTime { return $this->updatedAt; } - public function setUpdatedAt(\DateTime $updatedAt): self + public function setUpdatedAt(DateTime $updatedAt): self { $this->updatedAt = $updatedAt; + return $this; } } diff --git a/src/CoreBundle/Migrations/Schema/V200/Version20201216122012.php b/src/CoreBundle/Migrations/Schema/V200/Version20201216122012.php index 17120a9649..6cdca12717 100644 --- a/src/CoreBundle/Migrations/Schema/V200/Version20201216122012.php +++ b/src/CoreBundle/Migrations/Schema/V200/Version20201216122012.php @@ -71,7 +71,7 @@ final class Version20201216122012 extends AbstractMigrationChamilo $this->entityManager->persist($resource); - if ($counter % self::BATCH_SIZE === 0) { + if (0 === $counter % self::BATCH_SIZE) { $this->entityManager->flush(); } @@ -128,7 +128,7 @@ final class Version20201216122012 extends AbstractMigrationChamilo ; $this->entityManager->persist($rootItem); - if ($counter % self::BATCH_SIZE === 0) { + if (0 === $counter % self::BATCH_SIZE) { $this->entityManager->flush(); } diff --git a/src/CoreBundle/Migrations/Schema/V200/Version20240709222700.php b/src/CoreBundle/Migrations/Schema/V200/Version20240709222700.php index ec0d3e30a3..7ffe7a65ff 100644 --- a/src/CoreBundle/Migrations/Schema/V200/Version20240709222700.php +++ b/src/CoreBundle/Migrations/Schema/V200/Version20240709222700.php @@ -10,6 +10,7 @@ use Chamilo\CoreBundle\DataFixtures\PermissionFixtures; use Chamilo\CoreBundle\Entity\Permission; use Chamilo\CoreBundle\Entity\PermissionRelRole; use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo; +use DateTime; use Doctrine\DBAL\Schema\Schema; final class Version20240709222700 extends AbstractMigrationChamilo @@ -42,11 +43,11 @@ final class Version20240709222700 extends AbstractMigrationChamilo } foreach ($roles as $roleName => $roleCode) { - if (in_array($roleCode, $permissionsMapping[$permData['slug']])) { + if (\in_array($roleCode, $permissionsMapping[$permData['slug']])) { $permissionRelRoleRepository = $this->entityManager->getRepository(PermissionRelRole::class); $existingRelation = $permissionRelRoleRepository->findOneBy([ 'permission' => $permission, - 'roleCode' => $roleName + 'roleCode' => $roleName, ]); if ($existingRelation) { @@ -57,7 +58,7 @@ final class Version20240709222700 extends AbstractMigrationChamilo $permissionRelRole->setPermission($permission); $permissionRelRole->setRoleCode($roleName); $permissionRelRole->setChangeable(true); - $permissionRelRole->setUpdatedAt(new \DateTime()); + $permissionRelRole->setUpdatedAt(new DateTime()); $this->entityManager->persist($permissionRelRole); $this->entityManager->flush(); diff --git a/src/CoreBundle/Repository/PermissionRelRoleRepository.php b/src/CoreBundle/Repository/PermissionRelRoleRepository.php index 75ef3828b2..6e4eaa4ed5 100644 --- a/src/CoreBundle/Repository/PermissionRelRoleRepository.php +++ b/src/CoreBundle/Repository/PermissionRelRoleRepository.php @@ -19,5 +19,4 @@ class PermissionRelRoleRepository extends ServiceEntityRepository { parent::__construct($registry, PermissionRelRole::class); } - } diff --git a/src/CoreBundle/Repository/PermissionRepository.php b/src/CoreBundle/Repository/PermissionRepository.php index 0f559138ff..f08bff5c34 100644 --- a/src/CoreBundle/Repository/PermissionRepository.php +++ b/src/CoreBundle/Repository/PermissionRepository.php @@ -19,5 +19,4 @@ class PermissionRepository extends ServiceEntityRepository { parent::__construct($registry, Permission::class); } - } diff --git a/src/CoreBundle/ServiceHelper/PermissionServiceHelper.php b/src/CoreBundle/ServiceHelper/PermissionServiceHelper.php index 51f31dbb3b..314e66e440 100644 --- a/src/CoreBundle/ServiceHelper/PermissionServiceHelper.php +++ b/src/CoreBundle/ServiceHelper/PermissionServiceHelper.php @@ -21,7 +21,7 @@ class PermissionServiceHelper $roles = $this->parameterBag->get('security.role_hierarchy.roles'); return array_filter(array_keys($roles), function ($role) { - return !str_starts_with($role, 'ROLE_CURRENT_') && $role !== 'ROLE_ANONYMOUS'; + return !str_starts_with($role, 'ROLE_CURRENT_') && 'ROLE_ANONYMOUS' !== $role; }); } @@ -34,10 +34,11 @@ class PermissionServiceHelper ->andWhere('prr.changeable = :changeable') ->setParameter('permissionSlug', $permissionSlug) ->setParameter('roles', $roles) - ->setParameter('changeable', true); + ->setParameter('changeable', true) + ; $results = $queryBuilder->getQuery()->getResult(); - return count($results) > 0; + return \count($results) > 0; } }