Skip to content

Commit

Permalink
🚨 Apply PHPStan fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jbelien committed Sep 15, 2024
1 parent 250039d commit 9874891
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion grumphp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ grumphp:
check:
tasks:
- phpcsfixer
# - phpstan
- phpstan
- twigcs
# - xlifflint # TODO: Re-implement
- yamllint
11 changes: 8 additions & 3 deletions src/Controller/App/MapperController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Entity\Note;
use App\Entity\Region;
use App\Entity\Template;
use App\Entity\User;
use App\Entity\Welcome;
use App\Service\RegionsProvider;
use App\Service\TemplatesProvider;
Expand All @@ -22,6 +23,9 @@
class MapperController extends AbstractController
{
private Mapper $mapper;

private ?User $user;

/** @var Template[] */
private array $templates;

Expand All @@ -39,6 +43,7 @@ public function index(Request $request, string $regionKey, int $id, ?string $con
{
$region = $this->provider->getRegion($continent, $regionKey);

$this->user = $this->getUser(); // @phpstan-ignore assign.propertyType
$this->mapper = $this->entityManager->find(Mapper::class, $id);

$mapperRegions = array_map(fn (Region $region) => $region->getId(), $this->mapper->getRegion()->toArray());
Expand Down Expand Up @@ -102,7 +107,7 @@ private function updateWelcomeDate(bool $state): void

if (true === $state) {
$welcome->setDate(new \DateTime());
$welcome->setUser($this->getUser());
$welcome->setUser($this->user);

$this->entityManager->persist($welcome);
} else {
Expand All @@ -119,7 +124,7 @@ private function updateWelcomeReply(bool $state): void
$welcome = new Welcome();
$welcome->setMapper($this->mapper);
$welcome->setDate(new \DateTime());
$welcome->setUser($this->getUser());
$welcome->setUser($this->user);
}
$welcome->setReply($state ? new \DateTime() : null);

Expand Down Expand Up @@ -164,7 +169,7 @@ private function note(Request $request): FormInterface
{
$note = new Note();
$note->setMapper($this->mapper);
$note->setAuthor($this->getUser());
$note->setAuthor($this->user);

$form = $this->createFormBuilder($note)
->add('text', TextareaType::class, ['label' => 'Note'])
Expand Down
7 changes: 5 additions & 2 deletions src/Entity/Mapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,21 @@ class Mapper
#[ORM\Column(type: 'string', length: 255)]
private ?string $status;

/** @var Collection<int,Changeset> */
#[ORM\OneToMany(targetEntity: Changeset::class, mappedBy: 'mapper', orphanRemoval: true)]
private Collection $changesets;

#[ORM\Column(type: 'text', nullable: true)]
private ?string $image;

/** @var Collection<int,Note> */
#[ORM\OneToMany(targetEntity: Note::class, mappedBy: 'mapper', orphanRemoval: true)]
private Collection $notes;

#[ORM\OneToOne(targetEntity: Welcome::class, mappedBy: 'mapper', cascade: ['persist'])]
private ?Welcome $welcome;

/** @var Collection<int,Region> */
#[ORM\ManyToMany(targetEntity: Region::class, inversedBy: 'mappers')]
private Collection $region;

Expand Down Expand Up @@ -109,7 +112,7 @@ public function setStatus(string $status): self
}

/**
* @return Collection|Changeset[]
* @return Collection<int,Changeset>
*/
public function getChangesets(): Collection
{
Expand Down Expand Up @@ -149,7 +152,7 @@ public function setImage(?string $image): self
}

/**
* @return Collection|Note[]
* @return Collection<int,Note>
*/
public function getNotes(): Collection
{
Expand Down
1 change: 1 addition & 0 deletions src/Entity/Region.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Region
#[ORM\Column(type: 'datetime')]
private \DateTime $lastUpdate;

/** @var Collection<int,Mapper> */
#[ORM\ManyToMany(targetEntity: Mapper::class, mappedBy: 'region')]
private Collection $mappers;

Expand Down
4 changes: 2 additions & 2 deletions src/Security/OpenStreetMapAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ public function authenticate(Request $request): Passport
$openstreetmapUser = $client->fetchUserFromToken($accessToken);

$user = $this->entityManager->getRepository(User::class)->find($openstreetmapUser->getId());
if (null === $user) {
if (null === $user && null !== $openstreetmapUser->getId()) {
$user = new User();
$user->setId($openstreetmapUser->getId());
$user->setId((int) $openstreetmapUser->getId());
}

$user->setDisplayName($openstreetmapUser->getDisplayName());
Expand Down

0 comments on commit 9874891

Please sign in to comment.