Skip to content

Commit

Permalink
Add phpcs and make it pass
Browse files Browse the repository at this point in the history
Change-Id: If17d74cb08da803aa7676063d0e631111480fff3
  • Loading branch information
kizule committed Apr 14, 2020
1 parent 95be433 commit 74f6c77
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 20 deletions.
7 changes: 7 additions & 0 deletions .phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0"?>
<ruleset>
<rule ref="./vendor/mediawiki/mediawiki-codesniffer/MediaWiki" />
<file>.</file>
<arg name="extensions" value="php,php5,inc"/>
<arg name="encoding" value="UTF-8"/>
</ruleset>
14 changes: 7 additions & 7 deletions RandomSelection.i18n.magic.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
* @ingroup Extensions
*/

$magicWords = array();
$magicWords = [];

/** English */
$magicWords['en'] = array(
'choose' => array( 0, 'choose' ),
);
$magicWords['en'] = [
'choose' => [ 0, 'choose' ],
];

/** Finnish (suomi) */
$magicWords['fi'] = array(
'choose' => array( 0, 'valitse' ),
);
$magicWords['fi'] = [
'choose' => [ 0, 'valitse' ],
];
7 changes: 5 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@
"require-dev": {
"jakub-onderka/php-parallel-lint": "1.0.0",
"jakub-onderka/php-console-highlighter": "0.4.0",
"mediawiki/mediawiki-codesniffer": "30.0.0",
"mediawiki/minus-x": "1.0.0"
},
"scripts": {
"test": [
"parallel-lint . --exclude vendor --exclude node_modules",
"minus-x check ."
"minus-x check .",
"phpcs -p -s"
],
"fix": [
"minus-x fix ."
"minus-x fix .",
"phpcbf"
]
}
}
2 changes: 1 addition & 1 deletion extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
]
},
"AutoloadClasses": {
"RandomSelection": "RandomSelection.class.php"
"RandomSelection": "src/RandomSelection.php"
},
"ExtensionMessagesFiles": {
"RandomSelectionMagic": "RandomSelection.i18n.magic.php"
Expand Down
23 changes: 13 additions & 10 deletions RandomSelection.class.php → src/RandomSelection.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,20 @@ class RandomSelection {
* Register the <choose> tag and {{#choose:option 1|...|option N}} function
* with the Parser.
*
* @param Parser $parser
* @param Parser &$parser
* @return bool
*/
public static function register( &$parser ) {
$parser->setHook( 'choose', array( __CLASS__, 'render' ) );
$parser->setFunctionHook( 'choose', array( __CLASS__, 'renderParserFunction' ), Parser::SFH_OBJECT_ARGS );
$parser->setHook( 'choose', [ __CLASS__, 'render' ] );
$parser->setFunctionHook( 'choose', [ __CLASS__, 'renderParserFunction' ],
Parser::SFH_OBJECT_ARGS );
return true;
}

/**
* Register the magic word ID.
*
* @param array $variableIds
* @param array &$variableIds
* @return bool
*/
public static function variableIds( &$variableIds ) {
Expand All @@ -40,6 +41,7 @@ public static function variableIds( &$variableIds ) {
* @param string $input User-supplied input
* @param array $argv User-supplied arguments to the tag, e.g. <choose uncached>...</choose>
* @param Parser $parser
* @return string
*/
public static function render( $input, $argv, $parser ) {
# Prevent caching if specified so by the user
Expand Down Expand Up @@ -119,22 +121,23 @@ public static function render( $input, $argv, $parser ) {
/**
* Callback for the {{#choose:}} magic word magic (see register() in this file)
*
* @param Parser $parser
* @param Parser &$parser
* @param PPFrame $frame
* @param array $args User-supplied arguments
* @return string
*/
public static function renderParserFunction( &$parser, $frame, $args ) {
$options = array();
$options = [];
$r = 0;

// First one is not an object
$arg = array_shift( $args );
$parts = explode( '=', $arg, 2 );
if ( count( $parts ) == 2 ) {
$options[] = array( intval( trim( $parts[0] ) ), $parts[1] );
$options[] = [ intval( trim( $parts[0] ) ), $parts[1] ];
$r += intval( trim( $parts[0] ) );
} elseif ( count( $parts ) == 1 ) {
$options[] = array( 1, $parts[0] );
$options[] = [ 1, $parts[0] ];
$r += 1;
}

Expand All @@ -145,10 +148,10 @@ public static function renderParserFunction( &$parser, $frame, $args ) {
$valueNode = $bits['value'];
if ( $index === '' ) {
$name = trim( $frame->expand( $nameNode ) );
$options[] = array( intval( $name ), $valueNode );
$options[] = [ intval( $name ), $valueNode ];
$r += intval( $name );
} else {
$options[] = array( 1, $valueNode );
$options[] = [ 1, $valueNode ];
$r += 1;
}
}
Expand Down

0 comments on commit 74f6c77

Please sign in to comment.