[MediaWiki-commits] [Gerrit] mediawiki...namespaceizer[master]: Added conflict and reserved word detection
Tim Starling has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/392364 ) Change subject: Added conflict and reserved word detection .. Added conflict and reserved word detection Detect conflicts due to two classes being renamed to the same thing. Exempt existing class_alias() calls. Detect class names that use PHP reserved words. Change-Id: I91762c902b049fea472a189073acc87ab0ada85f --- M bin/dumpCoreAliases.php M src/CoreAliases.php A src/ReservedWords.php 3 files changed, 333 insertions(+), 117 deletions(-) Approvals: Tim Starling: Verified Anomie: Looks good to me, approved diff --git a/bin/dumpCoreAliases.php b/bin/dumpCoreAliases.php index e115c2b..f5b88e0 100644 --- a/bin/dumpCoreAliases.php +++ b/bin/dumpCoreAliases.php @@ -9,76 +9,94 @@ require __DIR__ . '/../vendor/autoload.php'; -$self = array_shift( $argv ); - -if ( !count( $argv ) ) { - echo "Usage: $self \n"; - exit( 1 ); +function warnCallback( $msg ) { + fwrite( STDERR, "FYI: $msg\n" ); } -if ( $argv[0] === '--counts' ) { - $report = 'counts'; - array_shift( $argv ); -} elseif ( $argv[0] === '--3col' ) { - $report = '3col'; - array_shift( $argv ); -} elseif ( $argv[0] === '--classes' ) { - $report = 'classes'; - array_shift( $argv ); -} else { - $report = 'php'; +function errorCallback( $msg ) { + fwrite( STDERR, "ERROR: $msg\n" ); } -if ( !count( $argv ) ) { - echo "Usage: $self \n"; - exit( 1 ); -} +function dumpCoreAliases() { + global $argv; -$file = $argv[0]; + $self = array_shift( $argv ); -$autoload = AutoloadLoader::getAutoloadClasses( $file ); -if ( $autoload === false ) { - echo "Unable to open autoload file $file\n"; - exit( 1 ); -} + if ( !count( $argv ) ) { + echo "Usage: $self \n"; + exit( 1 ); + } -$ca = new CoreAliases( $autoload ); -$aliases = $ca->getAliases(); - -asort( $aliases ); - -$counts = []; -if ( $report === 'php' ) { - print " $new ) { - if ( $report === 'classes' ) { - print "$old\t$new\n"; - } elseif ( $report === 'php' ) { - print "\t'" . - strtr( $old, [ "\\" => "", "'" => "\\'" ] ) . - "' => '" . - strtr( $new, [ "\\" => "", "'" => "\\'" ] ) . - "',\n"; + if ( $argv[0] === '--counts' ) { + $report = 'counts'; + array_shift( $argv ); + } elseif ( $argv[0] === '--3col' ) { + $report = '3col'; + array_shift( $argv ); + } elseif ( $argv[0] === '--classes' ) { + $report = 'classes'; + array_shift( $argv ); } else { - if ( preg_match( '/(.*)([^]*)$/', $new, $m ) ) { - if ( $report === 'counts' ) { - if ( !isset( $counts[$m[1]] ) ) { - $counts[$m[1]] = 0; + $report = 'php'; + } + + if ( !count( $argv ) ) { + echo "Usage: $self \n"; + exit( 1 ); + } + + $file = $argv[0]; + + $autoload = AutoloadLoader::getAutoloadClasses( $file ); + if ( $autoload === false ) { + echo "Unable to open autoload file $file\n"; + exit( 1 ); + } + + $ca = new CoreAliases( $autoload, 'errorCallback', 'warnCallback' ); + $aliases = $ca->getAliases(); + + if ( $aliases === false ) { + exit( 1 ); + } + + asort( $aliases ); + + $counts = []; + if ( $report === 'php' ) { + print " $new ) { + if ( $report === 'classes' ) { + print "$old\t$new\n"; + } elseif ( $report === 'php' ) { + print "\t'" . + strtr( $old, [ "\\" => "", "'" => "\\'" ] ) . + "' => '" . + strtr( $new, [ "\\" => "", "'" => "\\'" ] ) . + "',\n"; + } else { + if ( preg_match( '/(.*)([^]*)$/', $new, $m ) ) { + if ( $report === 'counts' ) { + if ( !isset( $counts[$m[1]] ) ) { + $counts[$m[1]] = 0; + } + $counts[$m[1]]++; + } elseif ( $report === '3col' ) { + print "$old\t{$m[1]}\t{$m[2]}\n"; } - $counts[$m[1]]++; - } elseif ( $report === '3col' ) { - print "$old\t{$m[1]}
[MediaWiki-commits] [Gerrit] mediawiki...namespaceizer[master]: Added conflict and reserved word detection
Tim Starling has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/392364 ) Change subject: Added conflict and reserved word detection .. Added conflict and reserved word detection Detect conflicts due to two classes being renamed to the same thing. Exempt existing class_alias() calls. Detect class names that use PHP reserved words. Change-Id: I91762c902b049fea472a189073acc87ab0ada85f --- M bin/dumpCoreAliases.php M src/CoreAliases.php 2 files changed, 241 insertions(+), 117 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/tools/namespaceizer refs/changes/64/392364/1 diff --git a/bin/dumpCoreAliases.php b/bin/dumpCoreAliases.php index e115c2b..b270f53 100644 --- a/bin/dumpCoreAliases.php +++ b/bin/dumpCoreAliases.php @@ -9,76 +9,94 @@ require __DIR__ . '/../vendor/autoload.php'; -$self = array_shift( $argv ); - -if ( !count( $argv ) ) { - echo "Usage: $self \n"; - exit( 1 ); +function warnCallback( $msg ) { + fwrite( STDERR, "WARNING: $msg\n" ); } -if ( $argv[0] === '--counts' ) { - $report = 'counts'; - array_shift( $argv ); -} elseif ( $argv[0] === '--3col' ) { - $report = '3col'; - array_shift( $argv ); -} elseif ( $argv[0] === '--classes' ) { - $report = 'classes'; - array_shift( $argv ); -} else { - $report = 'php'; +function errorCallback( $msg ) { + fwrite( STDERR, "ERROR: $msg\n" ); } -if ( !count( $argv ) ) { - echo "Usage: $self \n"; - exit( 1 ); -} +function dumpCoreAliases() { + global $argv; -$file = $argv[0]; + $self = array_shift( $argv ); -$autoload = AutoloadLoader::getAutoloadClasses( $file ); -if ( $autoload === false ) { - echo "Unable to open autoload file $file\n"; - exit( 1 ); -} + if ( !count( $argv ) ) { + echo "Usage: $self \n"; + exit( 1 ); + } -$ca = new CoreAliases( $autoload ); -$aliases = $ca->getAliases(); - -asort( $aliases ); - -$counts = []; -if ( $report === 'php' ) { - print " $new ) { - if ( $report === 'classes' ) { - print "$old\t$new\n"; - } elseif ( $report === 'php' ) { - print "\t'" . - strtr( $old, [ "\\" => "", "'" => "\\'" ] ) . - "' => '" . - strtr( $new, [ "\\" => "", "'" => "\\'" ] ) . - "',\n"; + if ( $argv[0] === '--counts' ) { + $report = 'counts'; + array_shift( $argv ); + } elseif ( $argv[0] === '--3col' ) { + $report = '3col'; + array_shift( $argv ); + } elseif ( $argv[0] === '--classes' ) { + $report = 'classes'; + array_shift( $argv ); } else { - if ( preg_match( '/(.*)([^]*)$/', $new, $m ) ) { - if ( $report === 'counts' ) { - if ( !isset( $counts[$m[1]] ) ) { - $counts[$m[1]] = 0; + $report = 'php'; + } + + if ( !count( $argv ) ) { + echo "Usage: $self \n"; + exit( 1 ); + } + + $file = $argv[0]; + + $autoload = AutoloadLoader::getAutoloadClasses( $file ); + if ( $autoload === false ) { + echo "Unable to open autoload file $file\n"; + exit( 1 ); + } + + $ca = new CoreAliases( $autoload, 'errorCallback', 'warnCallback' ); + $aliases = $ca->getAliases(); + + if ( $aliases === false ) { + exit( 1 ); + } + + asort( $aliases ); + + $counts = []; + if ( $report === 'php' ) { + print " $new ) { + if ( $report === 'classes' ) { + print "$old\t$new\n"; + } elseif ( $report === 'php' ) { + print "\t'" . + strtr( $old, [ "\\" => "", "'" => "\\'" ] ) . + "' => '" . + strtr( $new, [ "\\" => "", "'" => "\\'" ] ) . + "',\n"; + } else { + if ( preg_match( '/(.*)([^]*)$/', $new, $m ) ) { + if ( $report === 'counts' ) { + if ( !isset( $counts[$m[1]] ) ) { + $counts[$m[1]] = 0; + } + $counts[$m[1]]++; + } elseif ( $report === '3col' ) { + print "$old\t{$m[1]}\t{$m[2]}\n"; } - $counts[$m[1]]++; - } elseif ( $report === '3col' ) { - print "$old\t{$m[1]}\t