Skip to content

Commit

Permalink
Stub generator now handles deprecated namespaced classes (#35144)
Browse files Browse the repository at this point in the history
  • Loading branch information
wilsonge authored Jan 9, 2022
1 parent d0878fb commit e581ffa
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions build/stubGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class StubGenerator extends CliApplication
public function doExecute()
{
$this->createExtensionNamespaceMap();
$contentsByNamespace = [];

$file = "<?php\n";

Expand All @@ -77,18 +78,36 @@ public function doExecute()
$modifier = (!$reflection->isInterface() && $reflection->isFinal()) ? 'final ' : '';
$modifier = ($reflection->isAbstract() && !$reflection->isInterface()) ? $modifier . 'abstract ' : $modifier;

$namespaceSegments = explode('\\', $oldName);
$className = array_pop($namespaceSegments);
$targetNamespace = ltrim(implode('\\', $namespaceSegments), '\\');

// If a deprecated version is available, write a stub class doc block with a deprecated tag
if ($deprecatedVersion !== false)
{
$file .= <<<PHP
/**
* @deprecated $deprecatedVersion Use $newName instead.
*/
$fileContents = <<<PHP
/**
* @deprecated $deprecatedVersion Use $newName instead.
*/
PHP;
}

$file .= "$modifier$type $oldName extends $newName {}\n\n";
$fileContents .= "\t$modifier$type $className extends \\$newName {}\n\n";

if (!array_key_exists($targetNamespace, $contentsByNamespace))
{
$contentsByNamespace[$targetNamespace] = '';
}

$contentsByNamespace[$targetNamespace] .= $fileContents;
}

foreach ($contentsByNamespace as $namespace => $contents)
{
$file .= "namespace $namespace {\n";
$file .= $contents;
$file .= "}\n\n";
}

// And save the file locally
Expand Down

0 comments on commit e581ffa

Please sign in to comment.