Skip to content

Commit

Permalink
fix most of phpstan errors
Browse files Browse the repository at this point in the history
  • Loading branch information
n-peugnet committed Jan 8, 2021
1 parent 4e8a6cd commit a21bc22
Show file tree
Hide file tree
Showing 11 changed files with 15 additions and 19 deletions.
1 change: 1 addition & 0 deletions src/Controller/AccountController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Controller;

use App\Entity\Invitation;
use App\Entity\User;
use App\Form\InvitationCreateType;
use App\Repository\InvitationRepository;
use App\Repository\UserRepository;
Expand Down
2 changes: 1 addition & 1 deletion src/Entity/SharableSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class SharableSearch
/**
* @var bool|null
*/
private $disabled = 0;
private $disabled = false;

/**
* @var bool|null
Expand Down
4 changes: 2 additions & 2 deletions src/Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ class User implements UserInterface

public function __construct()
{
$this->sharables = new ArrayCollection();
$this->validations = new ArrayCollection();
$this->invitations = new ArrayCollection();
$this->createdAt = new DateTime();
Expand Down Expand Up @@ -190,6 +189,7 @@ public function setPassword(string $password): self
public function getSalt()
{
// not needed when using the "bcrypt" algorithm in security.yaml
return null;
}

/**
Expand All @@ -201,7 +201,7 @@ public function eraseCredentials()
// $this->plainPassword = null;
}

public function getCreatedAt(): ?\DateTimeInterface
public function getCreatedAt(): ?\DateTime
{
return $this->createdAt;
}
Expand Down
1 change: 0 additions & 1 deletion src/Entity/UserContact.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use DateTime;
use Symfony\Component\Validator\Constraints as Assert;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Mime\Test\Constraint\EmailAddressContains;
use Symfony\Component\Validator\Constraints\Email;
use Symfony\Component\Validator\Constraints\Url;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
Expand Down
4 changes: 2 additions & 2 deletions src/Form/SharableType.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)


$builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
/** @var Sharable */
/** @var Sharable $sharable */
$sharable = $event->getData();
$form = $event->getForm();

Expand All @@ -56,7 +56,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
]);
}

if (!$sharable || $sharable->getId() === null) {
if ($sharable->getId() === null) {
$form->add('create', SubmitType::class);
} else {
$form->add('edit', SubmitType::class);
Expand Down
4 changes: 2 additions & 2 deletions src/Repository/SharableRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ public function __construct(ManagerRegistry $registry)
* List all sharable based on user Class and visibleBy setting on the sharables
*
* @param UserClass[] $visibleBy Collection of UserClass
* @param User the actual user
* @param User $user the actual user
*/
public function getFilteredSharables(SharableSearch $search, $visibleBy, User $user)
public function getFilteredSharables(SharableSearch $search, array $visibleBy, User $user)
{
$visibleByIds = array_map(function (UserClass $userClass)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Repository/UserClassRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function findLowerthan(UserClass $userClass)
*
* @param UserClass $userClass the user class as reference
*
* @return UserClass[] Returns an array of UserClass objects
* @return UserClass|null Returns an array of UserClass objects
*/
public function findNext(UserClass $userClass): ?UserClass
{
Expand Down
3 changes: 3 additions & 0 deletions src/Security/EmailVerifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Security;

use App\Entity\User;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
use Symfony\Component\HttpFoundation\Request;
Expand All @@ -25,6 +26,7 @@ public function __construct(VerifyEmailHelperInterface $helper, MailerInterface

public function sendEmailConfirmation(string $verifyEmailRouteName, UserInterface $user, TemplatedEmail $email): void
{
assert($user instanceof User);
$signatureComponents = $this->verifyEmailHelper->generateSignature(
$verifyEmailRouteName,
$user->getId(),
Expand All @@ -45,6 +47,7 @@ public function sendEmailConfirmation(string $verifyEmailRouteName, UserInterfac
*/
public function handleEmailConfirmation(Request $request, UserInterface $user): void
{
assert($user instanceof User);
$this->verifyEmailHelper->validateEmailConfirmation($request->getUri(), $user->getId(), $user->getEmail());

$user->setIsVerified(true);
Expand Down
5 changes: 1 addition & 4 deletions src/Security/Voter/SharableVoter.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ protected function supports($attribute, $subject)

protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token)
{
/** @var User $user */
$user = $token->getUser();
// if the user is anonymous, do not grant access
if (!$user instanceof UserInterface) {
Expand All @@ -50,16 +51,12 @@ protected function voteOnAttribute(string $attribute, $subject, TokenInterface $
switch ($attribute) {
case self::EDIT:
return $this->canEdit($sharable, $user);
break;
case self::VIEW:
return $this->canView($sharable, $user);
break;
case self::VALIDATE:
return $this->canValidate($sharable, $user);
break;
case self::CREATE:
return $this->canCreate($user);
break;
}

return false;
Expand Down
6 changes: 1 addition & 5 deletions src/Security/Voter/UserVoter.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ protected function supports($attribute, $subject)

protected function voteOnAttribute($attribute, $subject, TokenInterface $token)
{
/** @var User $user */
$user = $token->getUser();
// if the user is anonymous, do not grant access
if (!$user instanceof UserInterface) {
Expand All @@ -53,19 +54,14 @@ protected function voteOnAttribute($attribute, $subject, TokenInterface $token)
switch ($attribute) {
case self::EDIT:
return $this->canEdit($user, $userProfile);
break;
case self::VIEW:
return true;
break;
case self::VIEW_VALIDATIONS:
return $this->canView($user, $userProfile, self::VIEW_VALIDATIONS);
break;
case self::VIEW_SHARABLES:
return $this->canView($user, $userProfile, self::VIEW_SHARABLES);
break;
case self::VIEW_STATS:
return $this->canView($user, $userProfile, self::VIEW_STATS);
break;
}

return false;
Expand Down
2 changes: 1 addition & 1 deletion src/Validator/CodeValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function __construct(InvitationRepository $invitationRepository, Paramete

public function validate($value, Constraint $constraint)
{
/* @var $constraint \App\Validator\Code */
assert($constraint instanceof Code);

if (null === $value || '' === $value) {
return;
Expand Down

0 comments on commit a21bc22

Please sign in to comment.