Libraryupgrader has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/375845 )
Change subject: build: Updating mediawiki/mediawiki-codesniffer to 0.12.0 ...................................................................... build: Updating mediawiki/mediawiki-codesniffer to 0.12.0 The following sniffs are failing and were disabled: * MediaWiki.Commenting.FunctionComment.MissingDocumentationPublic * MediaWiki.Commenting.FunctionComment.MissingParamComment * MediaWiki.ControlStructures.AssignmentInControlStructures.AssignmentInControlStructures Also added "composer fix" command. Change-Id: I1be473cf82364de6151a2bc9c71405b74a8d4b83 --- M composer.json M phpcs.xml M src/Converter.php M src/Converter/Operator.php M src/Evaluator.php M src/Range.php M tests/EvaluatorTest.php 7 files changed, 101 insertions(+), 94 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/CLDRPluralRuleParser refs/changes/45/375845/1 diff --git a/composer.json b/composer.json index 989626c..d92d366 100644 --- a/composer.json +++ b/composer.json @@ -29,13 +29,16 @@ "require-dev": { "jakub-onderka/php-parallel-lint": "^0.9.0.0", "phpunit/phpunit": "^4.7.7.0", - "mediawiki/mediawiki-codesniffer": "0.4.0" + "mediawiki/mediawiki-codesniffer": "0.12.0" }, "scripts": { "test": [ "parallel-lint . --exclude vendor", "phpunit $PHPUNIT_ARGS", "phpcs -p" + ], + "fix": [ + "phpcbf" ] } } diff --git a/phpcs.xml b/phpcs.xml index a55f518..37c6130 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -1,6 +1,10 @@ <?xml version="1.0"?> <ruleset> - <rule ref="vendor/mediawiki/mediawiki-codesniffer/MediaWiki"/> + <rule ref="./vendor/mediawiki/mediawiki-codesniffer/MediaWiki"> + <exclude name="MediaWiki.Commenting.FunctionComment.MissingDocumentationPublic" /> + <exclude name="MediaWiki.Commenting.FunctionComment.MissingParamComment" /> + <exclude name="MediaWiki.ControlStructures.AssignmentInControlStructures.AssignmentInControlStructures" /> + </rule> <file>.</file> <arg name="encoding" value="UTF-8"/> diff --git a/src/Converter.php b/src/Converter.php index 4bb87a2..f6087ca 100644 --- a/src/Converter.php +++ b/src/Converter.php @@ -43,21 +43,21 @@ * * @var array */ - public $operators = array(); + public $operators = []; /** * The operand stack * * @var array */ - public $operands = array(); + public $operands = []; /** * Precedence levels. Note that there's no need to worry about associativity * for the level 4 operators, since they return boolean and don't accept * boolean inputs. */ - private static $precedence = array( + private static $precedence = [ 'or' => 2, 'and' => 3, 'is' => 4, @@ -69,7 +69,7 @@ 'mod' => 5, ',' => 6, '..' => 7, - ); + ]; /** * A character list defining whitespace, for use in strspn() etc. diff --git a/src/Converter/Operator.php b/src/Converter/Operator.php index 3a23d39..58b515b 100644 --- a/src/Converter/Operator.php +++ b/src/Converter/Operator.php @@ -29,7 +29,7 @@ * * @var array */ - private static $opTypes = array( + private static $opTypes = [ 'or' => 'bbb', 'and' => 'bbb', 'is' => 'nnb', @@ -41,27 +41,27 @@ 'mod' => 'nnn', ',' => 'rrr', '..' => 'nnr', - ); + ]; /** * Map converting from the abbrevation to the full form. * * @var array */ - private static $typeSpecMap = array( + private static $typeSpecMap = [ 'b' => 'boolean', 'n' => 'number', 'r' => 'range', - ); + ]; /** * Map for converting the new operators introduced in Rev 33 to the old forms */ - private static $aliasMap = array( + private static $aliasMap = [ '%' => 'mod', '!=' => 'not-in', '=' => 'in' - ); + ]; /** * Initialize a new instance of a CLDRPluralRuleConverterOperator object diff --git a/src/Evaluator.php b/src/Evaluator.php index 695a92d..937ad98 100644 --- a/src/Evaluator.php +++ b/src/Evaluator.php @@ -64,32 +64,32 @@ return count( $rules ); } if ( !isset( $m[3] ) ) { - $operandSymbols = array( + $operandSymbols = [ 'n' => intval( $m[1] ), 'i' => intval( $m[1] ), 'v' => 0, 'w' => 0, 'f' => 0, 't' => 0 - ); + ]; } else { $absValStr = $m[1]; $intStr = $m[2]; $fracStr = $m[3]; - $operandSymbols = array( + $operandSymbols = [ 'n' => floatval( $absValStr ), 'i' => intval( $intStr ), 'v' => strlen( $fracStr ), 'w' => strlen( rtrim( $fracStr, '0' ) ), 'f' => intval( $fracStr ), 't' => intval( rtrim( $fracStr, '0' ) ), - ); + ]; } // The compiled form is RPN, with tokens strictly delimited by // spaces, so this is a simple RPN evaluator. foreach ( $rules as $i => $rule ) { - $stack = array(); + $stack = []; $zero = ord( '0' ); $nine = ord( '9' ); @@ -125,7 +125,7 @@ * @return mixed The operation result */ private static function doOperation( $token, $left, $right ) { - if ( in_array( $token, array( 'in', 'not-in', 'within', 'not-within' ) ) ) { + if ( in_array( $token, [ 'in', 'not-in', 'within', 'not-within' ] ) ) { if ( !$right instanceof Range ) { $right = new Range( $right ); } diff --git a/src/Range.php b/src/Range.php index be18789..40ebe1b 100644 --- a/src/Range.php +++ b/src/Range.php @@ -17,7 +17,7 @@ * * @var array */ - public $parts = array(); + public $parts = []; /** * Initialize a new instance of Range @@ -29,7 +29,7 @@ if ( $end === false ) { $this->parts[] = $start; } else { - $this->parts[] = array( $start, $end ); + $this->parts[] = [ $start, $end ]; } } diff --git a/tests/EvaluatorTest.php b/tests/EvaluatorTest.php index 8433fb3..cc44f37 100644 --- a/tests/EvaluatorTest.php +++ b/tests/EvaluatorTest.php @@ -29,88 +29,88 @@ } function validTestCases() { - $tests = array( + $tests = [ # expected, rule, number, comment - array( 0, 'n is 1', 1, 'integer number and is' ), - array( 0, 'n is 1', "1", 'string integer number and is' ), - array( 0, 'n is 1', 1.0, 'float number and is' ), - array( 0, 'n is 1', "1.0", 'string float number and is' ), - array( 1, 'n is 1', 1.1, 'float number and is' ), - array( 1, 'n is 1', 2, 'float number and is' ), + [ 0, 'n is 1', 1, 'integer number and is' ], + [ 0, 'n is 1', "1", 'string integer number and is' ], + [ 0, 'n is 1', 1.0, 'float number and is' ], + [ 0, 'n is 1', "1.0", 'string float number and is' ], + [ 1, 'n is 1', 1.1, 'float number and is' ], + [ 1, 'n is 1', 2, 'float number and is' ], - array( 0, 'n in 1,3,5', 3, '' ), - array( 1, 'n not in 1,3,5', 5, '' ), + [ 0, 'n in 1,3,5', 3, '' ], + [ 1, 'n not in 1,3,5', 5, '' ], - array( 1, 'n in 1,3,5', 2, '' ), - array( 0, 'n not in 1,3,5', 4, '' ), + [ 1, 'n in 1,3,5', 2, '' ], + [ 0, 'n not in 1,3,5', 4, '' ], - array( 0, 'n in 1..3', 2, '' ), - array( 0, 'n in 1..3', 3, 'in is inclusive' ), - array( 1, 'n in 1..3', 0, '' ), + [ 0, 'n in 1..3', 2, '' ], + [ 0, 'n in 1..3', 3, 'in is inclusive' ], + [ 1, 'n in 1..3', 0, '' ], - array( 1, 'n not in 1..3', 2, '' ), - array( 1, 'n not in 1..3', 3, 'in is inclusive' ), - array( 0, 'n not in 1..3', 0, '' ), + [ 1, 'n not in 1..3', 2, '' ], + [ 1, 'n not in 1..3', 3, 'in is inclusive' ], + [ 0, 'n not in 1..3', 0, '' ], - array( 1, 'n is not 1 and n is not 2 and n is not 3', 1, 'and relation' ), - array( 0, 'n is not 1 and n is not 2 and n is not 4', 3, 'and relation' ), + [ 1, 'n is not 1 and n is not 2 and n is not 3', 1, 'and relation' ], + [ 0, 'n is not 1 and n is not 2 and n is not 4', 3, 'and relation' ], - array( 0, 'n is not 1 or n is 1', 1, 'or relation' ), - array( 1, 'n is 1 or n is 2', 3, 'or relation' ), + [ 0, 'n is not 1 or n is 1', 1, 'or relation' ], + [ 1, 'n is 1 or n is 2', 3, 'or relation' ], - array( 0, 'n is 1', 1, 'extra whitespace' ), + [ 0, 'n is 1', 1, 'extra whitespace' ], - array( 0, 'n mod 3 is 1', 7, 'mod' ), - array( 0, 'n mod 3 is not 1', 4.3, 'mod with floats' ), + [ 0, 'n mod 3 is 1', 7, 'mod' ], + [ 0, 'n mod 3 is not 1', 4.3, 'mod with floats' ], - array( 0, 'n within 1..3', 2, 'within with integer' ), - array( 0, 'n within 1..3', 2.5, 'within with float' ), - array( 0, 'n in 1..3', 2, 'in with integer' ), - array( 1, 'n in 1..3', 2.5, 'in with float' ), + [ 0, 'n within 1..3', 2, 'within with integer' ], + [ 0, 'n within 1..3', 2.5, 'within with float' ], + [ 0, 'n in 1..3', 2, 'in with integer' ], + [ 1, 'n in 1..3', 2.5, 'in with float' ], - array( 0, 'n in 3 or n is 4 and n is 5', 3, 'and binds more tightly than or' ), - array( 1, 'n is 3 or n is 4 and n is 5', 4, 'and binds more tightly than or' ), + [ 0, 'n in 3 or n is 4 and n is 5', 3, 'and binds more tightly than or' ], + [ 1, 'n is 3 or n is 4 and n is 5', 4, 'and binds more tightly than or' ], - array( 0, 'n mod 10 in 3..4,9 and n mod 100 not in 10..19,70..79,90..99', 24, 'breton rule' ), - array( 1, 'n mod 10 in 3..4,9 and n mod 100 not in 10..19,70..79,90..99', 25, 'breton rule' ), + [ 0, 'n mod 10 in 3..4,9 and n mod 100 not in 10..19,70..79,90..99', 24, 'breton rule' ], + [ 1, 'n mod 10 in 3..4,9 and n mod 100 not in 10..19,70..79,90..99', 25, 'breton rule' ], - array( 0, 'n within 0..2 and n is not 2', 0, 'french rule' ), - array( 0, 'n within 0..2 and n is not 2', 1, 'french rule' ), - array( 0, 'n within 0..2 and n is not 2', 1.2, 'french rule' ), - array( 1, 'n within 0..2 and n is not 2', 2, 'french rule' ), + [ 0, 'n within 0..2 and n is not 2', 0, 'french rule' ], + [ 0, 'n within 0..2 and n is not 2', 1, 'french rule' ], + [ 0, 'n within 0..2 and n is not 2', 1.2, 'french rule' ], + [ 1, 'n within 0..2 and n is not 2', 2, 'french rule' ], - array( 1, 'n in 3..10,13..19', 2, 'scottish rule - ranges with comma' ), - array( 0, 'n in 3..10,13..19', 4, 'scottish rule - ranges with comma' ), - array( 1, 'n in 3..10,13..19', 12.999, 'scottish rule - ranges with comma' ), - array( 0, 'n in 3..10,13..19', 13, 'scottish rule - ranges with comma' ), + [ 1, 'n in 3..10,13..19', 2, 'scottish rule - ranges with comma' ], + [ 0, 'n in 3..10,13..19', 4, 'scottish rule - ranges with comma' ], + [ 1, 'n in 3..10,13..19', 12.999, 'scottish rule - ranges with comma' ], + [ 0, 'n in 3..10,13..19', 13, 'scottish rule - ranges with comma' ], - array( 0, '5 mod 3 is n', 2, 'n as result of mod - no need to pass' ), + [ 0, '5 mod 3 is n', 2, 'n as result of mod - no need to pass' ], # Revision 33 new operand examples # expected, rule, number, comment - array( 0, 'i is 1', '1.00', 'new operand i' ), - array( 0, 'v is 2', '1.00', 'new operand v' ), - array( 0, 'w is 0', '1.00', 'new operand w' ), - array( 0, 'f is 0', '1.00', 'new operand f' ), - array( 0, 't is 0', '1.00', 'new operand t' ), + [ 0, 'i is 1', '1.00', 'new operand i' ], + [ 0, 'v is 2', '1.00', 'new operand v' ], + [ 0, 'w is 0', '1.00', 'new operand w' ], + [ 0, 'f is 0', '1.00', 'new operand f' ], + [ 0, 't is 0', '1.00', 'new operand t' ], - array( 0, 'i is 1', '1.30', 'new operand i' ), - array( 0, 'v is 2', '1.30', 'new operand v' ), - array( 0, 'w is 1', '1.30', 'new operand w' ), - array( 0, 'f is 30', '1.30', 'new operand f' ), - array( 0, 't is 3', '1.30', 'new operand t' ), + [ 0, 'i is 1', '1.30', 'new operand i' ], + [ 0, 'v is 2', '1.30', 'new operand v' ], + [ 0, 'w is 1', '1.30', 'new operand w' ], + [ 0, 'f is 30', '1.30', 'new operand f' ], + [ 0, 't is 3', '1.30', 'new operand t' ], - array( 0, 'i is 1', '1.03', 'new operand i' ), - array( 0, 'v is 2', '1.03', 'new operand v' ), - array( 0, 'w is 2', '1.03', 'new operand w' ), - array( 0, 'f is 3', '1.03', 'new operand f' ), - array( 0, 't is 3', '1.03', 'new operand t' ), + [ 0, 'i is 1', '1.03', 'new operand i' ], + [ 0, 'v is 2', '1.03', 'new operand v' ], + [ 0, 'w is 2', '1.03', 'new operand w' ], + [ 0, 'f is 3', '1.03', 'new operand f' ], + [ 0, 't is 3', '1.03', 'new operand t' ], # Revision 33 new operator aliases # expected, rule, number, comment - array( 0, 'n % 3 is 1', 7, 'new % operator' ), - array( 0, 'n = 1,3,5', 3, 'new = operator' ), - array( 1, 'n != 1,3,5', 5, 'new != operator' ), + [ 0, 'n % 3 is 1', 7, 'new % operator' ], + [ 0, 'n = 1,3,5', 3, 'new = operator' ], + [ 1, 'n != 1,3,5', 5, 'new != operator' ], # Revision 33 samples # expected, rule, number, comment @@ -119,15 +119,15 @@ // @codingStandardsIgnoreEnd # Revision 33 some test cases from CLDR - array( 0, 'i = 1 and v = 0 or i = 0 and t = 1', '0.1', 'pt one' ), - array( 0, 'i = 1 and v = 0 or i = 0 and t = 1', '0.01', 'pt one' ), - array( 0, 'i = 1 and v = 0 or i = 0 and t = 1', '0.10', 'pt one' ), - array( 0, 'i = 1 and v = 0 or i = 0 and t = 1', '0.010', 'pt one' ), - array( 0, 'i = 1 and v = 0 or i = 0 and t = 1', '0.100', 'pt one' ), - array( 1, 'i = 1 and v = 0 or i = 0 and t = 1', '0.0', 'pt other' ), - array( 1, 'i = 1 and v = 0 or i = 0 and t = 1', '0.2', 'pt other' ), - array( 1, 'i = 1 and v = 0 or i = 0 and t = 1', '10.0', 'pt other' ), - array( 1, 'i = 1 and v = 0 or i = 0 and t = 1', '100.0', 'pt other' ), + [ 0, 'i = 1 and v = 0 or i = 0 and t = 1', '0.1', 'pt one' ], + [ 0, 'i = 1 and v = 0 or i = 0 and t = 1', '0.01', 'pt one' ], + [ 0, 'i = 1 and v = 0 or i = 0 and t = 1', '0.10', 'pt one' ], + [ 0, 'i = 1 and v = 0 or i = 0 and t = 1', '0.010', 'pt one' ], + [ 0, 'i = 1 and v = 0 or i = 0 and t = 1', '0.100', 'pt one' ], + [ 1, 'i = 1 and v = 0 or i = 0 and t = 1', '0.0', 'pt other' ], + [ 1, 'i = 1 and v = 0 or i = 0 and t = 1', '0.2', 'pt other' ], + [ 1, 'i = 1 and v = 0 or i = 0 and t = 1', '10.0', 'pt other' ], + [ 1, 'i = 1 and v = 0 or i = 0 and t = 1', '100.0', 'pt other' ], // @codingStandardsIgnoreStart Ignore Generic.Files.LineLength.TooLong array( 0, 'v = 0 and i % 10 = 2..4 and i % 100 != 12..14 or f % 10 = 2..4 and f % 100 != 12..14', '2', 'bs few' ), array( 0, 'v = 0 and i % 10 = 2..4 and i % 100 != 12..14 or f % 10 = 2..4 and f % 100 != 12..14', '4', 'bs few' ), @@ -138,17 +138,17 @@ array( 0, 'v = 0 and i % 10 = 2..4 and i % 100 != 12..14 or f % 10 = 2..4 and f % 100 != 12..14', '10.2', 'bs few' ), array( 1, 'v = 0 and i % 10 = 2..4 and i % 100 != 12..14 or f % 10 = 2..4 and f % 100 != 12..14', '10.0', 'bs other' ), // @codingStandardsIgnoreEnd - ); + ]; return $tests; } function invalidTestCases() { - $tests = array( - array( 'n mod mod 5 is 1', 'mod mod' ), - array( 'n', 'just n' ), - array( 'n is in 5', 'is in' ), - ); + $tests = [ + [ 'n mod mod 5 is 1', 'mod mod' ], + [ 'n', 'just n' ], + [ 'n is in 5', 'is in' ], + ]; return $tests; } -- To view, visit https://gerrit.wikimedia.org/r/375845 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I1be473cf82364de6151a2bc9c71405b74a8d4b83 Gerrit-PatchSet: 1 Gerrit-Project: CLDRPluralRuleParser Gerrit-Branch: master Gerrit-Owner: Libraryupgrader <tools.libraryupgra...@tools.wmflabs.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits