[MediaWiki-commits] [Gerrit] mediawiki...CiteThisPage[master]: Add phan configuration for static analysis
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/400185 ) Change subject: Add phan configuration for static analysis .. Add phan configuration for static analysis Bug: T179554 Change-Id: I9f099e07e5873c1125b4b75839f0089f59b4fa8b --- M .gitignore M SpecialCiteThisPage.php A tests/phan/config.php 3 files changed, 309 insertions(+), 3 deletions(-) Approvals: D3r1ck01: Looks good to me, but someone else must approve Florianschmidtwelzow: Looks good to me, but someone else must approve Legoktm: Looks good to me, approved jenkins-bot: Verified diff --git a/.gitignore b/.gitignore index 4489bce..e9de19d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ /node_modules/ /vendor/ +/tests/phan/issues /composer.lock # Editors diff --git a/SpecialCiteThisPage.php b/SpecialCiteThisPage.php index 9a17686..6633380 100644 --- a/SpecialCiteThisPage.php +++ b/SpecialCiteThisPage.php @@ -55,6 +55,7 @@ if ( strlen( $data['page'] ) ) { $this->title = Title::newFromText( $data['page'] ); } + return true; } /** @@ -72,9 +73,10 @@ return []; } // Autocomplete subpage the same as a normal search - $prefixSearcher = new StringPrefixSearch; - $result = $prefixSearcher->search( $search, $limit, [], $offset ); - return $result; + $result = SearchEngine::completionSearch( $search ); + return array_map( function ( $sub ) { + return $sub->getSuggestedTitle(); + }, $result->getSuggestions() ); } protected function getGroupName() { diff --git a/tests/phan/config.php b/tests/phan/config.php new file mode 100644 index 000..2264c5d --- /dev/null +++ b/tests/phan/config.php @@ -0,0 +1,303 @@ + [ + ], + + /** +* 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' => [ + '.', + './../../includes', + './../../languages', + './../../maintenance', + './../../vendor', + ], + + /** +* A file list that defines files that will be excluded +* from parsing and analysis and will not be read at all. +* +* This is useful for excluding hopelessly unanalyzable +* files that can't be removed for whatever reason. +*/ + 'exclude_file_list' => [ + ], + + /** +* A list of directories holding code that we want +* to parse, but not analyze. Also works for individual +* files. +*/ + "exclude_analysis_directory_list" => [ + './../../includes', + './../../languages', + './../../maintenance', + './../../vendor', + ], + + /** +* 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, + + /** +* A set of fully qualified class-names for which +* a call to parent::__construct() is required +*/ + 'parent_constructor_required' => [ + ], + + /** +* 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. +* +* In quick-mode the scanner doesn't rescan a function +* or a method's code block every time a call is seen. +* This means that the problem here won't be detected: +* +* ```php +* false, + + /** +* By default, Phan will not analyze all node types +* in order to save time. If this config is set to true, +* Phan will dig deeper into the AST tree and do an +* analysis on all nodes, possibly finding more issues. +* +* See \Phan\Analysis::shouldVisit for the set of skipped +* nodes. +*/ + 'should_visit_all_nodes' => true, + + /** +* 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
[MediaWiki-commits] [Gerrit] mediawiki...CiteThisPage[master]: Add phan configuration for static analysis
Phantom42 has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/400185 ) Change subject: Add phan configuration for static analysis .. Add phan configuration for static analysis Bug: T179554 Change-Id: I9f099e07e5873c1125b4b75839f0089f59b4fa8b --- M .gitignore M SpecialCiteThisPage.php A tests/phan/config.php 3 files changed, 310 insertions(+), 3 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CiteThisPage refs/changes/85/400185/1 diff --git a/.gitignore b/.gitignore index 4489bce..e9de19d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ /node_modules/ /vendor/ +/tests/phan/issues /composer.lock # Editors diff --git a/SpecialCiteThisPage.php b/SpecialCiteThisPage.php index 9a17686..3e770e8 100644 --- a/SpecialCiteThisPage.php +++ b/SpecialCiteThisPage.php @@ -55,6 +55,7 @@ if ( strlen( $data['page'] ) ) { $this->title = Title::newFromText( $data['page'] ); } + return true; } /** @@ -71,10 +72,12 @@ // No prefix suggestion in special and media namespace return []; } + // Autocomplete subpage the same as a normal search - $prefixSearcher = new StringPrefixSearch; - $result = $prefixSearcher->search( $search, $limit, [], $offset ); - return $result; + $result = SearchEngine::completionSearch( $search ); + return array_map( function ( $sub ) { + return $sub->getSuggestedTitle(); + }, $result->getSuggestions() ); } protected function getGroupName() { diff --git a/tests/phan/config.php b/tests/phan/config.php new file mode 100644 index 000..2264c5d --- /dev/null +++ b/tests/phan/config.php @@ -0,0 +1,303 @@ + [ + ], + + /** +* 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' => [ + '.', + './../../includes', + './../../languages', + './../../maintenance', + './../../vendor', + ], + + /** +* A file list that defines files that will be excluded +* from parsing and analysis and will not be read at all. +* +* This is useful for excluding hopelessly unanalyzable +* files that can't be removed for whatever reason. +*/ + 'exclude_file_list' => [ + ], + + /** +* A list of directories holding code that we want +* to parse, but not analyze. Also works for individual +* files. +*/ + "exclude_analysis_directory_list" => [ + './../../includes', + './../../languages', + './../../maintenance', + './../../vendor', + ], + + /** +* 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, + + /** +* A set of fully qualified class-names for which +* a call to parent::__construct() is required +*/ + 'parent_constructor_required' => [ + ], + + /** +* 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. +* +* In quick-mode the scanner doesn't rescan a function +* or a method's code block every time a call is seen. +* This means that the problem here won't be detected: +* +* ```php +* false, + + /** +* By default, Phan will not analyze all node types +* in order to save time. If this config is set to true, +* Phan will dig deeper into the AST tree and do an +* analysis on all nodes, possibly finding more issues. +* +* See \Phan\Analysis::shouldVisit for the set of skipped +* nodes. +*/ + 'should_visit_all_nodes' => true, + + /** +* 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