<commit_before><?php
declare(strict_types = 1);
/**
 * /src/ArgumentResolver/EntityValueResolver.php
 *
 * @author TLe, <NAME> <<EMAIL>>
 */

namespace App\ArgumentResolver;

use App\Entity\Interfaces\EntityInterface;
use App\Resource\ResourceCollection;
use Generator;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface;
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;
use Throwable;
use function is_string;
use function is_subclass_of;

/**
 * Class EntityValueResolver
 *
 * Example how to use this within your controller;
 *
 *  #[Route(path: 'some_path_to_your_route/{user}/{apikey}')]
 *  public function someMethod(\App\Entity\User $user, \App\Entity\ApiKey $apikey): Response
 *  {
 *      ...
 *  }
 *
 * And when you make your request like `GET /some_path_to_your_route/_user_uuid_/_apikey_uuid`
 * you will get those entities to your controller method which are resolved automatically via
 * those entity resource classes.
 *
 * Only thing that you need check is that parameter in your `path` definition matches with
 * method argument name.
 *
 * @package App\ArgumentResolver
 * @author TLe, <NAME> <<EMAIL>>
 */
class EntityValueResolver implements ArgumentValueResolverInterface
{
    public function __construct(
        private ResourceCollection $resourceCollection,
    ) {
    }

    public function supports(Request $request, ArgumentMetadata $argument): bool
    {
        $uuid = $request->query->get($argument->getName())
            ?? $request->request->get($argument->getName())
            ?? $request->attributes->get($argument->getName());

        return is_string($uuid)
            && is_subclass_of((string)$argument->getType(), EntityInterface::class, true)
            && $this->resourceCollection->hasEntityResource($argument->getType());
    }

    /**
     * @throws Throwable
     *
     * @return Generator<EntityInterface|null>
     */
    public function resolve(Request $request, ArgumentMetadata $argument): Generator
    {
        $uuid = $request->query->get($argument->getName())
            ?? $request->request->get($argument->getName())
            ?? $request->attributes->get($argument->getName());
        
        yield $this->resourceCollection
            ->getEntityResource((string)$argument->getType())
            ->findOne((string)($uuid), !$argument->isNullable());
    }
}<commit_msg>Fixed ECS error<commit_after><?php
declare(strict_types = 1);
/**
 * /src/ArgumentResolver/EntityValueResolver.php
 *
 * @author TLe, <NAME> <<EMAIL>>
 */

namespace App\ArgumentResolver;

use App\Entity\Interfaces\EntityInterface;
use App\Resource\ResourceCollection;
use Generator;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface;
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;
use Throwable;
use function is_string;
use function is_subclass_of;

/**
 * Class EntityValueResolver
 *
 * Example how to use this within your controller;
 *
 *  #[Route(path: 'some_path_to_your_route/{user}/{apikey}')]
 *  public function someMethod(\App\Entity\User $user, \App\Entity\ApiKey $apikey): Response
 *  {
 *      ...
 *  }
 *
 * And when you make your request like `GET /some_path_to_your_route/_user_uuid_/_apikey_uuid`
 * you will get those entities to your controller method which are resolved automatically via
 * those entity resource classes.
 *
 * Only thing that you need check is that parameter in your `path` definition matches with
 * method argument name.
 *
 * @package App\ArgumentResolver
 * @author TLe, <NAME> <<EMAIL>>
 */
class EntityValueResolver implements ArgumentValueResolverInterface
{
    public function __construct(
        private ResourceCollection $resourceCollection,
    ) {
    }

    public function supports(Request $request, ArgumentMetadata $argument): bool
    {
        $uuid = $request->query->get($argument->getName())
            ?? $request->request->get($argument->getName())
            ?? $request->attributes->get($argument->getName());

        return is_string($uuid)
            && is_subclass_of((string)$argument->getType(), EntityInterface::class, true)
            && $this->resourceCollection->hasEntityResource($argument->getType());
    }

    /**
     * @throws Throwable
     *
     * @return Generator<EntityInterface|null>
     */
    public function resolve(Request $request, ArgumentMetadata $argument): Generator
    {
        $uuid = $request->query->get($argument->getName())
            ?? $request->request->get($argument->getName())
            ?? $request->attributes->get($argument->getName());

        yield $this->resourceCollection
            ->getEntityResource((string)$argument->getType())
            ->findOne((string)($uuid), !$argument->isNullable());
    }
}
{'fraction_non_alphanumeric': 0.1304883052933935, 'fraction_numerical': 0.0004103405826836274, 'mean_word_length': 3.774730656219393, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 71, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6429673', 'n_tokens_mistral': 1299, 'n_tokens_neox': 1296, 'n_words': 296}