Resolve PHPStan issues

This commit is contained in:
myrmidex 2026-06-05 11:15:30 +00:00
parent a8133b3233
commit 3e297f4d5c
8 changed files with 29 additions and 14 deletions

View file

@ -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();

View file

@ -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;

View file

@ -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);
}
}

View file

@ -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<string> 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;
}

View file

@ -26,6 +26,9 @@ class RatingRepository extends ServiceEntityRepository
->getOneOrNullResult();
}
/**
* @return Rating[]
*/
public function findAllBySubject(Subject $subject): array
{
return $this->createQueryBuilder('r')

View file

@ -4,6 +4,10 @@ namespace App\Services;
class OutputService
{
/**
* @param array<string, mixed> $output
* @return array{status: string, payload: array<string, mixed>, errors: null}
*/
public function success(array $output): array
{
return [
@ -13,6 +17,10 @@ class OutputService
];
}
/**
* @param array<int, string> $errors
* @return array{status: string, payload: null, errors: array<int, string>}
*/
public function error(array $errors): array
{
return [

View file

@ -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');

View file

@ -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');