Skip to content

Commit

Permalink
Update phpcs
Browse files Browse the repository at this point in the history
  • Loading branch information
samwilson authored and addshore committed Oct 3, 2017
1 parent 1d010d3 commit 51bec20
Show file tree
Hide file tree
Showing 18 changed files with 81 additions and 77 deletions.
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -15,7 +15,7 @@
},
"require-dev": {
"jakub-onderka/php-parallel-lint": "^0.9.2",
"mediawiki/mediawiki-codesniffer": "^0.7.2",
"mediawiki/mediawiki-codesniffer": "^13.0",
"phpunit/phpunit": "~4.8"
},
"autoload": {
Expand Down
4 changes: 3 additions & 1 deletion phpcs.xml
@@ -1,6 +1,8 @@
<?xml version="1.0"?>
<ruleset name="MediaWiki">
<rule ref="vendor/mediawiki/mediawiki-codesniffer/MediaWiki"/>
<rule ref="vendor/mediawiki/mediawiki-codesniffer/MediaWiki">
<exclude name="MediaWiki.Commenting.FunctionComment.MissingParamComment" />
</rule>
<file>.</file>
<arg name="extensions" value="php,php5,inc"/>
<arg name="encoding" value="utf8"/>
Expand Down
3 changes: 3 additions & 0 deletions src/Generator/AnonymousGenerator.php
Expand Up @@ -30,6 +30,9 @@ public function __construct( $name, array $params ) {
$this->params = $params;
}

/**
* @return array
*/
public function getParams() {
$params = $this->params;
$params['generator'] = $this->name;
Expand Down
3 changes: 3 additions & 0 deletions src/Generator/FluentGenerator.php
Expand Up @@ -32,6 +32,9 @@ public static function factory( $name ) {
return new self( $name );
}

/**
* @return string[]
*/
public function getParams() {
$params = $this->params;
$params['generator'] = $this->name;
Expand Down
15 changes: 9 additions & 6 deletions src/Service/CategoryTraverser.php
Expand Up @@ -6,7 +6,6 @@
use Mediawiki\Api\MediawikiApi;
use Mediawiki\Api\SimpleRequest;
use Mediawiki\DataModel\Page;
use Mediawiki\DataModel\PageIdentifier;
use Mediawiki\DataModel\Pages;

/**
Expand Down Expand Up @@ -43,6 +42,9 @@ class CategoryTraverser {
*/
protected $alreadyVisited;

/**
* @param MediawikiApi $api The API to connect to.
*/
public function __construct( MediawikiApi $api ) {
$this->api = $api;
$this->callbacks = [];
Expand All @@ -68,7 +70,7 @@ protected function retrieveNamespaces() {
/**
* Register a callback that will be called for each page or category visited during the
* traversal.
* @param integer $type One of the 'CALLBACK_' constants of this class.
* @param int $type One of the 'CALLBACK_' constants of this class.
* @param callable $callback A callable that takes two \Mediawiki\DataModel\Page parameters.
*/
public function addCallback( $type, $callback ) {
Expand Down Expand Up @@ -102,7 +104,7 @@ public function descend( Page $rootCat, $currentPath = null ) {
// Start a list of child pages.
$descendants = new Pages();
do {
$pageListGetter = new PageListGetter( $this->api );
$pageListGetter = new PageListGetter( $this->api );
$members = $pageListGetter->getPageListFromCategoryName( $rootCatName );
foreach ( $members->toArray() as $member ) {
/** @var Title */
Expand Down Expand Up @@ -133,9 +135,10 @@ public function descend( Page $rootCat, $currentPath = null ) {
$this->call( self::CALLBACK_CATEGORY, [ $member, $rootCat ] );
$newDescendants = $this->descend( $member, $currentPath );
$descendants->addPages( $newDescendants );
$currentPath = new Pages(); // Re-set the path.
// Re-set the path.
$currentPath = new Pages();
} else {
// If it's a page, add it to the list and carry on.
// If it's a page, add it to the list and carry on.
$descendants->addPage( $member );
$this->call( self::CALLBACK_PAGE, [ $member, $rootCat ] );
}
Expand All @@ -146,7 +149,7 @@ public function descend( Page $rootCat, $currentPath = null ) {

/**
* Call all the registered callbacks of a particular type.
* @param integer $type The callback type; should match one of the 'CALLBACK_' constants.
* @param int $type The callback type; should match one of the 'CALLBACK_' constants.
* @param mixed[] $params The parameters to pass to the callback function.
*/
protected function call( $type, $params ) {
Expand Down
8 changes: 5 additions & 3 deletions src/Service/NamespaceGetter.php
Expand Up @@ -11,10 +11,12 @@
*
* @author gbirke
*/
class NamespaceGetter
{
class NamespaceGetter {
private $api;

/**
* @param MediawikiApi $api The API to connect to.
*/
public function __construct( MediawikiApi $api ) {
$this->api = $api;
}
Expand Down Expand Up @@ -65,7 +67,7 @@ public function getNamespaceByName( $name ) {
*/
public function getNamespaces() {
$namespaces = [];
$result = $this->getNamespaceResult()['query'];
$result = $this->getNamespaceResult()['query'];
foreach ( $result['namespaces'] as $nsInfo ) {
$namespaces[$nsInfo['id']] = $this->createNamespaceFromQuery(
$nsInfo, $result['namespacealiases']
Expand Down
8 changes: 4 additions & 4 deletions src/Service/PageGetter.php
Expand Up @@ -38,7 +38,7 @@ public function __construct( MediawikiApi $api ) {
* @param int $id
* @param array $extraParams
*
* @returns Page
* @return Page
*/
public function getFromRevisionId( $id, array $extraParams = [] ) {
$result =
Expand All @@ -58,7 +58,7 @@ public function getFromRevisionId( $id, array $extraParams = [] ) {
* @param string|Title $title
* @param array $extraParams
*
* @returns Page
* @return Page
*/
public function getFromTitle( $title, array $extraParams = [] ) {
if ( $title instanceof Title ) {
Expand All @@ -81,7 +81,7 @@ public function getFromTitle( $title, array $extraParams = [] ) {
* @param int $id
* @param array $extraParams
*
* @returns Page
* @return Page
*/
public function getFromPageId( $id, array $extraParams = [] ) {
$result =
Expand All @@ -102,7 +102,7 @@ public function getFromPageId( $id, array $extraParams = [] ) {
* @param array $extraParams
*
* @throws RuntimeException
* @returns Page
* @return Page
*/
public function getFromPageIdentifier(
PageIdentifier $pageIdentifier,
Expand Down
5 changes: 2 additions & 3 deletions src/Service/PageListGetter.php
Expand Up @@ -7,7 +7,6 @@
use Mediawiki\DataModel\Page;
use Mediawiki\DataModel\PageIdentifier;
use Mediawiki\DataModel\Pages;
use Mediawiki\DataModel\Revisions;
use Mediawiki\DataModel\Title;

/**
Expand Down Expand Up @@ -101,7 +100,7 @@ public function getFromWhatLinksHere( $pageName ) {
public function getFromPrefix( $prefix ) {
$params = [
'list' => 'allpages',
'apprefix' => $prefix,
'apprefix' => $prefix,
];
return $this->runQuery( $params, 'apcontinue', 'allpages' );
}
Expand All @@ -128,7 +127,7 @@ public function getRandom( array $extraParams = [] ) {
* @param string $contName Result subelement name for continue details
* @param string $resName Result element name for main results array
* @param string $pageIdName Result element name for page ID
* @param boolean $cont Whether to continue the query, using multiple requests
* @param bool $cont Whether to continue the query, using multiple requests
* @return Pages
*/
protected function runQuery( $params, $contName, $resName, $pageIdName = 'pageid', $cont = true ) {
Expand Down
4 changes: 0 additions & 4 deletions src/Service/PagePurger.php
Expand Up @@ -90,16 +90,12 @@ public function purgePages( Pages $pages ) {

// for every purge result
foreach ( $responseArray['purge'] as $purgeResponse ) {

// if the purge for the page was successful
if ( array_key_exists( 'purged', $purgeResponse ) ) {

// we iterate all the input pages
foreach ( $pagesArray as $page ) {

// and if the page from the input was successfully purged
if ( $purgeResponse['title'] === $page->getTitle()->getText() ) {

// add it in the purgedPages object
$purgedPages->addPage( $page );

Expand Down
2 changes: 1 addition & 1 deletion src/Service/PageWatcher.php
Expand Up @@ -28,7 +28,7 @@ public function __construct( MediawikiApi $api ) {
/**
* @param Page $page
*
* @returns bool
* @return bool
*/
public function watch( Page $page ) {
$params = [
Expand Down
2 changes: 1 addition & 1 deletion src/Service/Parser.php
Expand Up @@ -52,7 +52,7 @@ public function parsePageAsync( PageIdentifier $pageIdentifier ) {

$promise = $this->api->getRequestAsync( new SimpleRequest( 'parse', $params ) );

return $promise->then( function( $result ) {
return $promise->then( function ( $result ) {
return $result['parse'];
} );
}
Expand Down
2 changes: 0 additions & 2 deletions src/Service/RevisionDeleter.php
Expand Up @@ -33,7 +33,6 @@ public function __construct( MediawikiApi $api ) {
* @return bool
*/
public function delete( Revision $revision ) {

$params = [
'type' => 'revision',
'hide' => 'content',
Expand All @@ -48,7 +47,6 @@ public function delete( Revision $revision ) {
) );

return true;

}

}
2 changes: 1 addition & 1 deletion src/Service/RevisionSaver.php
Expand Up @@ -34,7 +34,7 @@ public function __construct( MediawikiApi $api ) {
* @param Revision $revision
* @param EditInfo $editInfo
*
* @returns bool success
* @return bool success
*/
public function save( Revision $revision, EditInfo $editInfo = null ) {
$editInfo = $editInfo ? $editInfo : $revision->getEditInfo();
Expand Down
3 changes: 1 addition & 2 deletions src/Service/UserGetter.php
Expand Up @@ -28,7 +28,7 @@ public function __construct( MediawikiApi $api ) {
/**
* @param string $username
*
* @returns User
* @return User
*/
public function getFromUsername( $username ) {
$result = $this->api->getRequest(
Expand Down Expand Up @@ -71,7 +71,6 @@ private function newUserFromListUsersResult( $array ) {
''
);
}

}

}
3 changes: 1 addition & 2 deletions tests/integration/CategoryTraverserTest.php
Expand Up @@ -10,8 +10,7 @@
use Mediawiki\DataModel\Revision;
use Mediawiki\DataModel\Content;

class CategoryTraverserTest extends \PHPUnit_Framework_TestCase
{
class CategoryTraverserTest extends \PHPUnit_Framework_TestCase {

/** @var \Mediawiki\Api\MediawikiFactory */
protected $factory;
Expand Down
5 changes: 1 addition & 4 deletions tests/integration/NamespaceGetterTest.php
Expand Up @@ -7,8 +7,7 @@
use Mediawiki\Api\SimpleRequest;
use Mediawiki\DataModel\NamespaceInfo;

class NamespaceGetterTest extends \PHPUnit_Framework_TestCase
{
class NamespaceGetterTest extends \PHPUnit_Framework_TestCase {
public function testGetNamespaceByCanonicalNameReturnsNullIfNamespaceWasNotFound() {
$nsGetter = new NamespaceGetter( $this->getApi() );
$this->assertNull( $nsGetter->getNamespaceByCanonicalName( 'Dummy' ) );
Expand Down Expand Up @@ -74,7 +73,6 @@ private function getApi() {
}

private function getRequest() {

return new SimpleRequest(
'query', [
'meta' => 'siteinfo',
Expand All @@ -83,7 +81,6 @@ private function getRequest() {
}

private function getNamespaceFixture() {

return json_decode( file_get_contents( __DIR__ . '/../fixtures/namespaces.json' ), true );
}
}
20 changes: 12 additions & 8 deletions tests/integration/TestEnvironment.php
Expand Up @@ -12,13 +12,17 @@
*/
class TestEnvironment {

/** @var \Mediawiki\Api\MediawikiFactory */
private $factory;

/**
* Get a new default test environment.
* @return TestEnvironment
*/
public static function newDefault() {
return new self();
}

/** @var \Mediawiki\Api\MediawikiFactory */
private $factory;

/**
* Set up the test environment by creating a new API object pointing to a
* MediaWiki installation on localhost (or elsewhere as specified by the
Expand Down Expand Up @@ -61,7 +65,7 @@ public function getFactory() {
* @return void
*/
public function runJobs() {
$reqestProps = [ 'meta'=>'siteinfo', 'siprop'=>'general' ];
$reqestProps = [ 'meta' => 'siteinfo', 'siprop' => 'general' ];
$siteInfoRequest = new SimpleRequest( 'query', $reqestProps );
$out = $this->getApi()->getRequest( $siteInfoRequest );
$mainPageUrl = $out['query']['general']['base'];
Expand All @@ -75,16 +79,16 @@ public function runJobs() {
* Get the number of jobs currently in the queue.
* @todo This and TestEnvironment::runJobs() should probably not live here.
* @param MediawikiApi $api
* @return integer
* @return int
*/
public function getJobQueueLength( MediawikiApi $api ) {
$req = new SimpleRequest( 'query', [
'meta'=>'siteinfo',
'siprop'=>'statistics',
'meta' => 'siteinfo',
'siprop' => 'statistics',
]
);
$out = $api->getRequest( $req );
return (int) $out['query']['statistics']['jobs'];
return (int)$out['query']['statistics']['jobs'];
}

}

0 comments on commit 51bec20

Please sign in to comment.