Skip to content

Commit

Permalink
Fix PhpStan errors
Browse files Browse the repository at this point in the history
  • Loading branch information
janbarasek committed Jan 7, 2021
1 parent 11da531 commit 73fb4cc
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 17 deletions.
7 changes: 7 additions & 0 deletions src/Api/CmsEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Baraja\Cms\Helpers;
use Baraja\Cms\Settings;
use Baraja\Cms\User\Entity\CmsUser;
use Baraja\Cms\User\Entity\User;
use Baraja\Cms\User\Entity\UserResetPasswordRequest;
use Baraja\Cms\User\UserManager;
use Baraja\Doctrine\EntityManager;
Expand Down Expand Up @@ -118,6 +119,12 @@ public function postForgotPassword(string $locale, string $username): void
->getQuery()
->getSingleResult();

if (!$user instanceof User) {
$this->sendError('Reset password is available only for system CMS Users. Please contact your administrator');

return;
}

$this->entityManager->persist($request = new UserResetPasswordRequest($user, '3 hours'));
$this->entityManager->flush();

Expand Down
8 changes: 2 additions & 6 deletions src/Api/UserEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,10 @@ public function createDefault(string $fullName, string $email, string $role, ?st
}
try {
try {
/* @phpstan-ignore-next-line */
$ref = new \ReflectionClass($this->userManager->getDefaultEntity());
/** @var CmsUser $user */
$user = $ref->newInstanceArgs([
'username' => $email,
'password' => $password,
'email' => $email,
'role' => CmsUser::ROLE_USER,
]);
$user = $ref->newInstanceArgs([$email, $password, $email, CmsUser::ROLE_USER]);
} catch (\Throwable $e) {
if (class_exists(Debugger::class)) {
Debugger::log($e, ILogger::CRITICAL);
Expand Down
4 changes: 2 additions & 2 deletions src/Menu/MenuAuthorizator.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function getId(): ?string
*/
public function getRoles(): array
{
return $this->roles;
return array_keys($this->roles);
}


Expand All @@ -72,7 +72,7 @@ public function getRoles(): array
*/
public function getPrivileges(): array
{
return $this->privileges;
return array_keys($this->privileges);
}


Expand Down
18 changes: 9 additions & 9 deletions src/User/Entity/CmsUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,21 +87,21 @@ public function setCreateDate(\DateTime $createDate): void;
*/
public function getMetaData(): array;

public function getOtpCode();
public function getOtpCode(): ?string;

public function setOtpCode(?string $otpCode);
public function setOtpCode(?string $otpCode): void;

public function isActive();
public function isActive(): bool;

public function setActive(bool $active);
public function setActive(bool $active): void;

public function getAvatarUrl();
public function getAvatarUrl(): ?string;

public function setAvatarUrl(?string $avatarUrl);
public function setAvatarUrl(?string $avatarUrl): void;

public function getName(bool $reverse = false);
public function getName(bool $reverse = false): string;

public function getPhone();
public function getPhone(): ?string;

public function setPhone(?string $phone, int $region = 420);
public function setPhone(?string $phone, int $region = 420): void;
}
1 change: 1 addition & 0 deletions src/User/UserManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ final class UserManager implements Authenticator

public function __construct(EntityManager $entityManager, UserStorage $userStorage, ?string $userEntity = null)
{
/* @phpstan-ignore-next-line */
if ((class_implements($userEntity = $userEntity ?? User::class)[CmsUser::class] ?? false) === false) {
throw new \InvalidArgumentException('User entity "' . $userEntity . '" must implements "' . CmsUser::class . '" interface.');
}
Expand Down

0 comments on commit 73fb4cc

Please sign in to comment.