26 require_once __DIR__ .
'/Maintenance.php';
27 require_once __DIR__ .
'/../vendor/autoload.php';
36 $retVal = parent::enterNode( $node );
42 $this->currentFile = $filename;
61 foreach ( $this->foundNodes as $version => &$nodes ) {
62 uasort( $nodes,
function ( $a, $b ) {
63 return ( $a[
'filename'] . $a[
'name'] ) <=> ( $b[
'filename'] . $b[
'name'] );
66 ksort( $this->foundNodes );
77 if ( !$node->stmts ) {
80 foreach ( $node->stmts as $stmt ) {
82 $stmt instanceof PhpParser\Node\Expr\FuncCall
83 && $stmt->name->toString() ===
'wfDeprecated'
92 $retVal = parent::enterNode( $node );
94 if ( $node instanceof PhpParser\Node\Stmt\ClassLike ) {
95 $this->currentClass = $node->name;
98 if ( $node instanceof PhpParser\Node\FunctionLike ) {
99 $docComment = $node->getDocComment();
100 if ( !$docComment ) {
103 if ( !preg_match(
'/@deprecated.*(\d+\.\d+)/', $docComment->getText(),
$matches ) ) {
108 if ( $node instanceof PhpParser\Node\Stmt\ClassMethod ) {
109 $name = $this->currentClass .
'::' . $node->name;
114 $this->foundNodes[ $version ][] = [
115 'filename' => $node->filename,
116 'line' => $node->getLine(),
132 parent::__construct();
142 $files =
new RecursiveDirectoryIterator(
$IP .
'/includes' );
143 $files =
new RecursiveIteratorIterator( $files );
144 $files =
new RegexIterator( $files,
'/\.php$/' );
145 return iterator_to_array( $files,
false );
152 $chunkSize = ceil( count( $files ) / 72 );
154 $parser = (
new PhpParser\ParserFactory )->create( PhpParser\ParserFactory::PREFER_PHP7 );
155 $traverser =
new PhpParser\NodeTraverser;
157 $traverser->addVisitor( $finder );
159 $fileCount = count( $files );
161 for ( $i = 0; $i < $fileCount; $i++ ) {
163 $code = file_get_contents(
$file );
165 if ( strpos( $code,
'@deprecated' ) === -1 ) {
169 $finder->setCurrentFile( substr(
$file->getPathname(), strlen(
$IP ) + 1 ) );
170 $nodes = $parser->parse( $code );
171 $traverser->traverse( $nodes );
173 if ( $i % $chunkSize === 0 ) {
174 $percentDone = 100 * $i / $fileCount;
175 fprintf( STDERR,
"\r[%-72s] %d%%", str_repeat(
'#', $i / $chunkSize ), $percentDone );
179 fprintf( STDERR,
"\r[%'#-72s] 100%%\n",
'' );
183 $versionFmt =
"\n* Deprecated since \033[37;1m%s\033[0m:\n";
184 $entryFmt =
" %s \033[33;1m%s\033[0m (%s:%d)\n";
186 $versionFmt =
"\n* Deprecated since %s:\n";
187 $entryFmt =
" %s %s (%s:%d)\n";
190 foreach ( $finder->getFoundNodes() as $version => $nodes ) {
191 printf( $versionFmt, $version );
192 foreach ( $nodes as $node ) {
195 $node[
'hard'] ?
'+' :
'-',
202 printf(
"\nlegend:\n -: soft-deprecated\n +: hard-deprecated (via wfDeprecated())\n" );