25 require_once __DIR__ .
'/Maintenance.php';
26 require_once __DIR__ .
'/../vendor/autoload.php';
35 $retVal = parent::enterNode( $node );
41 $this->currentFile = $filename;
60 foreach ( $this->foundNodes
as $version => &$nodes ) {
61 uasort( $nodes,
function ( $a, $b ) {
62 return ( $a[
'filename'] . $a[
'name'] ) < ( $b[
'filename'] . $b[
'name'] ) ? -1 : 1;
65 ksort( $this->foundNodes );
76 if ( !$node->stmts ) {
79 foreach ( $node->stmts
as $stmt ) {
81 $stmt instanceof PhpParser\Node\Expr\FuncCall
82 && $stmt->name->toString() ===
'wfDeprecated'
91 $retVal = parent::enterNode( $node );
93 if ( $node instanceof PhpParser\Node\Stmt\ClassLike ) {
94 $this->currentClass = $node->name;
97 if ( $node instanceof PhpParser\Node\FunctionLike ) {
98 $docComment = $node->getDocComment();
102 if ( !preg_match(
'/@deprecated.*(\d+\.\d+)/', $docComment->getText(),
$matches ) ) {
107 if ( $node instanceof PhpParser\Node\Stmt\ClassMethod ) {
108 $name = $this->currentClass .
'::' . $node->name;
113 $this->foundNodes[ $version ][] = [
114 'filename' => $node->filename,
115 'line' => $node->getLine(),
131 parent::__construct();
138 $files =
new RecursiveDirectoryIterator(
$IP .
'/includes' );
139 $files =
new RecursiveIteratorIterator( $files );
140 $files =
new RegexIterator( $files,
'/\.php$/' );
141 return iterator_to_array( $files,
false );
148 $chunkSize = ceil(
count( $files ) / 72 );
150 $parser = (
new PhpParser\ParserFactory )->create( PhpParser\ParserFactory::PREFER_PHP7 );
151 $traverser =
new PhpParser\NodeTraverser;
153 $traverser->addVisitor( $finder );
155 $fileCount =
count( $files );
157 for ( $i = 0; $i < $fileCount; $i++ ) {
159 $code = file_get_contents( $file );
161 if ( strpos(
$code,
'@deprecated' ) === -1 ) {
165 $finder->setCurrentFile( substr( $file->getPathname(), strlen(
$IP ) + 1 ) );
166 $nodes =
$parser->parse(
$code, [
'throwOnError' =>
false ] );
167 $traverser->traverse( $nodes );
169 if ( $i % $chunkSize === 0 ) {
170 $percentDone = 100 * $i / $fileCount;
171 fprintf( STDERR,
"\r[%-72s] %d%%", str_repeat(
'#', $i / $chunkSize ), $percentDone );
175 fprintf( STDERR,
"\r[%'#-72s] 100%%\n",
'' );
179 $versionFmt =
"\n* Deprecated since \033[37;1m%s\033[0m:\n";
180 $entryFmt =
" %s \033[33;1m%s\033[0m (%s:%d)\n";
182 $versionFmt =
"\n* Deprecated since %s:\n";
183 $entryFmt =
" %s %s (%s:%d)\n";
186 foreach ( $finder->getFoundNodes()
as $version => $nodes ) {
187 printf( $versionFmt, $version );
188 foreach ( $nodes
as $node ) {
191 $node[
'hard'] ?
'+' :
'-',
198 printf(
"\nlegend:\n -: soft-deprecated\n +: hard-deprecated (via wfDeprecated())\n" );