Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed some Psalm issues #2537

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion src/AutoMapper/RestRequestMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ abstract class RestRequestMapper implements MapperInterface
*/
public function map($source, string $targetClass, array $context = []): RestDtoInterface
{
/** @psalm-var class-string $targetClass */
/** @psalm-var class-string<RestDtoInterface> $targetClass */
$destination = new $targetClass();

return $this->mapToObject($source, $destination, $context);
Expand Down
31 changes: 7 additions & 24 deletions src/Command/ApiKey/ApiKeyHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@
use App\Entity\ApiKey;
use App\Resource\ApiKeyResource;
use App\Security\RolesService;
use Closure;
use Symfony\Component\Console\Style\SymfonyStyle;
use Throwable;
use function array_map;
use function implode;
use function sprintf;

Expand Down Expand Up @@ -90,35 +88,20 @@ public function getApiKeyMessage(string $message, ApiKey $apiKey): array
*/
private function getApiKeyEntity(SymfonyStyle $io, string $question): ?ApiKey
{
/** @var array<string, string> $choices */
$choices = [];

array_map(
$this->getApiKeyIterator($choices),
$this->apiKeyResource->find(orderBy: [
'token' => 'ASC',
])
);

$choices['Exit'] = 'Exit command';

return $this->apiKeyResource->findOne((string)$io->choice($question, $choices));
}

/**
* Method to return ApiKeyIterator closure. This will format ApiKey
* entities for choice list.
*
* @param array<string, string> $choices
*/
private function getApiKeyIterator(array &$choices): Closure
{
return function (ApiKey $apiKey) use (&$choices): void {
foreach ($this->apiKeyResource->find() as $apiKey) {
$choices[$apiKey->getId()] = sprintf(
'[Token: %s] %s - Roles: %s',
$apiKey->getToken(),
$apiKey->getDescription(),
implode(', ', $this->rolesService->getInheritedRoles($apiKey->getRoles())),
);
};
}

$choices['Exit'] = 'Exit command';

return $this->apiKeyResource->findOne((string)$io->choice($question, $choices));
}
}
2 changes: 1 addition & 1 deletion src/Command/ApiKey/ListApiKeysCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
/**
* Getter method for formatted API key rows for console table.
*
* @return array<int, string>
* @return array<array-key, mixed>
*
* @throws Throwable
*/
Expand Down Expand Up @@ -99,7 +99,7 @@
$apiToken->getId(),
$apiToken->getToken(),
$apiToken->getDescription(),
implode(",\n", $apiToken->getUserGroups()->map($userGroupFormatter)->toArray()),

Check warning on line 102 in src/Command/ApiKey/ListApiKeysCommand.php

View workflow job for this annotation

GitHub Actions / Static analyzers

MixedArgumentTypeCoercion

src/Command/ApiKey/ListApiKeysCommand.php:102:60: MixedArgumentTypeCoercion: Argument 1 of Doctrine\Common\Collections\Collection::map expects Closure(T:Doctrine\Common\Collections\Collection as mixed):non-empty-string, but parent type pure-Closure(App\Entity\UserGroup):non-empty-string provided (see https://psalm.dev/194)
implode(",\n", $this->rolesService->getInheritedRoles($apiToken->getRoles())),
];
}
Expand Down
2 changes: 1 addition & 1 deletion src/Command/User/ListUserGroupsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
/**
* Getter method for formatted user group rows for console table.
*
* @return array<int, string>
* @return array<array-key, mixed>
*
* @throws Throwable
*/
Expand Down Expand Up @@ -98,7 +98,7 @@
$userGroup->getId(),
$userGroup->getName(),
$userGroup->getRole()->getId(),
implode(",\n", $userGroup->getUsers()->map($userFormatter)->toArray()),

Check warning on line 101 in src/Command/User/ListUserGroupsCommand.php

View workflow job for this annotation

GitHub Actions / Static analyzers

MixedArgumentTypeCoercion

src/Command/User/ListUserGroupsCommand.php:101:56: MixedArgumentTypeCoercion: Argument 1 of Doctrine\Common\Collections\Collection::map expects Closure(T:Doctrine\Common\Collections\Collection as mixed):non-empty-string, but parent type pure-Closure(App\Entity\User):non-empty-string provided (see https://psalm.dev/194)
];
}
}
2 changes: 1 addition & 1 deletion src/Command/User/ListUsersCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
/**
* Getter method for formatted user rows for console table.
*
* @return array<int, string>
* @return array<array-key, mixed>
*
* @throws Throwable
*/
Expand Down Expand Up @@ -103,7 +103,7 @@
$user->getEmail(),
$user->getFirstName() . ' ' . $user->getLastName(),
implode(",\n", $this->roles->getInheritedRoles($user->getRoles())),
implode(",\n", $user->getUserGroups()->map($userGroupFormatter)->toArray()),

Check warning on line 106 in src/Command/User/ListUsersCommand.php

View workflow job for this annotation

GitHub Actions / Static analyzers

MixedArgumentTypeCoercion

src/Command/User/ListUsersCommand.php:106:56: MixedArgumentTypeCoercion: Argument 1 of Doctrine\Common\Collections\Collection::map expects Closure(T:Doctrine\Common\Collections\Collection as mixed):non-empty-string, but parent type pure-Closure(App\Entity\UserGroup):non-empty-string provided (see https://psalm.dev/194)
];
}
}
2 changes: 1 addition & 1 deletion src/Rest/Interfaces/SearchTermInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ interface SearchTermInterface
* @param int|null $mode Used mode on LIKE search. See MODE_* constants. Defaults to
* self::MODE_FULL
*
* @return array<string, array<string, array<string, string>>>|null
* @return array<string, array<string, array<string, mixed>>>|null
*/
public static function getCriteria(
array | string $column,
Expand Down
Loading
Loading