diff --git a/src/Controller/Api/SubjectController.php b/src/Controller/Api/SubjectController.php index f2359ae..befc727 100644 --- a/src/Controller/Api/SubjectController.php +++ b/src/Controller/Api/SubjectController.php @@ -3,6 +3,7 @@ namespace App\Controller\Api; use App\Entity\Restaurant; +use App\Entity\User; use App\Repository\SubjectRepository; use App\Services\OutputService; use Doctrine\ORM\EntityManagerInterface; @@ -10,6 +11,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Attribute\Route; +use Symfony\Component\Security\Http\Attribute\CurrentUser; class SubjectController extends AbstractController { @@ -25,10 +27,12 @@ class SubjectController extends AbstractController public function create( Request $request, EntityManagerInterface $em, + #[CurrentUser] + User $user, ): JsonResponse { $subject = new Restaurant(); $subject->setName($request->getPayload()->get('name')); - $subject->setCreatedBy($this->getUser()); + $subject->setCreatedBy($user); $em->persist($subject); $em->flush(); diff --git a/src/Entity/Rating.php b/src/Entity/Rating.php index 755b207..3968ed3 100644 --- a/src/Entity/Rating.php +++ b/src/Entity/Rating.php @@ -16,7 +16,7 @@ class Rating #[ORM\ManyToOne(inversedBy: 'ratings')] #[ORM\JoinColumn(nullable: false)] - private ?Subject $subject = null; + private Subject $subject; #[ORM\Column(type: Types::SMALLINT, nullable: true)] private ?int $score = null; diff --git a/src/Entity/Subject.php b/src/Entity/Subject.php index 79a95cf..ddb8929 100644 --- a/src/Entity/Subject.php +++ b/src/Entity/Subject.php @@ -20,7 +20,7 @@ abstract class Subject private ?int $id = null; #[ORM\Column(length: 255)] - private ?string $name = null; + private string $name; #[ORM\ManyToOne] #[ORM\JoinColumn(nullable: true)] @@ -42,7 +42,7 @@ abstract class Subject return $this->id; } - public function getName(): ?string + public function getName(): string { return $this->name; } @@ -76,9 +76,9 @@ abstract class Subject public function addRating(Rating $rating): static { - if (!$this->ratings->contains($rating)) { + if (! $this->ratings->contains($rating)) { $this->ratings->add($rating); - $rating->setSubjectId($this); + $rating->setSubject($this); } return $this; @@ -88,8 +88,8 @@ abstract class Subject { if ($this->ratings->removeElement($rating)) { // set the owning side to null (unless already changed) - if ($rating->getSubjectId() === $this) { - $rating->setSubjectId(null); + if ($rating->getSubject() === $this) { + $rating->setSubject(null); } } diff --git a/src/Entity/User.php b/src/Entity/User.php index 4d9463a..01c3181 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -18,7 +18,7 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface private ?int $id = null; #[ORM\Column(length: 180)] - private ?string $email = null; + private string $email; /** * @var list The user roles @@ -30,14 +30,14 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface * @var string The hashed password */ #[ORM\Column] - private ?string $password = null; + private string $password; - public function getId(): ?int + public function getId(): int { return $this->id; } - public function getEmail(): ?string + public function getEmail(): string { return $this->email; } diff --git a/src/Repository/RatingRepository.php b/src/Repository/RatingRepository.php index 2680716..c9277ea 100644 --- a/src/Repository/RatingRepository.php +++ b/src/Repository/RatingRepository.php @@ -26,6 +26,9 @@ class RatingRepository extends ServiceEntityRepository ->getOneOrNullResult(); } + /** + * @return Rating[] + */ public function findAllBySubject(Subject $subject): array { return $this->createQueryBuilder('r') diff --git a/src/Services/OutputService.php b/src/Services/OutputService.php index cca505c..0bf7971 100644 --- a/src/Services/OutputService.php +++ b/src/Services/OutputService.php @@ -4,6 +4,10 @@ namespace App\Services; class OutputService { + /** + * @param array $output + * @return array{status: string, payload: array, errors: null} + */ public function success(array $output): array { return [ @@ -13,6 +17,10 @@ class OutputService ]; } + /** + * @param array $errors + * @return array{status: string, payload: null, errors: array} + */ public function error(array $errors): array { return [ diff --git a/tests/Integration/Auth/LoginTest.php b/tests/Integration/Auth/LoginTest.php index e929153..605bd78 100644 --- a/tests/Integration/Auth/LoginTest.php +++ b/tests/Integration/Auth/LoginTest.php @@ -13,7 +13,7 @@ class LoginTest extends WebTestCase $faker = \Zenstruck\Foundry\faker(); $email = $faker->email(); - $plainPwd = $faker->word(8); + $plainPwd = $faker->password(8, 12); $client->request('GET', '/account/register'); diff --git a/tests/Integration/Auth/RegistrationControllerTest.php b/tests/Integration/Auth/RegistrationControllerTest.php index babd218..fd0a6ce 100644 --- a/tests/Integration/Auth/RegistrationControllerTest.php +++ b/tests/Integration/Auth/RegistrationControllerTest.php @@ -13,7 +13,7 @@ class RegistrationControllerTest extends WebTestCase $faker = \Zenstruck\Foundry\faker(); $email = $faker->email(); - $plainPwd = $faker->word(8); + $plainPwd = $faker->password(8, 12); $client->request('GET', '/account/register');