*/ private array $converters, ) {} /** * @return list */ public function converters(): array { if (! $this->convertersCallablesWereChecked) { $this->convertersCallablesWereChecked = true; foreach ($this->converters as $transformer) { $function = $this->functionDefinitionRepository->for($transformer); self::checkConverter($function); } } return $this->converters; } public static function filterConverterAttributes(AttributeDefinition $attribute): bool { return $attribute->class->methods->has('map') && self::checkConverter($attribute->class->methods->get('map')); } private static function checkConverter(MethodDefinition|FunctionDefinition $method): bool { $parameters = $method->parameters; if ($parameters->count() === 0) { throw new ConverterHasNoParameter($method); } if ($parameters->count() > 2) { throw new ConverterHasTooManyParameters($method); } if ($parameters->count() > 1 && ! $parameters->at(1)->nativeType instanceof CallableType) { throw new ConverterHasInvalidCallableParameter($method, $parameters->at(1)->nativeType); } return true; } }