Use imports instead of FQNs

This commit is contained in:
Jan Böhmer 2023-06-11 14:55:06 +02:00
parent f63b6d7207
commit 5629215ce4
179 changed files with 792 additions and 597 deletions

View file

@ -51,7 +51,7 @@ class PasswordResetManager
//Try to find a user by the given string
$user = $repo->findByEmailOrName($name_or_email);
//Do nothing if no user was found
if (!$user instanceof \App\Entity\UserSystem\User) {
if (!$user instanceof User) {
return;
}
@ -101,7 +101,7 @@ class PasswordResetManager
$user = $repo->findOneBy(['name' => $username]);
//If no user matching the name, show an error message
if (!$user instanceof \App\Entity\UserSystem\User) {
if (!$user instanceof User) {
return false;
}

View file

@ -22,6 +22,7 @@ declare(strict_types=1);
namespace App\Services\UserSystem;
use App\Entity\Base\AbstractStructuralDBElement;
use App\Configuration\PermissionsConfiguration;
use App\Entity\UserSystem\Group;
use App\Entity\UserSystem\User;
@ -110,7 +111,7 @@ class PermissionManager
/** @var Group $parent */
$parent = $user->getGroup();
while ($parent instanceof \App\Entity\Base\AbstractStructuralDBElement) { //The top group, has parent == null
while ($parent instanceof AbstractStructuralDBElement) { //The top group, has parent == null
//Check if our current element gives an info about disallow/allow
$allowed = $this->dontInherit($parent, $permission, $operation);
if (null !== $allowed) {

View file

@ -102,7 +102,7 @@ class PermissionSchemaUpdater
public function userUpgradeSchemaRecursively(User $user, int $target_version = PermissionData::CURRENT_SCHEMA_VERSION): bool
{
$updated = $this->upgradeSchema($user, $target_version);
if ($user->getGroup() instanceof \App\Entity\UserSystem\Group) {
if ($user->getGroup() instanceof Group) {
$updated = $this->groupUpgradeSchemaRecursively($user->getGroup(), $target_version) || $updated;
}

View file

@ -20,6 +20,7 @@
namespace App\Services\UserSystem;
use Imagine\Exception\RuntimeException;
use App\Entity\Attachments\Attachment;
use App\Entity\Attachments\AttachmentType;
use App\Entity\Attachments\UserAttachment;
@ -44,7 +45,7 @@ class UserAvatarHelper
public function getAvatarURL(User $user): string
{
//Check if the user has a master attachment defined (meaning he has explicitly defined a profile picture)
if ($user->getMasterPictureAttachment() instanceof \App\Entity\Attachments\Attachment) {
if ($user->getMasterPictureAttachment() instanceof Attachment) {
return $this->attachmentURLGenerator->getThumbnailURL($user->getMasterPictureAttachment(), 'thumbnail_md');
}
@ -60,7 +61,7 @@ class UserAvatarHelper
public function getAvatarSmURL(User $user): string
{
//Check if the user has a master attachment defined (meaning he has explicitly defined a profile picture)
if ($user->getMasterPictureAttachment() instanceof \App\Entity\Attachments\Attachment) {
if ($user->getMasterPictureAttachment() instanceof Attachment) {
return $this->attachmentURLGenerator->getThumbnailURL($user->getMasterPictureAttachment(), 'thumbnail_xs');
}
@ -72,7 +73,7 @@ class UserAvatarHelper
try {
//Otherwise we can serve the relative path via Asset component
return $this->filterService->getUrlOfFilteredImage('/img/default_avatar.png', 'thumbnail_xs');
} catch (\Imagine\Exception\RuntimeException) {
} catch (RuntimeException) {
//If the filter fails, we can not serve the thumbnail and fall back to the original image and log an warning
return $this->packages->getUrl('/img/default_avatar.png');
}
@ -81,7 +82,7 @@ class UserAvatarHelper
public function getAvatarMdURL(User $user): string
{
//Check if the user has a master attachment defined (meaning he has explicitly defined a profile picture)
if ($user->getMasterPictureAttachment() instanceof \App\Entity\Attachments\Attachment) {
if ($user->getMasterPictureAttachment() instanceof Attachment) {
return $this->attachmentURLGenerator->getThumbnailURL($user->getMasterPictureAttachment(), 'thumbnail_sm');
}
@ -93,7 +94,7 @@ class UserAvatarHelper
try {
//Otherwise we can serve the relative path via Asset component
return $this->filterService->getUrlOfFilteredImage('/img/default_avatar.png', 'thumbnail_xs');
} catch (\Imagine\Exception\RuntimeException) {
} catch (RuntimeException) {
//If the filter fails, we can not serve the thumbnail and fall back to the original image and log an warning
return $this->packages->getUrl('/img/default_avatar.png');
}
@ -131,7 +132,7 @@ class UserAvatarHelper
{
//Determine which attachment to user
//If the user already has a master attachment, we use this one
if ($user->getMasterPictureAttachment() instanceof \App\Entity\Attachments\Attachment) {
if ($user->getMasterPictureAttachment() instanceof Attachment) {
$attachment = $user->getMasterPictureAttachment();
} else { //Otherwise we have to create one
$attachment = new UserAttachment();

View file

@ -22,17 +22,18 @@ declare(strict_types=1);
namespace App\Services\UserSystem;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\HttpFoundation\Request;
use App\Entity\UserSystem\User;
use Locale;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Security\Core\Security;
/**
* Purpose of this service is to generate a key unique for a user, to use in Cache keys and tags.
*/
class UserCacheKeyGenerator
{
public function __construct(protected \Symfony\Bundle\SecurityBundle\Security $security, protected RequestStack $requestStack)
public function __construct(protected Security $security, protected RequestStack $requestStack)
{
}
@ -46,10 +47,10 @@ class UserCacheKeyGenerator
{
$request = $this->requestStack->getCurrentRequest();
//Retrieve the locale from the request, if possible, otherwise use the default locale
$locale = $request instanceof \Symfony\Component\HttpFoundation\Request ? $request->getLocale() : Locale::getDefault();
$locale = $request instanceof Request ? $request->getLocale() : Locale::getDefault();
//If no user was specified, use the currently used one.
if (!$user instanceof \App\Entity\UserSystem\User) {
if (!$user instanceof User) {
$user = $this->security->getUser();
}