workaround for internal stan error

master
Josha von Gizycki 1 week ago
parent ff8b022454
commit 79c0272cec

@ -5,6 +5,7 @@ declare(strict_types=1);
namespace Kartierung\Repository;
use Kartierung\Analyze\RepositoryAnalyzer;
use Kartierung\Analyze\Result\RepositoryMethod;
use Kartierung\Analyze\Result\RepositoryResult;
use Kartierung\Repository\ResolutionStrategy\ResolutionStrategyFactory;
use PDO;
@ -26,10 +27,10 @@ readonly class Repository
$repoResult = (new RepositoryAnalyzer($resolutionStrategyFactory))->analyze($clazz);
/**
* @var R of object
* @var R $proxy
* @phpstan-ignore varTag.nativeType
*/
return new class($repoResult, $this->pdo) {
$proxy = new class($repoResult, $this->pdo) {
public function __construct(
private readonly RepositoryResult $repoResult,
private readonly PDO $pdo
@ -43,17 +44,30 @@ readonly class Repository
public function __call(string $methodName, array $arguments): mixed
{
$repoMethod = $this->repoResult->methods[$methodName];
$queryArgs = $this->callArgsToQueryArgs($repoMethod, $arguments);
$argCount = 0;
$callParams = [];
foreach ($repoMethod->parameters as $parameter) {
$callParams[$parameter->name] = $arguments[$argCount++];
}
$query = $repoMethod->createQuery($callParams);
$query = $repoMethod->createQuery($queryArgs);
return $query->execute($this->pdo);
}
/**
* @param RepositoryMethod $method
* @param list<mixed> $arguments
* @return array<string, mixed>
*/
private function callArgsToQueryArgs(RepositoryMethod $method, array $arguments): array
{
$queryArgs = [];
foreach ($method->parameters as $i => $parameter) {
$queryArgs[$parameter->name] = $arguments[$i];
}
return $queryArgs;
}
};
return $proxy;
}
}

Loading…
Cancel
Save