EBernhardson has uploaded a new change for review. https://gerrit.wikimedia.org/r/316573
Change subject: Update phan to use a config file ...................................................................... Update phan to use a config file The latest versions of phan support configuration via a config file that provides the files/directories to inspect, along with various settings that effect what issues are raised. This also seems to now be detecting a few more type mis-matches. This is prep work for moving the running of phan into CI. Change-Id: I6a0a949d5238a2d539d689336a61b4c65afb317b --- A .phan/config.php A .phan/stubs/phan.stubs.php M includes/CompletionSuggester.php M includes/DataSender.php M includes/Dump.php M includes/Search/SearchContext.php M maintenance/indexNamespaces.php M maintenance/runSearch.php M scripts/postprocess-phan.php M scripts/run-phan.sh 10 files changed, 148 insertions(+), 36 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CirrusSearch refs/changes/73/316573/1 diff --git a/.phan/config.php b/.phan/config.php new file mode 100644 index 0000000..6a2019d --- /dev/null +++ b/.phan/config.php @@ -0,0 +1,116 @@ +<?php + +$directoryList = []; +$excludeAnalysisDirectoryList = []; + +$IP = getenv( 'MW_INSTALL_PATH' ); +if ( $IP === false ) { + $IP = realpath( __DIR__ . '/../../..' ); +} + +$cirrusDirs = ['includes', 'maintenance', 'profiles', '.phan/stubs']; +$otherDirs = [ + 'includes', 'vendor', 'maintenance', 'languages', + 'extensions/Elastica', 'extensions/GeoData', 'extensions/BetaFeatures', + 'extensions/CirrusSearch/vendor', +]; +foreach ( $cirrusDirs as $dir ) { + $directoryList[] = "$IP/extensions/CirrusSearch/$dir"; +} +foreach ( $otherDirs as $dir ) { + $fullpath = "$IP/$dir"; + $directoryList[] = $fullpath; + $excludeAnalysisDirectoryList[] = $fullpath; +} + +/** + * This configuration will be read and overlaid on top of the + * default configuration. Command line arguments will be applied + * after this file is read. + * + * @see src/Phan/Config.php + * See Config for all configurable options. + */ +return [ + // A list of directories that should be parsed for class and + // method information. After excluding the directories + // defined in exclude_analysis_directory_list, the remaining + // files will be statically analyzed for errors. + // + // Thus, both first-party and third-party code being used by + // your application should be included in this list. + 'directory_list' => $directoryList, + + // A directory list that defines files that will be excluded + // from static analysis, but whose class and method + // information should be included. + // + // Generally, you'll want to include the directories for + // third-party code (such as "vendor/") in this list. + // + // n.b.: If you'd like to parse but not analyze 3rd + // party code, directories containing that code + // should be added to the `directory_list` as + // to `excluce_analysis_directory_list`. + "exclude_analysis_directory_list" => $excludeAnalysisDirectoryList, + + // Backwards Compatibility Checking. This is slow + // and expensive, but you should consider running + // it before upgrading your version of PHP to a + // new version that has backward compatibility + // breaks. + 'backward_compatibility_checks' => false, + + // Run a quick version of checks that takes less + // time at the cost of not running as thorough + // an analysis. You should consider setting this + // to true only when you wish you had more issues + // to fix in your code base. + 'quick_mode' => false, + + // If enabled, check all methods that override a + // parent method to make sure its signature is + // compatible with the parent's. This check + // can add quite a bit of time to the analysis. + 'analyze_signature_compatibility' => true, + + // The minimum severity level to report on. This can be + // set to Issue::SEVERITY_LOW, Issue::SEVERITY_NORMAL or + // Issue::SEVERITY_CRITICAL. Setting it to only + // critical issues is a good place to start on a big + // sloppy mature code base. + 'minimum_severity' => 0, + + // If true, missing properties will be created when + // they are first seen. If false, we'll report an + // error message if there is an attempt to write + // to a class property that wasn't explicitly + // defined. + 'allow_missing_properties' => false, + + // Allow null to be cast as any type and for any + // type to be cast to null. Setting this to false + // will cut down on false positives. + 'null_casts_as_any_type' => false, + + // If enabled, scalars (int, float, bool, string, null) + // are treated as if they can cast to each other. + 'scalar_implicit_cast' => false, + + // If true, seemingly undeclared variables in the global + // scope will be ignored. This is useful for projects + // with complicated cross-file globals that you have no + // hope of fixing. + 'ignore_undeclared_variables_in_global_scope' => true, + + // Add any issue types (such as 'PhanUndeclaredMethod') + // to this black-list to inhibit them from being reported. + 'suppress_issue_types' => [ + ], + + // If empty, no filter against issues types will be applied. + // If this white-list is non-empty, only issues within the list + // will be emitted by Phan. + 'whitelist_issue_types' => [ + ], +]; diff --git a/.phan/stubs/phan.stubs.php b/.phan/stubs/phan.stubs.php new file mode 100644 index 0000000..8088c1d --- /dev/null +++ b/.phan/stubs/phan.stubs.php @@ -0,0 +1,14 @@ +<?php + +/** + * Stub methods from hhvm that phan doesn't know about + */ + +/** + * @param string $poolName + * @param string|null $url + * @return resource|false + */ +function curl_init_pooled( $poolName, $url = null ) { + return false; +} diff --git a/includes/CompletionSuggester.php b/includes/CompletionSuggester.php index ff385f1..a02e3d9 100644 --- a/includes/CompletionSuggester.php +++ b/includes/CompletionSuggester.php @@ -523,7 +523,7 @@ LoggerFactory::getInstance( 'CirrusSearch' )->warning( 'Unable to fetch redirects for suggestion {query} with results {ids} : {error}', [ 'query' => $this->term, - 'ids' => serialize( $missingText ), + 'ids' => serialize( $missingTextDocIds ), 'error' => $redirResponse->getError() ] ); } } catch ( \Elastica\Exception\ExceptionInterface $e ) { @@ -532,7 +532,7 @@ 'Unable to fetch redirects for suggestion {query} with results {ids}. {error_type}: {error_reason}', [ 'query' => $this->term, - 'ids' => serialize( $missingText ), + 'ids' => serialize( $missingTextDocIds ), 'error_type' => $error['type'], 'error_reason' => $error['reason'], ] diff --git a/includes/DataSender.php b/includes/DataSender.php index 15fb2dc..caedd0b 100644 --- a/includes/DataSender.php +++ b/includes/DataSender.php @@ -144,7 +144,9 @@ $ids = new \Elastica\Query\Ids( null, $indexes ); $ids->addId( self::ALL_INDEXES_FROZEN_NAME ); - $resp = $this->connection->getFrozenIndexNameType()->search( $ids ); + $resp = $this->connection->getFrozenIndexNameType()->search( + \Elastica\Query::create( $ids ) + ); if ( $resp->count() === 0 ) { return true; diff --git a/includes/Dump.php b/includes/Dump.php index 2c2a071..f316003 100644 --- a/includes/Dump.php +++ b/includes/Dump.php @@ -35,6 +35,7 @@ $config = MediaWikiServices::getInstance() ->getConfigFactory() ->makeConfig( 'CirrusSearch' ); + /** @suppress PhanTypeMismatchArgument $config is actually a SearchConfig */ $conn = new Connection( $config ); $searcher = new Searcher( $conn, 0, 0, null, [], $this->getUser() ); diff --git a/includes/Search/SearchContext.php b/includes/Search/SearchContext.php index ecd05bd..14da0e5 100644 --- a/includes/Search/SearchContext.php +++ b/includes/Search/SearchContext.php @@ -175,6 +175,7 @@ */ public function __construct( SearchConfig $config, array $namespaces = null ) { $this->config = $config; + /** @suppress PhanDeprecatedProperty */ $this->boostLinks = $this->config->get( 'CirrusSearchBoostLinks' ); $this->namespaces = $namespaces; $this->rescoreProfile = $this->config->get( 'CirrusSearchRescoreProfile' ); @@ -235,6 +236,7 @@ * @param bool $boostLinks Deactivate IncomingLinksFunctionScoreBuilder if present in the rescore profile */ public function setBoostLinks( $boostLinks ) { + /** @suppress PhanDeprecatedProperty */ $this->boostLinks = $boostLinks; } diff --git a/maintenance/indexNamespaces.php b/maintenance/indexNamespaces.php index 3fcb70e..716ed49 100644 --- a/maintenance/indexNamespaces.php +++ b/maintenance/indexNamespaces.php @@ -39,7 +39,7 @@ $type = $this->getConnection()->getNamespaceType( $this->getSearchConfig()->get( SearchConfig::INDEX_BASE_NAME ) ); $this->outputIndented( "Deleting namespaces..." ); - $type->deleteByQuery( new MatchAll() ); + $type->deleteByQuery( \Elastica\Query::create( new MatchAll() ) ); $this->output( "done\n" ); $this->outputIndented( "Indexing namespaces..." ); diff --git a/maintenance/runSearch.php b/maintenance/runSearch.php index 41f6eb0..36f7ffc 100644 --- a/maintenance/runSearch.php +++ b/maintenance/runSearch.php @@ -109,6 +109,7 @@ $data['totalHits'] = $value->getTotalHits(); $data['rows'] = []; $result = $value->next(); + $terms = explode( ' ', $query ); while ( $result ) { $data['rows'][] = [ // use getDocId() rather than asking the title to allow this script @@ -117,7 +118,7 @@ 'title' => $result->getTitle()->getPrefixedText(), 'score' => $result->getScore(), 'snippets' => [ - 'text' => $result->getTextSnippet( $query ), + 'text' => $result->getTextSnippet( [] ), 'title' => $result->getTitleSnippet(), 'redirect' => $result->getRedirectSnippet(), 'section' => $result->getSectionSnippet(), diff --git a/scripts/postprocess-phan.php b/scripts/postprocess-phan.php index 6512be0..73c364b 100644 --- a/scripts/postprocess-phan.php +++ b/scripts/postprocess-phan.php @@ -1,6 +1,7 @@ <?php $results = file( "php://stdin" ); +$errors = []; foreach ( $results as $error ) { if ( !preg_match( '/^(.*):(\d+) (Phan\w+) (.*)$/', $error, $matches ) ) { echo "Failed to parse line: $error\n"; diff --git a/scripts/run-phan.sh b/scripts/run-phan.sh index 5a0f44b..d186935 100755 --- a/scripts/run-phan.sh +++ b/scripts/run-phan.sh @@ -2,23 +2,12 @@ # Some systems, like mediawiki-vagrant, don't have realpath if ! which realpath > /dev/null; then - realpath() { - php -r "echo realpath('$*');" - } + realpath() { + php -r "echo realpath('$*');" + } fi MW_PREFIX=$(realpath "${MW_PREFIX:-$(dirname "$0")/../../..}") -CIRRUS="extensions/CirrusSearch/includes/ extensions/CirrusSearch/maintenance/ extensions/CirrusSearch/profiles" -DEPS="extensions/Elastica/ extensions/GeoData extensions/BetaFeatures includes vendor/ maintenance/ languages/ extensions/CirrusSearch/vendor" - -set -e - -if [ ! -f "$MW_PREFIX/includes/MediaWiki.php" ]; then - echo "Could not find MediaWiki installation at $MW_PREFIX" - echo "Please specify with MW_PREFIX environment variable" - echo - exit 1 -fi if ! which docker > /dev/null; then echo "Docker not installed. Press any key to install docker or Ctrl-C to quit" @@ -47,28 +36,14 @@ rm -rf /tmp/docker-phan.$$ fi -for i in $CIRRUS; do - ALL_DIRS="$ALL_DIRS $MW_PREFIX/$i" -done -for i in $DEPS; do - SKIP_ANALYSIS="$SKIP_ANALYSIS,/mnt/src/$i" - ALL_DIRS="$ALL_DIRS $MW_PREFIX/$i" -done -# Strip leading comma -SKIP_ANALYSIS="${SKIP_ANALYSIS:1}" - -PHAN_IN=$MW_PREFIX/phan.in.$$ SED_PATTERN=$(echo $MW_PREFIX | sed 's/[\/&]/\\&/g') -find $ALL_DIRS -iname '*.php' | sed "s/${SED_PATTERN}/\/mnt\/src/" > $PHAN_IN -echo "/mnt/src/extensions/CirrusSearch/scripts/phan.stubs.php" >> $PHAN_IN docker run \ --volume="$MW_PREFIX:/mnt/src" \ --rm \ --user "$(id -u):$(id -g)" \ - cloudflare/phan:latest \ - --file-list "/mnt/src/phan.in.$$" \ - --exclude-directory-list "$SKIP_ANALYSIS" \ + cloudflare/phan:edge \ + --project-root-directory /mnt/src/extensions/CirrusSearch \ --output "php://stdout" \ | sed "s/\/mnt\/src/$SED_PATTERN/" \ | php $(dirname $0)/postprocess-phan.php \ @@ -82,6 +57,6 @@ fi cat /tmp/phan.out -rm "$PHAN_IN" /tmp/phan.out +rm /tmp/phan.out exit $RETVAL -- To view, visit https://gerrit.wikimedia.org/r/316573 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I6a0a949d5238a2d539d689336a61b4c65afb317b Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/CirrusSearch Gerrit-Branch: master Gerrit-Owner: EBernhardson <ebernhard...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits