Skip to content

Commit

Permalink
Merge pull request #33 from samwilson/cs
Browse files Browse the repository at this point in the history
Conform to MediaWiki coding standards
  • Loading branch information
addshore committed Sep 14, 2016
2 parents 8418ad8 + 8f13442 commit f3b94f1
Show file tree
Hide file tree
Showing 36 changed files with 235 additions and 208 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ before_script:

script:
- cd tests/unit && phpunit --coverage-clover=coverage.clover && cd ../../
- $TRAVIS_BUILD_DIR/vendor/bin/phpcs

after_script:
- wget https://scrutinizer-ci.com/ocular.phar
Expand Down
14 changes: 13 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "addwiki/mediawiki-api",
"type": "library",
"description": "A Mediawiki api lib",
"description": "A MediaWiki API library",
"keywords": ["Mediawiki"],
"license": "GPL-2.0+",
"authors": [
Expand All @@ -13,6 +13,11 @@
"addwiki/mediawiki-api-base": "~2.0",
"addwiki/mediawiki-datamodel": "~0.6.0"
},
"require-dev": {
"jakub-onderka/php-parallel-lint": "^0.9.2",
"mediawiki/mediawiki-codesniffer": "^0.7.2",
"phpunit/phpunit": "~4.8"
},
"autoload": {
"psr-4": {
"Mediawiki\\Api\\": "src/"
Expand All @@ -22,5 +27,12 @@
"branch-alias": {
"dev-master": "0.7.x-dev"
}
},
"scripts": {
"fix": "phpcbf",
"test": [
"parallel-lint . --exclude vendor",
"phpcs -ps"
]
}
}
8 changes: 8 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0"?>
<ruleset name="MediaWiki">
<rule ref="vendor/mediawiki/mediawiki-codesniffer/MediaWiki"/>
<file>.</file>
<arg name="extensions" value="php,php5,inc"/>
<arg name="encoding" value="utf8"/>
<exclude-pattern>vendor/</exclude-pattern>
</ruleset>
2 changes: 1 addition & 1 deletion src/Generator/FluentGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function set( $key, $value ) {
* @return string
*/
private function addKeyPrefixIfNeeded( $key ) {
if( strtolower( substr( $key, 0, 1 ) ) === 'g' ) {
if ( strtolower( substr( $key, 0, 1 ) ) === 'g' ) {
return $key;
}
return 'g' . $key;
Expand Down
2 changes: 1 addition & 1 deletion src/MediawikiFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,4 +219,4 @@ public function newImageRotator() {
public function newParser() {
return new Parser( $this->api );
}
}
}
6 changes: 3 additions & 3 deletions src/Service/FileUploader.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ public function __construct( MediawikiApi $api ) {
* @return bool
*/
public function upload( $targetName, $location ) {
$params = array(
$params = [
'filename' => $targetName,
'token' => $this->api->getToken( 'edit' ),
);
$headers = array();
];
$headers = [];

if ( is_file( $location ) ) {
$params['file'] = fopen( $location, 'r' );
Expand Down
6 changes: 3 additions & 3 deletions src/Service/ImageRotator.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ public function __construct( MediawikiApi $api ) {
* @return bool
*/
public function rotate( File $file, $rotation ) {
$params = array(
$params = [
'rotation' => $rotation,
'token' => $this->api->getToken(),
);
];

if ( !is_null( $file->getPageIdentifier()->getTitle() ) ) {
$params['titles'] = $file->getPageIdentifier()->getTitle()->getText();
Expand All @@ -66,4 +66,4 @@ public function rotate( File $file, $rotation ) {
return true;
}

}
}
15 changes: 8 additions & 7 deletions src/Service/LogListGetter.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,17 @@ public function __construct( MediawikiApi $api ) {
*
* @return LogList
*/
public function getLogList ( array $extraParams = array() ) {
public function getLogList( array $extraParams = [] ) {
$logList = new LogList();

while ( true ) {
$params = array(
$params = [
'list' => 'logevents',
'leprop' => 'title|ids|type|user|timestamp|comment|details'
);
];

$result = $this->api->getRequest( new SimpleRequest( 'query', array_merge( $extraParams, $params ) ) );
$newParams = array_merge( $extraParams, $params );
$result = $this->api->getRequest( new SimpleRequest( 'query', $newParams ) );

foreach ( $result[ 'query' ]['logevents'] as $logevent ) {
$logList->addLog(
Expand Down Expand Up @@ -76,7 +77,7 @@ public function getLogList ( array $extraParams = array() ) {
* @return array
*/
private function getLogDetailsFromEvent( $event ) {
$ignoreKeys = array_flip( array(
$ignoreKeys = array_flip( [
'logid',
'ns',
'title',
Expand All @@ -87,8 +88,8 @@ private function getLogDetailsFromEvent( $event ) {
'user',
'type',
'timestamp',
'comment' ) );
'comment' ] );
return array_diff_key( $event, $ignoreKeys );
}

}
}
16 changes: 8 additions & 8 deletions src/Service/PageDeleter.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function __construct( MediawikiApi $api ) {
*
* @return bool
*/
public function delete( Page $page, array $extraParams = array() ) {
public function delete( Page $page, array $extraParams = [] ) {
$this->api->postRequest( new SimpleRequest(
'delete',
$this->getDeleteParams( $page->getPageIdentifier(), $extraParams )
Expand All @@ -52,7 +52,7 @@ public function delete( Page $page, array $extraParams = array() ) {
*
* @return bool
*/
public function deleteFromRevision( Revision $revision, array $extraParams = array() ) {
public function deleteFromRevision( Revision $revision, array $extraParams = [] ) {
$this->api->postRequest( new SimpleRequest(
'delete',
$this->getDeleteParams( $revision->getPageIdentifier(), $extraParams )
Expand All @@ -68,7 +68,7 @@ public function deleteFromRevision( Revision $revision, array $extraParams = arr
*
* @return bool
*/
public function deleteFromPageId( $pageid, array $extraParams = array() ) {
public function deleteFromPageId( $pageid, array $extraParams = [] ) {
$this->api->postRequest( new SimpleRequest(
'delete',
$this->getDeleteParams( new PageIdentifier( null, $pageid ), $extraParams )
Expand All @@ -84,8 +84,8 @@ public function deleteFromPageId( $pageid, array $extraParams = array() ) {
*
* @return bool
*/
public function deleteFromPageTitle( $title, array $extraParams = array() ) {
if( is_string( $title ) ) {
public function deleteFromPageTitle( $title, array $extraParams = [] ) {
if ( is_string( $title ) ) {
$title = new Title( $title );
}
$this->api->postRequest( new SimpleRequest(
Expand All @@ -102,9 +102,9 @@ public function deleteFromPageTitle( $title, array $extraParams = array() ) {
* @return array
*/
private function getDeleteParams( PageIdentifier $identifier, $extraParams ) {
$params = array();
$params = [];

if( !is_null( $identifier->getId() ) ) {
if ( !is_null( $identifier->getId() ) ) {
$params['pageid'] = $identifier->getId();
} else {
$params['title'] = $identifier->getTitle()->getTitle();
Expand All @@ -115,4 +115,4 @@ private function getDeleteParams( PageIdentifier $identifier, $extraParams ) {
return array_merge( $extraParams, $params );
}

}
}
30 changes: 15 additions & 15 deletions src/Service/PageGetter.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ public function __construct( MediawikiApi $api ) {
*
* @returns Page
*/
public function getFromRevisionId( $id, array $extraParams = array() ) {
public function getFromRevisionId( $id, array $extraParams = [] ) {
$result =
$this->api->getRequest(
new SimpleRequest(
'query',
$this->getQuery( array( 'revids' => $id ), $extraParams )
$this->getQuery( [ 'revids' => $id ], $extraParams )
)
);

Expand All @@ -60,15 +60,15 @@ public function getFromRevisionId( $id, array $extraParams = array() ) {
*
* @returns Page
*/
public function getFromTitle( $title, array $extraParams = array() ) {
public function getFromTitle( $title, array $extraParams = [] ) {
if ( $title instanceof Title ) {
$title = $title->getTitle();
}
$result =
$this->api->getRequest(
new SimpleRequest(
'query',
$this->getQuery( array( 'titles' => $title ), $extraParams )
$this->getQuery( [ 'titles' => $title ], $extraParams )
)
);

Expand All @@ -83,12 +83,12 @@ public function getFromTitle( $title, array $extraParams = array() ) {
*
* @returns Page
*/
public function getFromPageId( $id, array $extraParams = array() ) {
public function getFromPageId( $id, array $extraParams = [] ) {
$result =
$this->api->getRequest(
new SimpleRequest(
'query',
$this->getQuery( array( 'pageids' => $id ), $extraParams )
$this->getQuery( [ 'pageids' => $id ], $extraParams )
)
);

Expand All @@ -106,7 +106,7 @@ public function getFromPageId( $id, array $extraParams = array() ) {
*/
public function getFromPageIdentifier(
PageIdentifier $pageIdentifier,
array $extraParams = array()
array $extraParams = []
) {
if ( !$pageIdentifier->identifiesPage() ) {
throw new RuntimeException( '$pageIdentifier does not identify a page' );
Expand All @@ -126,12 +126,12 @@ public function getFromPageIdentifier(
*
* @return Page
*/
public function getFromPage( Page $page, array $extraParams = array() ) {
public function getFromPage( Page $page, array $extraParams = [] ) {
$result =
$this->api->getRequest(
new SimpleRequest(
'query',
$this->getQuery( array( 'pageids' => $page->getId() ), $extraParams )
$this->getQuery( [ 'pageids' => $page->getId() ], $extraParams )
)
);
$revisions = $this->getRevisionsFromResult( array_shift( $result['query']['pages'] ) );
Expand All @@ -151,12 +151,12 @@ public function getFromPage( Page $page, array $extraParams = array() ) {
*
* @return Page
*/
public function getFromRevision( Revision $revision, array $extraParams = array() ) {
public function getFromRevision( Revision $revision, array $extraParams = [] ) {
$result =
$this->api->getRequest(
new SimpleRequest(
'query',
$this->getQuery( array( 'revids' => $revision->getId() ), $extraParams )
$this->getQuery( [ 'revids' => $revision->getId() ], $extraParams )
)
);
$revisions = $this->getRevisionsFromResult( array_shift( $result['query']['pages'] ) );
Expand All @@ -181,12 +181,12 @@ public function getFromRevision( Revision $revision, array $extraParams = array(
*
* @return array
*/
private function getQuery( $additionalParams, array $extraParams = array() ) {
$base = array(
private function getQuery( $additionalParams, array $extraParams = [] ) {
$base = [
'prop' => 'revisions|info|pageprops',
'rvprop' => 'ids|flags|timestamp|user|size|sha1|comment|content|tags',
'inprop' => 'protection',
);
];

return array_merge( $extraParams, $base, $additionalParams );
}
Expand Down Expand Up @@ -256,4 +256,4 @@ private function newPageFromResult( $array ) {
);
}

}
}

0 comments on commit f3b94f1

Please sign in to comment.