Skip to content

Commit

Permalink
minor #20170 [HttpKernel] Clean ArgumentMetadataFactory::getType() (n…
Browse files Browse the repository at this point in the history
…icolas-grekas)

This PR was merged into the 3.1 branch.

Discussion
----------

[HttpKernel] Clean ArgumentMetadataFactory::getType()

| Q             | A
| ------------- | ---
| Branch?       | 3.1
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

By using the string representation of the parameter to get the type hint (on PHP5 only of course), we prevent autoloading of the corresponding class.

Commits
-------

c780978 [HttpKernel] Clean ArgumentMetadataFactory::getType()
  • Loading branch information
fabpot committed Oct 6, 2016
2 parents 134556a + c780978 commit a4a68bc
Showing 1 changed file with 2 additions and 15 deletions.
Expand Up @@ -122,21 +122,8 @@ private function getType(\ReflectionParameter $parameter)
return $typeName;
}

if ($parameter->isArray()) {
return 'array';
if (preg_match('/^(?:[^ ]++ ){4}([a-zA-Z_\x7F-\xFF][^ ]++)/', $parameter, $info)) {
return $info[1];
}

if ($parameter->isCallable()) {
return 'callable';
}

try {
$refClass = $parameter->getClass();
} catch (\ReflectionException $e) {
// mandatory; extract it from the exception message
return str_replace(array('Class ', ' does not exist'), '', $e->getMessage());
}

return $refClass ? $refClass->getName() : null;
}
}

0 comments on commit a4a68bc

Please sign in to comment.