jenkins-bot has submitted this change and it was merged. Change subject: Makefile command to run phpstorm inspections ......................................................................
Makefile command to run phpstorm inspections Includes an analyze-phpstorm.xml file which contains the differences between the default phpstorm set of inspections and the ones we want to run. Disabled illegal array key type inspection - MultiDimArray uses this Disabled include inspection - we dont generally use includes except for templates which fail this inspection. Disabled undefined method inspection - We want to enable this, but there are a few files that need to be gone through and annotated with classes to clean up current hits Disabled unused parameter inspection - In several places we have function parameters defined by the interface but unneccessary for that specific implementation. Disabled spell checking - it doesn't recognize a whole host of words like wikitext, parsoid, etc. Change-Id: Ic92b33b8d0f3e468e205be866cd60a97b992f307 --- M Makefile M includes/Block/Block.php M includes/Formatter/CheckUser.php M includes/Model/Definition.php A scripts/analyze-phpstorm.sh A scripts/analyze-phpstorm.xml M scripts/pre-commit 7 files changed, 96 insertions(+), 3 deletions(-) Approvals: Bsitu: Looks good to me, approved jenkins-bot: Verified diff --git a/Makefile b/Makefile index a721ffe..48a5ca9 100644 --- a/Makefile +++ b/Makefile @@ -60,14 +60,19 @@ ### # Static analysis ### -install-analyze: +install-analyze-hhvm: wget -O scripts/hhvm-wrapper.phar https://phar.phpunit.de/hhvm-wrapper.phar @which hhvm >/dev/null || which ${HHVM_HOME} >/dev/null || (echo Could not locate hhvm && false) -analyze: +analyze-hhvm: @test -f scripts/hhvm-wrapper.phar || (echo Run \`make install-analyze\` first && false) php scripts/hhvm-wrapper.phar analyze ${ANALYZE} ${ANALYZE_EXTRA} +analyze-phpstorm: + @scripts/analyze-phpstorm.sh + +analyze: analyze-hhvm analyze-phpstorm + ### # Update this repository ### diff --git a/includes/Block/Block.php b/includes/Block/Block.php index 868757e..a407ba1 100644 --- a/includes/Block/Block.php +++ b/includes/Block/Block.php @@ -6,7 +6,6 @@ use Flow\Model\Workflow; use Flow\NotificationController; use Flow\Data\ManagerGroup; -use Flow\Exception\DataModelException; use Flow\SpamFilter\Controller as SpamFilterController; use Flow\Templating; use Flow\Model\AbstractRevision; diff --git a/includes/Formatter/CheckUser.php b/includes/Formatter/CheckUser.php index 8010e12..0b3da8d 100644 --- a/includes/Formatter/CheckUser.php +++ b/includes/Formatter/CheckUser.php @@ -27,6 +27,7 @@ $data = explode( ',', $row->cuc_comment ); $post = null; switch( count( $data ) ) { + /** @noinspection PhpMissingBreakStatementInspection */ case 3: $post = UUID::create( $data[2] ); // fall-through to 2 parameter case diff --git a/includes/Model/Definition.php b/includes/Model/Definition.php index 0bb778a..853eda7 100644 --- a/includes/Model/Definition.php +++ b/includes/Model/Definition.php @@ -121,6 +121,8 @@ } /** + * @param string $key + * @param mixed $default * @return mixed */ public function getOption( $key, $default = null ) { diff --git a/scripts/analyze-phpstorm.sh b/scripts/analyze-phpstorm.sh new file mode 100755 index 0000000..4dc81a4 --- /dev/null +++ b/scripts/analyze-phpstorm.sh @@ -0,0 +1,61 @@ +#!/bin/sh + +# the realpath executable isn't guaranteed, so define one. +# FIXME: path with ' in it will break +realpath() { + php -r "echo realpath('$1'), \"\\n\";" +} + +if [ ! -x "$(which xmllint)" ]; then + echo xmllint is required to filter results + exit 1 +fi + +# specifying directly kinda sucks +if [ ! -d "$PHPSTORM_BIN_HOME" ]; then + PHPSTORM_BIN_HOME="$(realpath ~/PhpStorm-133.803/bin)" +fi + +if [ ! -x "$PHPSTORM_BIN_HOME/inspect.sh" ]; then + echo Could not locate PhpStorm. + echo Set PHPSTORM_BIN_HOME to the bin dir inside the uncompressed phpstorm executable + echo If you need a license check https://office.wikimedia.org/wiki/JetBrains + exit 1 +fi + +# all paths must be absolute +EXTENSION="$(dirname $(dirname $(realpath $0)))" + +# Path to the main project +MEDIAWIKI="$(realpath $EXTENSION/../..)" + +# Output path +OUTPUT="/tmp/phpstorm-inspect.$$" + +$PHPSTORM_BIN_HOME/inspect.sh $MEDIAWIKI $EXTENSION/scripts/analyze-phpstorm.xml $OUTPUT -d $EXTENSION/includes -v2 + +EXIT=0 +if [ $(find $OUTPUT | wc -l) -gt 1 ]; then + # @todo format the xml + for i in $OUTPUT/*; do + # Filter errors in api, its currently just a stub + xmllint --xpath "//problem[not(file[contains(text(), '/Flow/includes/api/')])]" "$i" 2>/dev/null > "$OUTPUT/tmp.out" + if [ -s "$OUTPUT/tmp.out" ]; then + EXIT=1 + echo $i + echo + cat "$OUTPUT/tmp.out" + echo + echo + fi + done + test -f "$OUTPUT/tmp.out" && rm "$OUTPUT/tmp.out" +fi + +if [ $EXIT -eq 0 ]; then + rm -rf $OUTPUT +else + echo XML output stored in $OUTPUT +fi + +exit $EXIT diff --git a/scripts/analyze-phpstorm.xml b/scripts/analyze-phpstorm.xml new file mode 100644 index 0000000..f1295f0 --- /dev/null +++ b/scripts/analyze-phpstorm.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="UTF-8"?> +<inspections version="1.0" is_locked="false"> + <option name="myName" value="Project Default" /> + <option name="myLocal" value="false" /> + <inspection_tool class="InconsistentLineSeparators" enabled="true" level="WARNING" enabled_by_default="true" /> + <inspection_tool class="PhpAssignmentInConditionInspection" enabled="true" level="WARNING" enabled_by_default="true" /> + <inspection_tool class="PhpDivisionByZeroInspection" enabled="true" level="WARNING" enabled_by_default="true" /> + <inspection_tool class="PhpIllegalArrayKeyTypeInspection" enabled="false" level="WARNING" enabled_by_default="false" /> + <inspection_tool class="PhpIncludeInspection" enabled="false" level="WARNING" enabled_by_default="false" /> + <inspection_tool class="PhpUndefinedMethodInspection" enabled="false" level="WARNING" enabled_by_default="false" /> + <inspection_tool class="PhpUnusedParameterInspection" enabled="false" level="WARNING" enabled_by_default="false"> + <option name="DONT_REPORT_PARAMETERS_COUNT_ACCESS" value="true" /> + </inspection_tool> + <inspection_tool class="PhpUsageOfSilenceOperatorInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true" /> + <inspection_tool class="SpellCheckingInspection" enabled="false" level="TYPO" enabled_by_default="false"> + <option name="processCode" value="true" /> + <option name="processLiterals" value="true" /> + <option name="processComments" value="true" /> + </inspection_tool> +</inspections> + diff --git a/scripts/pre-commit b/scripts/pre-commit index 1d53688..b343751 100755 --- a/scripts/pre-commit +++ b/scripts/pre-commit @@ -5,6 +5,10 @@ # Code from https://gist.github.com/holysugar/1318698 , simpler than # http://stackoverflow.com/a/6262715/451712 +function realpath() { + php -r "echo realpath('$1'), \"\\n\";" +} + function whitespace_error() { echo "'$1' has trailing whitespace\n" >&2 } -- To view, visit https://gerrit.wikimedia.org/r/114701 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ic92b33b8d0f3e468e205be866cd60a97b992f307 Gerrit-PatchSet: 6 Gerrit-Project: mediawiki/extensions/Flow Gerrit-Branch: master Gerrit-Owner: EBernhardson <ebernhard...@wikimedia.org> Gerrit-Reviewer: Bsitu <bs...@wikimedia.org> Gerrit-Reviewer: EBernhardson <ebernhard...@wikimedia.org> Gerrit-Reviewer: Matthias Mullie <mmul...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits