Skip to content

Commit

Permalink
Upgrade phpstan to max level
Browse files Browse the repository at this point in the history
  • Loading branch information
eerison committed Aug 6, 2022
1 parent 1fb5b28 commit 99c397c
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 20 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Xdebug is listening on port [10000](.docker/common.env)
[ci_link]: https://github.com/eerison/myprofile/actions/workflows/continuous_integration.yml?query=workflow%3AContinuous+Integration
[cd_badge]: https://github.com/eerison/myprofile/actions/workflows/continuous_deploy.yml/badge.svg
[cd_link]: https://github.com/eerison/myprofile/actions/workflows/continuous_deploy.yml?query=workflow%3AContinuous+Deploy
[phpstan_badge]: https://img.shields.io/badge/PHPStan-level%207-brightgreen.svg?style=flat
[phpstan_badge]: https://img.shields.io/badge/PHPStan-level%20max-brightgreen.svg?style=flat
[phpstan_link]: https://github.com/eerison/myprofile/blob/2.x/phpstan.neon#L2
[test_badge]: https://codecov.io/gh/eerison/myprofile/branch/2.x/graph/badge.svg?token=ZIW9RTWH1B
[test_link]: https://codecov.io/gh/eerison/myprofile
Expand Down
6 changes: 1 addition & 5 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
parameters:
level: 7
level: max
paths:
- src
checkGenericClassInNonGenericObjectType: false
Expand All @@ -8,10 +8,6 @@ parameters:
- src/EventListener/UpdateCurriculumListener.php
doctrine:
objectManagerLoader: tests/object-manager.php
symfony:
containerXmlPath: var/cache/dev/App_KernelDevDebugContainer.xml
scanDirectories:
- var/cache/dev/Symfony/Config
ignoreErrors:
- '#is never written, only read.#'
- '#type mapping mismatch\: property can contain App\\Entity\\UserInterface#'
10 changes: 8 additions & 2 deletions src/Controller/Profile/MainController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use App\Service\ProfileImageService;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
Expand All @@ -33,8 +34,13 @@ public function editAction(Request $request, ProfileImageService $profileImageSe
$form = $this->createForm(ProfileType::class, $user);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$profileImageService->upload($user, $form->get('profile_image')->getData());
$backgroundImageService->upload($user, $form->get('background_image')->getData());
/** @var ?UploadedFile $profileImage */
$profileImage = $form->get('profile_image')->getData();
/** @var ?UploadedFile $backgroundImage */
$backgroundImage = $form->get('background_image')->getData();

$profileImageService->upload($user, $profileImage);
$backgroundImageService->upload($user, $backgroundImage);

$this->entityManager->persist($user);
$this->entityManager->flush();
Expand Down
1 change: 1 addition & 0 deletions src/Controller/SecurityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public function authThirdParty(
return $this->redirectToRoute('profile_edit');
}

/** @var ?string $submittedToken */
$submittedToken = $request->get('token');

if (!$this->isCsrfTokenValid('third-party-login', $submittedToken)) {
Expand Down
3 changes: 1 addition & 2 deletions src/Entity/Education.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use App\EventListener\UpdateCurriculumListener;
use App\Repository\EducationRepository;
use App\ThirdCode\Contracts\EducationInterface;
use DateTime;
use DateTimeInterface;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
Expand All @@ -21,7 +20,7 @@ class Education implements EntityInterface, HasUserInterface, EducationInterface
#[ORM\Id]
#[ORM\Column(type: Types::INTEGER)]
#[ORM\GeneratedValue]
protected ?int $id = null;
protected int $id;

#[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'educations')]
#[ORM\JoinColumn(name: 'user_id', nullable: false)]
Expand Down
3 changes: 1 addition & 2 deletions src/Entity/Experience.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use App\EventListener\UpdateCurriculumListener;
use App\Repository\ExperienceRepository;
use App\ThirdCode\Contracts\ExperienceInterface;
use DateTime;
use DateTimeInterface;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
Expand All @@ -21,7 +20,7 @@ class Experience implements ExperienceInterface, EntityInterface, HasUserInterfa
#[ORM\Id]
#[ORM\Column(type: Types::INTEGER)]
#[ORM\GeneratedValue]
protected ?int $id = null;
protected int $id;

#[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'experiences')]
#[ORM\JoinColumn(name: 'user_id', nullable: false)]
Expand Down
6 changes: 3 additions & 3 deletions src/Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface, Stringa
#[ORM\Id]
#[ORM\Column(type: Types::INTEGER)]
#[ORM\GeneratedValue]
protected ?int $id = null;
protected int $id;

#[Assert\Length(max: 200)]
#[Assert\Email]
Expand Down Expand Up @@ -162,7 +162,7 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface, Stringa

private string $backgroundImage;

private string $website;
private ?string $website = null;

public function __construct()
{
Expand Down Expand Up @@ -485,7 +485,7 @@ public function getCreatedAt(): DateTimeInterface
return $this->createdAt;
}

public function getUpdatedAt(): DateTimeInterface
public function getUpdatedAt(): ?DateTimeInterface
{
return $this->updatedAt;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Entity/UserLanguage.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class UserLanguage implements EntityInterface, HasUserInterface, SpeakLanguageIn
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: Types::INTEGER)]
private ?int $id = null;
private int $id;

#[Assert\Length(max: 50)]
#[ORM\Column(type: Types::STRING, length: 50)]
Expand Down
2 changes: 1 addition & 1 deletion src/Entity/UserSocialNetworking.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class UserSocialNetworking implements UserSocialNetworkInterface, EntityInterfac
#[ORM\Id]
#[ORM\Column(type: Types::INTEGER)]
#[ORM\GeneratedValue]
protected ?int $id = null;
protected int $id;

#[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'userSocialNetworks')]
#[ORM\JoinColumn(name: 'user_id', nullable: false)]
Expand Down
2 changes: 1 addition & 1 deletion src/Repository/UserRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

/**
* @method User[] findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null)
* @method User|null findOneBy(array $criteria, ?array $orderBy = null)
* @method UserInterface findOneBy(array $criteria, ?array $orderBy = null)
*/
class UserRepository extends ServiceEntityRepository implements EmailRepositoryInterface
{
Expand Down
6 changes: 4 additions & 2 deletions src/Security/ThirdPartyAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@ public function authenticate(Request $request): Passport

/** @var GoogleUser $ownerDetails */
$ownerDetails = $this->provider->getResourceOwner($apiToken); //@phpstan-ignore-line
/** @var string $emailGoogle */
$emailGoogle = $ownerDetails->getEmail();

return new SelfValidatingPassport(
new UserBadge($ownerDetails->getEmail(), function ($email) use ($ownerDetails) {
new UserBadge($emailGoogle, function (string $email) use ($ownerDetails) {
// TODO Refactor this method.
$user = $this->userRepository->findOneBy(['email' => $email]);

Expand All @@ -67,7 +69,7 @@ public function authenticate(Request $request): Passport
$user
->setFirstName($ownerDetails->getFirstName())
->setLastName($ownerDetails->getLastName())
->setEmail($ownerDetails->getEmail())
->setEmail($email)
->setIsVerified(true)
;

Expand Down

0 comments on commit 99c397c

Please sign in to comment.