Skip to content
This repository has been archived by the owner on Feb 24, 2023. It is now read-only.

Commit

Permalink
Removed calls to deprecated ReflectionParameter::getClass() method.
Browse files Browse the repository at this point in the history
  • Loading branch information
derrabus committed May 31, 2020
1 parent c76bb1c commit 6bad4b1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ php:
- 7.2
- 7.3
- 7.4
- nightly

matrix:
include:
Expand All @@ -27,7 +28,8 @@ before_install:
- export SYMFONY_PHPUNIT_DIR="$(pwd)/.phpunit"
- INI_FILE=~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
- echo memory_limit = -1 >> $INI_FILE
- phpenv config-rm xdebug.ini
- phpenv config-rm xdebug.ini || true
- if [ $TRAVIS_PHP_VERSION = "nightly" ]; then composer config platform.php 7.4.99; fi;

install:
- if [ "$deps" = "no" ]; then composer install; fi;
Expand Down
20 changes: 7 additions & 13 deletions src/EventListener/ParamConverterListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,13 @@ class ParamConverterListener implements EventSubscriberInterface

private $autoConvert;

/**
* @var bool
*/
private $isParameterTypeSupported;

/**
* @param bool $autoConvert Auto convert non-configured objects
*/
public function __construct(ParamConverterManager $manager, $autoConvert = true)
{
$this->manager = $manager;
$this->autoConvert = $autoConvert;
$this->isParameterTypeSupported = method_exists('ReflectionParameter', 'getType');
}

/**
Expand Down Expand Up @@ -81,29 +75,29 @@ public function onKernelController(KernelEvent $event)
private function autoConfigure(\ReflectionFunctionAbstract $r, Request $request, $configurations)
{
foreach ($r->getParameters() as $param) {
if ($param->getClass() && $param->getClass()->isInstance($request)) {
$type = $param->getType();
$class = null !== $type && !$type->isBuiltin() ? $type->getName() : null;
if (null !== $class && $request instanceof $class) {
continue;
}

$name = $param->getName();
$class = $param->getClass();
$hasType = $this->isParameterTypeSupported && $param->hasType();

if ($class || $hasType) {
if ($type) {
if (!isset($configurations[$name])) {
$configuration = new ParamConverter([]);
$configuration->setName($name);

$configurations[$name] = $configuration;
}

if ($class && null === $configurations[$name]->getClass()) {
$configurations[$name]->setClass($class->getName());
if (null !== $class && null === $configurations[$name]->getClass()) {
$configurations[$name]->setClass($class);
}
}

if (isset($configurations[$name])) {
$configurations[$name]->setIsOptional($param->isOptional() || $param->isDefaultValueAvailable() || $hasType && $param->getType()->allowsNull());
$configurations[$name]->setIsOptional($param->isOptional() || $param->isDefaultValueAvailable() || ($type && $type->allowsNull()));
}
}

Expand Down

0 comments on commit 6bad4b1

Please sign in to comment.