Skip to content

Commit

Permalink
Use entity instead of repository class.
Browse files Browse the repository at this point in the history
  • Loading branch information
janbarasek committed Nov 16, 2021
1 parent ba1528d commit a0af488
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/Api/CmsDashboardEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function __construct(
public function actionFeed(): void
{
/** @var AnnouncementRepository $repository */
$repository = $this->entityManager->getRepository(AnnouncementRepository::class);
$repository = $this->entityManager->getRepository(Announcement::class);

$this->sendJson(
[
Expand Down
2 changes: 1 addition & 1 deletion src/Api/CmsEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public function postReportProblem(string $locale, string $description, string $u
public function postForgotPasswordSetNew(string $token, string $locale, string $password): void
{
/** @var UserResetPasswordRequestRepository $repository */
$repository = $this->entityManager->getRepository(UserResetPasswordRequestRepository::class);
$repository = $this->entityManager->getRepository(UserResetPasswordRequest::class);

try {
$request = $repository->getByToken($token);
Expand Down
3 changes: 2 additions & 1 deletion src/Api/UserEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Baraja\Cms\Settings;
use Baraja\Cms\User\Entity\CmsUser;
use Baraja\Cms\User\Entity\UserLogin;
use Baraja\Cms\User\Entity\UserMeta;
use Baraja\Cms\User\Entity\UserMetaRepository;
use Baraja\Cms\User\UserManager;
use Baraja\Cms\User\UserMetaManager;
Expand Down Expand Up @@ -131,7 +132,7 @@ public function actionDefault(
->getArrayResult();

/** @var UserMetaRepository $metaRepository */
$metaRepository = $this->entityManager->getRepository(UserMetaRepository::class);
$metaRepository = $this->entityManager->getRepository(UserMeta::class);

$metaToUser = $metaRepository->loadByUsersAndKeys(
array_map(static fn(array $user): int => $user['id'], $users),
Expand Down
3 changes: 2 additions & 1 deletion src/MiddleWare/TemplateRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Baraja\Cms\Proxy\GlobalAsset\CmsSimpleStaticAsset;
use Baraja\Cms\Settings;
use Baraja\Cms\User\Entity\CmsUser;
use Baraja\Cms\User\Entity\UserResetPasswordRequest;
use Baraja\Cms\User\Entity\UserResetPasswordRequestRepository;
use Baraja\Plugin\BasePlugin;
use Baraja\Plugin\CmsPluginPanel;
Expand Down Expand Up @@ -152,7 +153,7 @@ public function renderLoginOtpAuthTemplate(string $locale): string
public function renderResetPasswordTemplate(string $token, string $locale): string
{
/** @var UserResetPasswordRequestRepository $repository */
$repository = $this->context->getEntityManager()->getRepository(UserResetPasswordRequestRepository::class);
$repository = $this->context->getEntityManager()->getRepository(UserResetPasswordRequest::class);

try {
$request = $repository->getByToken($token);
Expand Down
2 changes: 1 addition & 1 deletion src/Settings/DoctrineStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function __construct(
private EntityManagerInterface $entityManager,
) {
/** @var OptionRepository $optionRepository */
$optionRepository = $entityManager->getRepository(OptionRepository::class);
$optionRepository = $entityManager->getRepository(Option::class);
$this->optionRepository = $optionRepository;
}

Expand Down
3 changes: 2 additions & 1 deletion src/Settings/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Baraja\BarajaCloud\CloudManager;
use Baraja\Cms\Settings\SystemInfo;
use Baraja\Cms\User\UserManagerAccessor;
use Baraja\DoctrineConfiguration\Option;
use Baraja\DoctrineConfiguration\OptionRepository;
use Baraja\DynamicConfiguration\Configuration;
use Baraja\DynamicConfiguration\ConfigurationSection;
Expand Down Expand Up @@ -92,7 +93,7 @@ public function isDatabaseConnectionOk(): bool
}

/** @var OptionRepository $optionRepository */
$optionRepository = $this->entityManager->getRepository(OptionRepository::class);
$optionRepository = $this->entityManager->getRepository(Option::class);

$status = $optionRepository->isOptionExist();
if ($status === true) {
Expand Down
2 changes: 1 addition & 1 deletion src/User/UserManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ public function isLoginFirewallBlocked(string $username, ?string $ip = null): bo
}

/** @var UserLoginAttemptRepository $attemptRepository */
$attemptRepository = $this->entityManager->getRepository(UserLoginAttemptRepository::class);
$attemptRepository = $this->entityManager->getRepository(UserLoginAttempt::class);
$attempts = $attemptRepository->getUsedAttempts($username, $blockInterval, $ip, (int) $blockCount);

return count($attempts) >= (int) $blockCount;
Expand Down
6 changes: 3 additions & 3 deletions src/User/UserMetaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __construct(
public function loadAll(int $userId): self
{
/** @var UserMetaRepository $userMetaRepository */
$userMetaRepository = $this->entityManager->getRepository(UserMetaRepository::class);
$userMetaRepository = $this->entityManager->getRepository(UserMeta::class);

foreach ($userMetaRepository->loadAll($userId) as $meta) {
$cacheKey = $this->getCacheKey($userId, $meta->getKey());
Expand All @@ -47,7 +47,7 @@ public function get(int $userId, string $key): ?string
}
try {
/** @var UserMetaRepository $userMetaRepository */
$userMetaRepository = $this->entityManager->getRepository(UserMetaRepository::class);
$userMetaRepository = $this->entityManager->getRepository(UserMeta::class);
$meta = $userMetaRepository->load($userId, $key);
self::$cache[$cacheKey] = $meta;

Expand All @@ -71,7 +71,7 @@ public function set(int $userId, string $key, ?string $value): self
$cacheKey = $this->getCacheKey($user->getId(), $key);
try {
/** @var UserMetaRepository $userMetaRepository */
$userMetaRepository = $this->entityManager->getRepository(UserMetaRepository::class);
$userMetaRepository = $this->entityManager->getRepository(UserMeta::class);
/** @var UserMeta $meta */
$meta = self::$cache[$cacheKey] ?? $userMetaRepository->load($user->getId(), $key);
} catch (NoResultException | NonUniqueResultException) {
Expand Down

0 comments on commit a0af488

Please sign in to comment.