Skip to content
Permalink
Browse files

Merge pull request #113 from tarlepp/type-coverage

Type coverage
  • Loading branch information...
tarlepp committed Jul 13, 2019
2 parents 4d7accb + ceb4a74 commit e507b5dd94f36f2e44af0c7e8c61725a152a55ec
Showing with 415 additions and 347 deletions.
  1. +1 −1 Makefile
  2. +5 −5 composer.lock
  3. +1 −4 phpstan.neon.dist
  4. +6 −4 src/ArgumentResolver/RestDtoValueResolver.php
  5. +21 −4 src/AutoMapper/RestRequestMapper.php
  6. +12 −7 src/Command/ApiKey/ApiKeyHelper.php
  7. +4 −7 src/Command/ApiKey/ChangeTokenCommand.php
  8. +15 −14 src/Command/ApiKey/CreateApiKeyCommand.php
  9. +11 −15 src/Command/ApiKey/EditApiKeyCommand.php
  10. +19 −22 src/Command/ApiKey/ListApiKeysCommand.php
  11. +4 −3 src/Command/ApiKey/RemoveApiKeyCommand.php
  12. +10 −16 src/Command/HelperConfigure.php
  13. +7 −5 src/Command/Traits/ExecuteMultipleCommandTrait.php
  14. +17 −16 src/Command/User/CreateUserCommand.php
  15. +16 −15 src/Command/User/CreateUserGroupCommand.php
  16. +13 −17 src/Command/User/EditUserCommand.php
  17. +12 −16 src/Command/User/EditUserGroupCommand.php
  18. +18 −20 src/Command/User/ListUserGroupsCommand.php
  19. +18 −21 src/Command/User/ListUsersCommand.php
  20. +5 −3 src/Command/User/RemoveUserCommand.php
  21. +5 −3 src/Command/User/RemoveUserGroupCommand.php
  22. +18 −7 src/Command/User/UserHelper.php
  23. +11 −4 src/Command/Utils/CheckVendorDependencies.php
  24. +2 −0 src/Controller/DefaultController.php
  25. +6 −1 src/Controller/ProfileController.php
  26. +1 −1 src/Controller/UserController.php
  27. +1 −1 src/Controller/UserGroupController.php
  28. +8 −4 src/DTO/ApiKey/ApiKey.php
  29. +8 −4 src/DTO/User/User.php
  30. +4 −3 src/Doctrine/DBAL/Types/EnumType.php
  31. +10 −10 src/Doctrine/DBAL/Types/UTCDateTimeType.php
  32. +10 −7 src/Entity/ApiKey.php
  33. +4 −1 src/Entity/Traits/UserRelations.php
  34. +7 −3 src/Form/DataTransformer/RoleTransformer.php
  35. +1 −1 src/Form/Type/Console/ApiKeyType.php
  36. +1 −1 src/Form/Type/Console/UserGroupType.php
  37. +1 −1 src/Form/Type/Console/UserType.php
  38. +2 −2 src/Form/Type/Traits/AddBasicFieldToForm.php
  39. +10 −10 src/Repository/BaseRepository.php
  40. +4 −4 src/Repository/BaseRepositoryInterface.php
  41. +7 −5 src/Repository/HealthzRepository.php
  42. +7 −3 src/Repository/UserRepository.php
  43. +2 −2 src/Request/ParamConverter/RestResourceConverter.php
  44. +4 −4 src/Rest/ResponseHandler.php
  45. +2 −3 src/Rest/SearchTerm.php
  46. +4 −6 src/Security/Authenticator/ApiKeyAuthenticator.php
  47. +9 −8 src/Security/RolesService.php
  48. +5 −5 src/Security/RolesServiceInterface.php
  49. +1 −0 src/Security/Voter/IsUserHimselfVoter.php
  50. +17 −1 tests/Integration/AutoMapper/GenericRestRequestMapperTest.php
  51. +1 −0 tests/Integration/Doctrine/DBAL/Types/EnumLogLoginTypeTest.php
  52. +1 −1 vendor-bin/phpstan/composer.json
  53. +6 −6 vendor-bin/phpstan/composer.lock
  54. +15 −15 vendor-bin/phpunit/composer.lock
  55. +5 −5 vendor-bin/psalm/composer.lock
@@ -183,7 +183,7 @@ phpinsights: ## Runs PHP Insights
psalm: ## Runs Psalm static analysis tool
@echo "\033[32mRunning Psalm - A static analysis tool for PHP\033[39m"
@php ./vendor/bin/psalm --version
@php ./vendor/bin/psalm --no-cache --shepherd --report=./build/psalm.json
@php ./vendor/bin/psalm --no-cache --shepherd --stats --report=./build/psalm.json
###< psalm ###

###> phpstan ###

Some generated files are not rendered by default. Learn more.

@@ -1,9 +1,6 @@
parameters:
inferPrivatePropertyTypeFromConstructor: true
excludes_analyse:
- %currentWorkingDirectory%/src/Migrations/*
symfony:
container_xml_path: '%currentWorkingDirectory%/var/cache/dev/srcApp_KernelDevDebugContainer.xml'
ignoreErrors:
-
message: '/Parameter #2 \$orderBy */'
path: %currentWorkingDirectory%/src/Repository/Traits/RepositoryMethodsTrait.php
@@ -81,11 +81,11 @@ public function __construct(ControllerCollection $controllerCollection, AutoMapp
*/
public function supports(Request $request, ArgumentMetadata $argument): bool
{
if (count(explode('::', $request->attributes->get(self::CONTROLLER_KEY))) !== 2) {
if (count(explode('::', (string)$request->attributes->get(self::CONTROLLER_KEY))) !== 2) {
return false;
}
[$controllerName, $actionName] = explode('::', $request->attributes->get(self::CONTROLLER_KEY));
[$controllerName, $actionName] = explode('::', (string)$request->attributes->get(self::CONTROLLER_KEY));
return $argument->getType() === RestDtoInterface::class
&& in_array($actionName, $this->supportedActions, true)
@@ -104,9 +104,11 @@ public function supports(Request $request, ArgumentMetadata $argument): bool
*/
public function resolve(Request $request, ArgumentMetadata $argumentMetadata): Generator
{
[$controllerName, $actionName] = explode('::', $request->attributes->get(self::CONTROLLER_KEY));
[$controllerName, $actionName] = explode('::', (string)$request->attributes->get(self::CONTROLLER_KEY));
$dtoClass = $this->controllerCollection->get($controllerName)->getDtoClass($this->actionMethodMap[$actionName]);
$dtoClass = $this->controllerCollection
->get($controllerName)
->getDtoClass((string)$this->actionMethodMap[$actionName]);
yield $this->autoMapper->map($request, $dtoClass);
}
@@ -16,6 +16,8 @@
use function array_filter;
use function count;
use function get_class;
use function gettype;
use function is_object;
use function method_exists;
use function sprintf;
use function ucfirst;
@@ -31,14 +33,16 @@ abstract class RestRequestMapper implements MapperInterface
/**
* Properties to map to destination object.
*
* @var string[]
* @var array<int, string>
*/
protected static $properties = [];
/**
* @inheritdoc
*
* @param array $context
* @param array|object $source
* @param string $targetClass
* @param array|array<int, mixed> $context
*
* @return RestDtoInterface
*/
@@ -52,12 +56,23 @@ public function map($source, string $targetClass, array $context = []): RestDtoI
/**
* @inheritdoc
*
* @param array $context
* @param array|object $source
* @param object $destination
* @param array|array<int, mixed> $context
*
* @return RestDtoInterface
*/
public function mapToObject($source, $destination, array $context = []): RestDtoInterface
{
if (!is_object($source)) {
throw new InvalidArgumentException(
sprintf(
'RestRequestMapper expects that $source is Request object, "%s" provided',
gettype($source)
)
);
}
if (!$source instanceof Request) {
throw new InvalidArgumentException(
sprintf(
@@ -100,9 +115,11 @@ private function getObject(Request $request, RestDtoInterface $restDto): RestDto
$setter = 'set' . ucfirst($property);
$transformer = 'transform' . ucfirst($property);
/** @var int|string|array|null $value */
$value = $request->request->get($property);
if (method_exists($this, $transformer)) {
/** @var int|string|object|array|null $value */
$value = $this->{$transformer}($value);
}
@@ -115,7 +132,7 @@ private function getObject(Request $request, RestDtoInterface $restDto): RestDto
/**
* @param Request $request
*
* @return array
* @return array<int, string>
*/
private function getValidProperties(Request $request): array
{
@@ -9,11 +9,11 @@
namespace App\Command\ApiKey;
use App\Entity\ApiKey as ApiKeyEntity;
use App\Entity\EntityInterface;
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;
@@ -53,13 +53,16 @@ public function __construct(ApiKeyResource $apiKeyResource, RolesService $rolesS
* changes to API keys.
*
* @param SymfonyStyle $io
* @param string $question
* @param string $question
*
* @return ApiKeyEntity|null
*
* @throws Throwable
*/
public function getApiKey(SymfonyStyle $io, string $question): ?ApiKeyEntity
{
$apiKeyFound = false;
$apiKeyEntity = null;
while ($apiKeyFound !== true) {
/** @var ApiKeyEntity|null $apiKeyEntity */
@@ -92,7 +95,7 @@ public function getApiKey(SymfonyStyle $io, string $question): ?ApiKeyEntity
* @param string $message
* @param ApiKeyEntity $apiKey
*
* @return mixed[]
* @return array<int, string>
*/
public function getApiKeyMessage(string $message, ApiKeyEntity $apiKey): array
{
@@ -110,11 +113,13 @@ public function getApiKeyMessage(string $message, ApiKeyEntity $apiKey): array
* Method to list ApiKeys where user can select desired one.
*
* @param SymfonyStyle $io
* @param string $question
* @param string $question
*
* @return ApiKeyEntity|null
*
* @return ApiKeyEntity|EntityInterface|null
* @throws Throwable
*/
private function getApiKeyEntity(SymfonyStyle $io, string $question): ?EntityInterface
private function getApiKeyEntity(SymfonyStyle $io, string $question): ?ApiKeyEntity
{
$choices = [];
$iterator = $this->getApiKeyIterator($choices);
@@ -123,7 +128,7 @@ private function getApiKeyEntity(SymfonyStyle $io, string $question): ?EntityInt
$choices['Exit'] = 'Exit command';
return $this->apiKeyResource->findOne($io->choice($question, $choices));
return $this->apiKeyResource->findOne((string)$io->choice($question, $choices));
}
/**
@@ -12,10 +12,10 @@
use App\Entity\ApiKey as ApiKeyEntity;
use App\Resource\ApiKeyResource;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Exception\InvalidArgumentException;
use Symfony\Component\Console\Exception\LogicException;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Throwable;
/**
* Class ChangeTokenCommand
@@ -65,17 +65,15 @@ public function __construct(ApiKeyResource $apiKeyResource, ApiKeyHelper $apiKey
*
* @return int|null
*
* @throws InvalidArgumentException
* @throws LogicException
* @throws \Doctrine\ORM\ORMException
* @throws \Doctrine\ORM\OptimisticLockException
* @throws Throwable
*/
protected function execute(InputInterface $input, OutputInterface $output): ?int
{
$io = $this->getSymfonyStyle($input, $output);
// Get API key entity
$apiKey = $this->apiKeyHelper->getApiKey($io, 'Which API key token you want to change?');
$message = null;
if ($apiKey instanceof ApiKeyEntity) {
$message = $this->changeApiKeyToken($apiKey);
@@ -95,8 +93,7 @@ protected function execute(InputInterface $input, OutputInterface $output): ?int
*
* @return mixed[]
*
* @throws \Doctrine\ORM\ORMException
* @throws \Doctrine\ORM\OptimisticLockException
* @throws Throwable
*/
private function changeApiKeyToken(ApiKeyEntity $apiKey): array
{
@@ -17,10 +17,14 @@
use App\Resource\ApiKeyResource;
use App\Resource\UserGroupResource;
use App\Security\RolesService;
use Matthias\SymfonyConsoleForm\Console\Helper\FormHelper;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Exception\InvalidArgumentException;
use Symfony\Component\Console\Exception\LogicException;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Throwable;
/**
* Class CreateApiKeyCommand
@@ -34,7 +38,7 @@ class CreateApiKeyCommand extends Command
use ApiKeyUserManagementHelperTrait;
/**
* @var mixed[]
* @var array<int, array<string, int|string>>
*/
private static $commandParameters = [
[
@@ -82,7 +86,7 @@ class CreateApiKeyCommand extends Command
* @param RolesService $rolesService
* @param RoleRepository $roleRepository
*
* @throws \Symfony\Component\Console\Exception\LogicException
* @throws LogicException
*/
public function __construct(
ApiKeyHelper $apiKeyHelper,
@@ -115,10 +119,12 @@ public function getRolesService(): RolesService
/**
* Configures the current command.
*
* @throws \Symfony\Component\Console\Exception\InvalidArgumentException
* @throws InvalidArgumentException
*/
protected function configure(): void
{
parent::configure();
HelperConfigure::configure($this, self::$commandParameters);
}
@@ -131,12 +137,7 @@ protected function configure(): void
*
* @return int|null null or 0 if everything went fine, or an error code
*
* @throws \Exception
* @throws \InvalidArgumentException
* @throws \Doctrine\ORM\NonUniqueResultException
* @throws \Symfony\Component\Console\Exception\CommandNotFoundException
* @throws \Symfony\Component\Console\Exception\InvalidArgumentException
* @throws \Symfony\Component\Console\Exception\LogicException
* @throws Throwable
*/
protected function execute(InputInterface $input, OutputInterface $output): ?int
{
@@ -146,8 +147,11 @@ protected function execute(InputInterface $input, OutputInterface $output): ?int
// Check that user group(s) exists
$this->checkUserGroups($output, $input->isInteractive());
/** @var FormHelper $helper */
$helper = $this->getHelper('form');
/** @var ApiKey $dto */
$dto = $this->getHelper('form')->interactUsingForm(ApiKeyType::class, $input, $output);
$dto = $helper->interactUsingForm(ApiKeyType::class, $input, $output);
// Create new API key
/** @var ApiKeyEntity $apiKey */
@@ -171,10 +175,7 @@ protected function execute(InputInterface $input, OutputInterface $output): ?int
* @param OutputInterface $output
* @param bool $interactive
*
* @throws \Exception
* @throws \InvalidArgumentException
* @throws \Doctrine\ORM\NonUniqueResultException
* @throws \Symfony\Component\Console\Exception\CommandNotFoundException
* @throws Throwable
*/
private function checkUserGroups(OutputInterface $output, bool $interactive): void
{

0 comments on commit e507b5d

Please sign in to comment.
You can’t perform that action at this time.