Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix deprecations in PHP 8 #8921

Merged
merged 1 commit into from May 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/Composer/EventDispatcher/EventDispatcher.php
Expand Up @@ -326,14 +326,23 @@ protected function checkListenerExpectedEvent($target, Event $event)
return $event;
}

$typehint = $reflected->getClass();
$expected = null;
$isClass = false;
if (\PHP_VERSION_ID >= 70000) {
$reflectionType = $reflected->getType();
if ($reflectionType) {
$expected = $reflectionType instanceof \ReflectionNamedType ? $reflectionType->getName() : (string)$reflectionType;
$isClass = !$reflectionType->isBuiltin();
}
} else {
$expected = $reflected->getClass() ? $reflected->getClass()->getName() : null;
$isClass = null !== $expected;
}

if (!$typehint instanceof \ReflectionClass) {
if (!$isClass) {
return $event;
}

$expected = $typehint->getName();

// BC support
if (!$event instanceof $expected && $expected === 'Composer\Script\CommandEvent') {
trigger_error('The callback '.$this->serializeCallback($target).' declared at '.$reflected->getDeclaringFunction()->getFileName().' accepts a '.$expected.' but '.$event->getName().' events use a '.get_class($event).' instance. Please adjust your type hint accordingly, see https://getcomposer.org/doc/articles/scripts.md#event-classes', E_USER_DEPRECATED);
Expand Down
16 changes: 14 additions & 2 deletions src/Composer/Repository/RepositoryManager.php
Expand Up @@ -127,8 +127,20 @@ public function createRepository($type, $config, $name = null)

$reflMethod = new \ReflectionMethod($class, '__construct');
$params = $reflMethod->getParameters();
if (isset($params[4]) && $params[4]->getClass() && $params[4]->getClass()->getName() === 'Composer\Util\RemoteFilesystem') {
return new $class($config, $this->io, $this->config, $this->eventDispatcher, $this->rfs);
if (isset($params[4])) {
$paramType = null;
if (\PHP_VERSION_ID >= 70000) {
$reflectionType = $params[4]->getType();
if ($reflectionType) {
$paramType = $reflectionType instanceof \ReflectionNamedType ? $reflectionType->getName() : (string)$reflectionType;
}
} else {
$paramType = $params[4]->getClass() ? $params[4]->getClass()->getName() : null;
}

if ($paramType === 'Composer\Util\RemoteFilesystem') {
return new $class($config, $this->io, $this->config, $this->eventDispatcher, $this->rfs);
}
}

return new $class($config, $this->io, $this->config, $this->eventDispatcher);
Expand Down