Skip to content

Commit

Permalink
Require parameters to have type declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
tlmcclatchey committed Feb 17, 2024
1 parent 0be6ae3 commit d886e27
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Support/ValueFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

use Closure;
use CommonPHP\DependencyInjection\Exceptions\ParameterDiscoveryFailedException;
use CommonPHP\DependencyInjection\Exceptions\ParameterTypeRequiredException;
use CommonPHP\DependencyInjection\Exceptions\UnsupportedReflectionTypeException;
use ReflectionFunction;
use ReflectionMethod;
Expand Down Expand Up @@ -115,6 +116,7 @@ public function findValue(string $name, ReflectionType $types, array $passedPara
* @return array An array of resolved parameters suitable for invoking the function or method.
* @throws ParameterDiscoveryFailedException
* @throws UnsupportedReflectionTypeException
* @throws ParameterTypeRequiredException
*/
public function findParameters(ReflectionFunction|ReflectionMethod $source, array $passedParameters): array
{
Expand All @@ -126,6 +128,14 @@ public function findParameters(ReflectionFunction|ReflectionMethod $source, arra
foreach ($source->getParameters() as $parameter)
{
$found = false;
if ($parameter->getType() === null)
{
throw new ParameterTypeRequiredException(
$source instanceof ReflectionMethod ? $source->getDeclaringClass()->getName() : '{main}',
$source->getName(),
$parameter->getName()
);
}

// Try to find the value
$newValue = $this->findValue($parameter->getName(), $parameter->getType(), $passedParameters, $found);
Expand Down

0 comments on commit d886e27

Please sign in to comment.