Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -420,12 +420,6 @@ parameters:
count: 1
path: src/lib/Form/Data/UserInvitationData.php

-
message: '#^Property Ibexa\\User\\Form\\Data\\UserInvitationData\:\:\$email \(string\) does not accept string\|null\.$#'
identifier: assign.propertyType
count: 1
path: src/lib/Form/Data/UserInvitationData.php

-
message: '#^Property Ibexa\\User\\Form\\Data\\UserInvitationData\:\:\$limitationValue type has no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
Expand Down Expand Up @@ -588,12 +582,6 @@ parameters:
count: 1
path: src/lib/Form/DataTransformer/LimitationValueTransformer.php

-
message: '#^Cannot call method getContentType\(\) on Ibexa\\User\\Form\\Data\\UserPasswordResetData\|null\.$#'
identifier: method.nonObject
count: 1
path: src/lib/Form/Factory/FormFactory.php

-
message: '#^Method Ibexa\\User\\Form\\Factory\\FormFactory\:\:changeUserPassword\(\) return type with generic interface Symfony\\Component\\Form\\FormInterface does not specify its types\: TData$#'
identifier: missingType.generics
Expand Down
6 changes: 6 additions & 0 deletions src/bundle/Controller/UserInvitationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Ibexa\User\ExceptionHandler\ActionResultHandler;
use Ibexa\User\Form\Type\Invitation\UserInvitationType;
use Ibexa\User\View\Invitation\FormView;
use InvalidArgumentException;
use JMS\TranslationBundle\Annotation\Desc;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\HttpFoundation\Request;
Expand Down Expand Up @@ -50,6 +51,11 @@ public function inviteUser(Request $request): FormView
if ($form->isSubmitted() && $form->isValid()) {
/** @var \Ibexa\User\Form\Data\UserInvitationData $data */
$data = $form->getData();

if ($data->getEmail() === null){
throw new InvalidArgumentException('Email cannot be null');
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do we need this check ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because of phpstan Error:


 ------ ------------------------------------------------------------------------------------------------------------------------------------ 
  Line   src/bundle/Controller/UserInvitationController.php                                                                                  
 ------ ------------------------------------------------------------------------------------------------------------------------------------ 
  58     Parameter #1 $email of class Ibexa\Contracts\User\Invitation\InvitationCreateStruct constructor expects string, string|null given.  
         🪪  argument.type                                                                                                                   
 ------ --------------------------------------------------------------------


try {
$invitation = $this->invitationService->createInvitation(
new InvitationCreateStruct(
Expand Down
4 changes: 2 additions & 2 deletions src/contracts/Notification/UserPasswordReset.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ public function __construct(
$this->token = $token;
}

public function asEmailMessage(EmailRecipientInterface $recipient, string $transport = null): ?EmailMessage
public function asEmailMessage(EmailRecipientInterface $recipient, ?string $transport = null): ?EmailMessage
{
return null;
}

public function asSmsMessage(SmsRecipientInterface $recipient, string $transport = null): ?SmsMessage
public function asSmsMessage(SmsRecipientInterface $recipient, ?string $transport = null): ?SmsMessage
{
return null;
}
Expand Down
4 changes: 2 additions & 2 deletions src/contracts/Notification/UserRegister.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ public function __construct(User $user)
$this->user = $user;
}

public function asEmailMessage(EmailRecipientInterface $recipient, string $transport = null): ?EmailMessage
public function asEmailMessage(EmailRecipientInterface $recipient, ?string $transport = null): ?EmailMessage
{
return null;
}

public function asSmsMessage(SmsRecipientInterface $recipient, string $transport = null): ?SmsMessage
public function asSmsMessage(SmsRecipientInterface $recipient, ?string $transport = null): ?SmsMessage
{
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/EventListener/ViewTemplatesListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function setViewTemplates(PreContentViewEvent $event): void
}

/**
* @return string[]
* @return array<string, string>
*/
private function getTemplatesMap(): array
{
Expand Down
8 changes: 4 additions & 4 deletions src/lib/Form/Data/UserInvitationData.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ final class UserInvitationData
*
* @Assert\Email()
*/
private string $email;
private ?string $email;

private ?Role $role;

Expand All @@ -44,8 +44,8 @@ final class UserInvitationData
private ?array $limitationValue;

public function __construct(
string $email = null,
SiteAccess $siteaccess = null,
?string $email = null,
?SiteAccess $siteaccess = null,
?Role $role = null,
?UserGroup $userGroup = null,
?array $sections = null,
Expand Down Expand Up @@ -85,7 +85,7 @@ public function setLimitationValue(?array $limitationValue): void
$this->limitationValue = $limitationValue;
}

public function getEmail(): string
public function getEmail(): ?string
{
return $this->email;
}
Expand Down
19 changes: 9 additions & 10 deletions src/lib/Form/Factory/FormFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Ibexa\User\Form\Type\UserPasswordForgotWithLoginType;
use Ibexa\User\Form\Type\UserPasswordResetType;
use Ibexa\User\Form\Type\UserSettingUpdateType;
use InvalidArgumentException;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\Util\StringUtil;
Expand All @@ -45,7 +46,7 @@ public function __construct(FormFactoryInterface $formFactory, UrlGeneratorInter

public function changeUserPassword(
ContentType $contentType,
UserPasswordChangeData $data = null,
?UserPasswordChangeData $data = null,
?string $name = null,
?User $user = null
): FormInterface {
Expand All @@ -71,7 +72,7 @@ public function changeUserPassword(
* @throws \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
*/
public function forgotUserPassword(
UserPasswordForgotData $data = null,
?UserPasswordForgotData $data = null,
?string $name = null
): FormInterface {
$name = $name ?: StringUtil::fqcnToBlockPrefix(UserPasswordForgotType::class);
Expand All @@ -88,7 +89,7 @@ public function forgotUserPassword(
* @throws \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
*/
public function forgotUserPasswordWithLogin(
UserPasswordForgotWithLoginData $data = null,
?UserPasswordForgotWithLoginData $data = null,
?string $name = null
): FormInterface {
$name = $name ?: StringUtil::fqcnToBlockPrefix(UserPasswordForgotWithLoginType::class);
Expand All @@ -97,21 +98,19 @@ public function forgotUserPasswordWithLogin(
}

/**
* @param \Ibexa\User\Form\Data\UserPasswordResetData $data
* @param string|null $name
*
* @return \Symfony\Component\Form\FormInterface
*
* @throws \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
*/
public function resetUserPassword(
UserPasswordResetData $data = null,
?UserPasswordResetData $data = null,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we enforce $data to be just UserPasswordData without null if we really don't support null?

In the user package it's executed only in 1 place where $data is not null

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, but for the sake of efficiency let's stick to original task which is (getting rid of deprecated syntax instead of evaluating each case separately) 😉

?string $name = null,
?ContentType $contentType = null,
?User $user = null
): FormInterface {
$name = $name ?: StringUtil::fqcnToBlockPrefix(UserPasswordResetType::class);

if (null === $data) {
throw new InvalidArgumentException('UserPasswordResetData is required for resetting user password');
}
$userContentType = $contentType ?? $data->getContentType();

return $this->formFactory->createNamed(
Expand All @@ -127,7 +126,7 @@ public function resetUserPassword(

public function updateUserSetting(
string $userSettingIdentifier,
UserSettingUpdateData $data = null,
?UserSettingUpdateData $data = null,
?string $name = null
): FormInterface {
$name = $name ?: StringUtil::fqcnToBlockPrefix(UserSettingUpdateType::class);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Permission/UserPermissionsLimitationType.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public function buildValue(array $limitationValues)
*
* @return bool
*/
public function evaluate(APILimitationValue $value, APIUserReference $currentUser, ValueObject $object, array $targets = null)
public function evaluate(APILimitationValue $value, APIUserReference $currentUser, ValueObject $object, ?array $targets = null)
{
if (!$value instanceof UserPermissionsLimitation) {
throw new InvalidArgumentException('$value', 'Must be of type: APISiteAccessLimitation');
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Templating/Twig/DateTimeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ function ($date, $timezone = null) {
*
* @throws \Exception
*/
public function format(FormatterInterface $formatter, $date = null, string $timezone = null): string
public function format(FormatterInterface $formatter, $date = null, ?string $timezone = null): string
{
if ($date === null) {
$date = new DateTimeImmutable();
Expand Down
2 changes: 1 addition & 1 deletion src/lib/UserSetting/DateTimeFormat/Formatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function __construct(string $locale, string $timezone, string $format)
/**
* {@inheritdoc}
*/
public function format(DateTimeInterface $datetime, string $timezone = null): string
public function format(DateTimeInterface $datetime, ?string $timezone = null): string
{
if ($timezone) {
$currentTimezone = $this->formatter->getTimeZone();
Expand Down
2 changes: 1 addition & 1 deletion src/lib/UserSetting/DateTimeFormat/FormatterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface FormatterInterface
*
* @return string
*/
public function format(DateTimeInterface $datetime, string $timezone = null): string;
public function format(DateTimeInterface $datetime, ?string $timezone = null): string;
}

class_alias(FormatterInterface::class, 'EzSystems\EzPlatformUser\UserSetting\DateTimeFormat\FormatterInterface');
Loading