Skip to content

Commit

Permalink
Merge pull request #2279 from tarlepp/feat/rector-changes
Browse files Browse the repository at this point in the history
Feat - Rector changes to code base
  • Loading branch information
tarlepp committed Apr 23, 2023
2 parents 9c9ace6 + e216fa8 commit e0a5eaf
Show file tree
Hide file tree
Showing 45 changed files with 98 additions and 81 deletions.
2 changes: 1 addition & 1 deletion src/Command/ApiKey/ChangeTokenCommand.php
Expand Up @@ -31,7 +31,7 @@ class ChangeTokenCommand extends Command
{
use SymfonyStyleTrait;

public const NAME = 'api-key:change-token';
final public const NAME = 'api-key:change-token';

public function __construct(
private readonly ApiKeyResource $apiKeyResource,
Expand Down
2 changes: 1 addition & 1 deletion src/Command/ApiKey/CreateApiKeyCommand.php
Expand Up @@ -40,7 +40,7 @@ class CreateApiKeyCommand extends Command
use ApiKeyUserManagementHelperTrait;
use SymfonyStyleTrait;

public const NAME = 'api-key:create';
final public const NAME = 'api-key:create';

/**
* @var array<int, array<string, string>>
Expand Down
2 changes: 1 addition & 1 deletion src/Command/ApiKey/EditApiKeyCommand.php
Expand Up @@ -34,7 +34,7 @@ class EditApiKeyCommand extends Command
{
use SymfonyStyleTrait;

public const NAME = 'api-key:edit';
final public const NAME = 'api-key:edit';

public function __construct(
private readonly ApiKeyResource $apiKeyResource,
Expand Down
2 changes: 1 addition & 1 deletion src/Command/ApiKey/ListApiKeysCommand.php
Expand Up @@ -35,7 +35,7 @@
)]
class ListApiKeysCommand extends Command
{
public const NAME = 'api-key:list';
final public const NAME = 'api-key:list';

public function __construct(
private readonly ApiKeyResource $apiKeyResource,
Expand Down
2 changes: 1 addition & 1 deletion src/Command/ApiKey/RemoveApiKeyCommand.php
Expand Up @@ -31,7 +31,7 @@ class RemoveApiKeyCommand extends Command
{
use SymfonyStyleTrait;

public const NAME = 'api-key:remove';
final public const NAME = 'api-key:remove';

public function __construct(
private readonly ApiKeyResource $apiKeyResource,
Expand Down
2 changes: 1 addition & 1 deletion src/Command/User/CreateRolesCommand.php
Expand Up @@ -36,7 +36,7 @@ class CreateRolesCommand extends Command
{
use SymfonyStyleTrait;

public const NAME = 'user:create-roles';
final public const NAME = 'user:create-roles';

public function __construct(
private readonly EntityManagerInterface $entityManager,
Expand Down
2 changes: 1 addition & 1 deletion src/Command/User/CreateUserCommand.php
Expand Up @@ -40,7 +40,7 @@ class CreateUserCommand extends Command
use ApiKeyUserManagementHelperTrait;
use SymfonyStyleTrait;

public const NAME = 'user:create';
final public const NAME = 'user:create';

private const PARAMETER_NAME = 'name';
private const PARAMETER_DESCRIPTION = 'description';
Expand Down
2 changes: 1 addition & 1 deletion src/Command/User/CreateUserGroupCommand.php
Expand Up @@ -39,7 +39,7 @@ class CreateUserGroupCommand extends Command
use GetApplicationTrait;
use SymfonyStyleTrait;

public const NAME = 'user:create-group';
final public const NAME = 'user:create-group';

/**
* @var array<int, array<string, string>>
Expand Down
2 changes: 1 addition & 1 deletion src/Command/User/EditUserCommand.php
Expand Up @@ -34,7 +34,7 @@ class EditUserCommand extends Command
{
use SymfonyStyleTrait;

public const NAME = 'user:edit';
final public const NAME = 'user:edit';

public function __construct(
private readonly UserResource $userResource,
Expand Down
2 changes: 1 addition & 1 deletion src/Command/User/EditUserGroupCommand.php
Expand Up @@ -34,7 +34,7 @@ class EditUserGroupCommand extends Command
{
use SymfonyStyleTrait;

public const NAME = 'user:edit-group';
final public const NAME = 'user:edit-group';

public function __construct(
private readonly UserGroupResource $userGroupResource,
Expand Down
2 changes: 1 addition & 1 deletion src/Command/User/ListUserGroupsCommand.php
Expand Up @@ -36,7 +36,7 @@ class ListUserGroupsCommand extends Command
{
use SymfonyStyleTrait;

public const NAME = 'user:list-groups';
final public const NAME = 'user:list-groups';

public function __construct(
private readonly UserGroupResource $userGroupResource,
Expand Down
2 changes: 1 addition & 1 deletion src/Command/User/ListUsersCommand.php
Expand Up @@ -37,7 +37,7 @@ class ListUsersCommand extends Command
{
use SymfonyStyleTrait;

public const NAME = 'user:list';
final public const NAME = 'user:list';

public function __construct(
private readonly UserResource $userResource,
Expand Down
2 changes: 1 addition & 1 deletion src/Command/User/RemoveUserCommand.php
Expand Up @@ -31,7 +31,7 @@ class RemoveUserCommand extends Command
{
use SymfonyStyleTrait;

public const NAME = 'user:remove';
final public const NAME = 'user:remove';

public function __construct(
private readonly UserResource $userResource,
Expand Down
2 changes: 1 addition & 1 deletion src/Command/User/RemoveUserGroupCommand.php
Expand Up @@ -31,7 +31,7 @@ class RemoveUserGroupCommand extends Command
{
use SymfonyStyleTrait;

public const NAME = 'user:remove-group';
final public const NAME = 'user:remove-group';

public function __construct(
private readonly UserGroupResource $userGroupResource,
Expand Down
4 changes: 2 additions & 2 deletions src/Doctrine/DBAL/Types/EnumLogLoginType.php
Expand Up @@ -16,8 +16,8 @@
*/
class EnumLogLoginType extends EnumType
{
public const TYPE_FAILURE = 'failure';
public const TYPE_SUCCESS = 'success';
final public const TYPE_FAILURE = 'failure';
final public const TYPE_SUCCESS = 'success';

protected static string $name = Types::ENUM_LOG_LOGIN;

Expand Down
6 changes: 3 additions & 3 deletions src/Doctrine/DBAL/Types/Types.php
Expand Up @@ -16,7 +16,7 @@
*/
class Types
{
public const ENUM_LANGUAGE = 'EnumLanguage';
public const ENUM_LOCALE = 'EnumLocale';
public const ENUM_LOG_LOGIN = 'EnumLogLogin';
final public const ENUM_LANGUAGE = 'EnumLanguage';
final public const ENUM_LOCALE = 'EnumLocale';
final public const ENUM_LOG_LOGIN = 'EnumLogLogin';
}
2 changes: 1 addition & 1 deletion src/Doctrine/DBAL/Types/UTCDateTimeType.php
Expand Up @@ -25,7 +25,7 @@
*/
class UTCDateTimeType extends DateTimeType
{
private static ?DateTimeZone $utc;
private static ?DateTimeZone $utc = null;

/**
* {@inheritdoc}
Expand Down
9 changes: 4 additions & 5 deletions src/Entity/ApiKey.php
Expand Up @@ -27,7 +27,6 @@
use Symfony\Component\Validator\Constraints as Assert;
use Throwable;
use function array_map;
use function array_merge;
use function array_unique;
use function array_values;

Expand Down Expand Up @@ -214,12 +213,12 @@ public function getRoles(): array
array_map(
'\strval',
array_unique(
array_merge(
[RoleEnum::API->value],
$this->userGroups
[
RoleEnum::API->value,
...$this->userGroups
->map(static fn (UserGroup $userGroup): string => $userGroup->getRole()->getId())
->toArray(),
),
],
),
),
);
Expand Down
8 changes: 2 additions & 6 deletions src/Entity/LogLogin.php
Expand Up @@ -226,8 +226,6 @@ class LogLogin implements EntityInterface
])]
private ?string $model = null;

private DeviceDetector $deviceDetector;

/**
* LogLogin constructor.
*
Expand All @@ -242,9 +240,9 @@ public function __construct(
'LogLogin',
'LogLogin.type',
])]
private string $type,
private readonly string $type,
Request $request,
DeviceDetector $deviceDetector,
private readonly DeviceDetector $deviceDetector,
#[ORM\ManyToOne(
targetEntity: User::class,
inversedBy: 'logsLogin',
Expand All @@ -261,8 +259,6 @@ public function __construct(
) {
$this->id = $this->createUuid();

$this->deviceDetector = $deviceDetector;

$this->processTimeAndDate();
$this->processRequestData($request);
$this->processClientData();
Expand Down
4 changes: 2 additions & 2 deletions src/Entity/User.php
Expand Up @@ -62,8 +62,8 @@ class User implements EntityInterface, UserInterface, UserGroupAwareInterface
use UserRelations;
use Uuid;

public const SET_USER_PROFILE = 'set.UserProfile';
public const SET_USER_BASIC = 'set.UserBasic';
final public const SET_USER_PROFILE = 'set.UserProfile';
final public const SET_USER_BASIC = 'set.UserBasic';

/**
* @OA\Property(type="string", format="uuid")
Expand Down
4 changes: 2 additions & 2 deletions src/Entity/UserGroup.php
Expand Up @@ -40,8 +40,8 @@ class UserGroup implements EntityInterface, Stringable
use Timestampable;
use Uuid;

public const SET_USER_PROFILE_GROUPS = 'set.UserProfileGroups';
public const SET_USER_GROUP_BASIC = 'set.UserGroupBasic';
final public const SET_USER_PROFILE_GROUPS = 'set.UserProfileGroups';
final public const SET_USER_GROUP_BASIC = 'set.UserGroupBasic';

/**
* @OA\Property(type="string", format="uuid")
Expand Down
6 changes: 3 additions & 3 deletions src/EventSubscriber/AcceptLanguageSubscriber.php
Expand Up @@ -22,10 +22,10 @@
class AcceptLanguageSubscriber implements EventSubscriberInterface
{
// Supported locales
public const LOCALE_EN = 'en';
public const LOCALE_FI = 'fi';
final public const LOCALE_EN = 'en';
final public const LOCALE_FI = 'fi';

public const SUPPORTED_LOCALES = [
final public const SUPPORTED_LOCALES = [
self::LOCALE_EN,
self::LOCALE_FI,
];
Expand Down
2 changes: 1 addition & 1 deletion src/Form/Type/Traits/AddBasicFieldToForm.php
Expand Up @@ -25,7 +25,7 @@ trait AddBasicFieldToForm
protected function addBasicFieldToForm(FormBuilderInterface $builder, array $fields): void
{
foreach ($fields as $params) {
call_user_func_array([$builder, 'add'], $params);
call_user_func_array($builder->add(...), $params);
}
}
}
2 changes: 1 addition & 1 deletion src/Helpers/LoggerAwareTrait.php
Expand Up @@ -23,7 +23,7 @@
*/
trait LoggerAwareTrait
{
protected ?LoggerInterface $logger;
protected ?LoggerInterface $logger = null;

#[Required]
public function setLogger(LoggerInterface $logger): self
Expand Down
2 changes: 1 addition & 1 deletion src/Helpers/StopwatchAwareTrait.php
Expand Up @@ -23,7 +23,7 @@
*/
trait StopwatchAwareTrait
{
protected ?Stopwatch $stopwatch;
protected ?Stopwatch $stopwatch = null;

#[Required]
public function setStopwatch(Stopwatch $stopwatch): self
Expand Down
3 changes: 1 addition & 2 deletions src/Repository/BaseRepository.php
Expand Up @@ -17,7 +17,6 @@
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag;
use function array_map;
use function array_merge;
use function array_unshift;
use function implode;
use function in_array;
Expand Down Expand Up @@ -157,7 +156,7 @@ public function addInnerJoin(array $parameters): self
public function addCallback(callable $callable, ?array $args = null): self
{
$args ??= [];
$hash = sha1(serialize(array_merge([spl_object_hash((object)$callable)], $args)));
$hash = sha1(serialize([spl_object_hash((object)$callable), ...$args]));

if (!in_array($hash, self::$processedCallbacks, true)) {
self::$callbacks[] = [$callable, $args];
Expand Down
2 changes: 1 addition & 1 deletion src/Repository/UserRepository.php
Expand Up @@ -49,7 +49,7 @@ class UserRepository extends BaseRepository
public function __construct(
protected ManagerRegistry $managerRegistry,
#[Autowire('%kernel.environment%')]
private string $environment,
private readonly string $environment,
) {
}

Expand Down
2 changes: 1 addition & 1 deletion src/Rest/RepositoryHelper.php
Expand Up @@ -320,7 +320,7 @@ private static function determineComparisonAndParameters(QueryBuilder $queryBuil
// Initialize used callback parameters
$parameters = [$comparisonObject->field];

$lowercaseOperator = strtolower($comparisonObject->operator);
$lowercaseOperator = strtolower((string)$comparisonObject->operator);

if ($lowercaseOperator !== 'isnull' && $lowercaseOperator !== 'isnotnull') {
$parameters = self::getComparisonParameters(
Expand Down
4 changes: 2 additions & 2 deletions src/Rest/RequestHandler.php
Expand Up @@ -27,7 +27,7 @@
use function is_string;
use function mb_strtoupper;
use function mb_substr;
use function strncmp;
use function str_starts_with;

/**
* Class RequestHandler
Expand Down Expand Up @@ -266,7 +266,7 @@ private static function getIterator(array &$output): Closure
$order = in_array(mb_strtoupper($value), ['ASC', 'DESC'], true) ? mb_strtoupper($value) : 'ASC';
$column = is_string($key) ? $key : $value;

if (strncmp($column, '-', 1) === 0) {
if (str_starts_with($column, '-')) {
$column = mb_substr($column, 1);
$order = 'DESC';
}
Expand Down
6 changes: 3 additions & 3 deletions src/Rest/ResponseHandler.php
Expand Up @@ -27,7 +27,7 @@
use function explode;
use function implode;
use function sprintf;
use function strncmp;
use function str_starts_with;

/**
* Class ResponseHandler
Expand Down Expand Up @@ -85,8 +85,8 @@ public function getSerializeContext(Request $request, ?RestResourceInterface $re
$restResource
);

$groups = array_merge([$entityName], $populate);
$filter = static fn (string $groupName): bool => strncmp($groupName, 'Set.', 4) === 0;
$groups = [$entityName, ...$populate];
$filter = static fn (string $groupName): bool => str_starts_with($groupName, 'Set.');

if (array_key_exists('populateOnly', $request->query->all())
|| array_values(array_filter($groups, $filter)) !== []
Expand Down
9 changes: 4 additions & 5 deletions src/Security/ApiKeyUser.php
Expand Up @@ -12,7 +12,6 @@
use App\Enum\Role;
use App\Security\Interfaces\ApiKeyUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use function array_merge;
use function array_unique;

/**
Expand All @@ -23,13 +22,13 @@
*/
class ApiKeyUser implements ApiKeyUserInterface, UserInterface
{
private string $identifier;
private string $apiKeyIdentifier;
private readonly string $identifier;
private readonly string $apiKeyIdentifier;

/**
* @var array<int, string>
*/
private array $roles;
private readonly array $roles;

/**
* {@inheritdoc}
Expand All @@ -38,7 +37,7 @@ public function __construct(ApiKey $apiKey, array $roles)
{
$this->identifier = $apiKey->getToken();
$this->apiKeyIdentifier = $apiKey->getId();
$this->roles = array_unique(array_merge($roles, [Role::API->value]));
$this->roles = array_unique([...$roles, Role::API->value]);
}

public function getUserIdentifier(): string
Expand Down
10 changes: 5 additions & 5 deletions src/Security/SecurityUser.php
Expand Up @@ -22,11 +22,11 @@
*/
class SecurityUser implements UserInterface, PasswordAuthenticatedUserInterface
{
private string $identifier;
private string | null $password;
private Language $language;
private Locale $locale;
private string $timezone;
private readonly string $identifier;
private readonly string | null $password;
private readonly Language $language;
private readonly Locale $locale;
private readonly string $timezone;

/**
* SecurityUser constructor.
Expand Down

0 comments on commit e0a5eaf

Please sign in to comment.