Skip to content

Commit

Permalink
Merge "REST: Combine PHPCS Rulesets for Search and CRUD"
Browse files Browse the repository at this point in the history
  • Loading branch information
jenkins-bot authored and Gerrit Code Review committed Feb 4, 2025
2 parents f3f3536 + 69b3010 commit 52e602b
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 57 deletions.
9 changes: 3 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,12 @@
"scripts": {
"lint": "parallel-lint . --exclude vendor --exclude node_modules --exclude .git --exclude lib/packages/*/*/vendor",
"phpcs": "phpcs -p -s --cache",
"phpcs:rest-api": "phpcs -p -s --standard=./repo/domains/crud/ruleset.xml repo/domains/crud/",
"phpcs:search": "phpcs -p -s --standard=./repo/domains/search/ruleset.xml repo/domains/search/",
"phpcs:prpl": "phpcs -p -s --cache --standard=prpl-ruleset.xml",
"phpcs-modified": "bash build/phpcsGitModified.sh",
"phpcs-committed": "bash build/phpcsGitCommitted.sh",
"fix": [
"minus-x fix .",
"phpcbf --standard=./repo/domains/crud/ruleset.xml repo/domains/crud/",
"phpcbf --standard=./repo/domains/search/ruleset.xml repo/domains/search/",
"phpcbf --standard=prpl-ruleset.xml",
"phpcbf"
],
"fix-modified": "bash build/phpcbfGitModified.sh",
Expand All @@ -75,8 +73,7 @@
"composer validate --no-interaction",
"composer lint",
"composer phpcs",
"composer phpcs:rest-api",
"composer phpcs:search",
"composer phpcs:prpl",
"composer phpstan",
"minus-x check ."
],
Expand Down
20 changes: 17 additions & 3 deletions repo/domains/crud/ruleset.xml → prpl-ruleset.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?xml version="1.0"?>
<ruleset name="rest-api">
<!-- This is not a standalone ruleset, but an extension of Wikibase's main phpcs config.
It is invoked separately to prevent the two rule sets from interfering with each other. -->
<ruleset name="Product Platform Team">
<!-- This is not a standalone ruleset but an extension of Wikibase's main PHPCS configuration.
It is invoked separately to prevent conflicts between multiple rule sets.
This ruleset is maintained by the PRPL team and applies only to directories owned by them. -->

<rule ref="Generic.PHP.RequireStrictTypes" />
<rule ref="Generic.WhiteSpace.ScopeIndent" />
Expand All @@ -25,6 +27,8 @@
<rule ref="SlevomatCodingStandard.Files.TypeNameMatchesFileName">
<properties>
<property name="rootNamespaces" type="array">
<element key="repo/domains/search/src" value="Wikibase\Repo\Domains\Search"/>
<element key="repo/domains/search/tests/phpunit" value="Wikibase\Repo\Tests\Domains\Search"/>
<element key="repo/domains/crud/src" value="Wikibase\Repo\Domains\Crud"/>
<element key="repo/domains/crud/tests/phpunit" value="Wikibase\Repo\Tests\Domains\Crud"/>
<element key="repo/domains/crud/tests/architecture" value="Wikibase\Repo\Tests\Domains\Crud\Architecture"/>
Expand All @@ -36,7 +40,17 @@
<property name="spacesCountAfterKeyword" value="0"/>
</properties>
</rule>
<rule ref="MediaWiki.Classes.FullQualifiedClassName">
<severity>5</severity>
<properties>
<property name="allowMainNamespace" value="false" />
<property name="allowInheritance" value="false" />
<property name="allowFunctions" value="false" />
</properties>
</rule>

<file>repo/domains/crud</file>
<file>repo/domains/search</file>
<arg name="tab-width" value="4" />
<arg name="extensions" value="php" />
<exclude-pattern>node_modules/*</exclude-pattern>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use MediaWiki\Rest\Response;
use MediaWiki\Rest\SimpleHandler;
use MediaWiki\Rest\StringStream;
use SearchEngineFactory;
use SearchResult;
use Wikibase\DataModel\Entity\EntityIdParser;
use Wikibase\DataModel\Entity\Item;
Expand Down Expand Up @@ -38,14 +39,14 @@ class SearchEntitiesRouteHandler extends SimpleHandler {
];
private const RESULTS_LIMIT = 5;

private \SearchEngineFactory $searchEngineFactory;
private SearchEngineFactory $searchEngineFactory;
private EntityNamespaceLookup $entityNamespaceLookup;
private FallbackLabelDescriptionLookupFactory $labelDescriptionLookupFactory;
private LanguageFactory $languageFactory;
private EntityIdParser $entityIdParser;

public function __construct(
\SearchEngineFactory $searchEngineFactory,
SearchEngineFactory $searchEngineFactory,
EntityNamespaceLookup $entityNamespaceLookup,
FallbackLabelDescriptionLookupFactory $labelDescriptionLookupFactory,
LanguageFactory $languageFactory,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Wikibase\Repo\Tests\Domains\Crud\Application\UseCaseRequestValidation;

use Generator;
use PHPUnit\Framework\TestCase;
use Wikibase\DataModel\SiteLink;
use Wikibase\Repo\Domains\Crud\Application\UseCaseRequestValidation\SitelinkEditRequest;
Expand Down Expand Up @@ -62,7 +63,7 @@ public function testGivenInvalidRequest_throws(
}
}

public static function sitelinkValidationErrorProvider(): \Generator {
public static function sitelinkValidationErrorProvider(): Generator {
yield 'missing title' => [
UseCaseError::newMissingField( '/sitelink', 'title' ),
new ValidationError(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Wikibase\Repo\Tests\Domains\Crud\Application\UseCases\SetItemDescription;

use PHPUnit\Framework\TestCase;
use Wikibase\DataModel\Entity\ItemId;
use Wikibase\DataModel\Term\Term;
use Wikibase\DataModel\Tests\NewItem;
Expand All @@ -28,7 +29,7 @@
*
* @license GPL-2.0-or-later
*/
class SetItemDescriptionTest extends \PHPUnit\Framework\TestCase {
class SetItemDescriptionTest extends TestCase {

private SetItemDescriptionValidator $validator;
private AssertItemExists $assertItemExists;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use DataValues\DataValue;
use DataValues\StringValue;
use Generator;
use InvalidArgumentException;
use PHPUnit\Framework\TestCase;
use Wikibase\Repo\Domains\Crud\Domain\ReadModel\Value;

Expand Down Expand Up @@ -34,7 +35,7 @@ public function testGivenInvalidConstructorArgs_throws(
string $valueType,
?DataValue $content = null
): void {
$this->expectException( \InvalidArgumentException::class );
$this->expectException( InvalidArgumentException::class );
$v = new Value( $valueType, $content );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Wikibase\Repo\Tests\Domains\Crud\Infrastructure;

use Exception;
use Generator;
use LogicException;
use PHPUnit\Framework\TestCase;
use Wikibase\DataModel\Entity\ItemId;
Expand Down Expand Up @@ -60,7 +61,7 @@ public function testGivenSitelinkDeserializerThrows_returnsValidationErrors(
$this->assertEquals( $context, $validationError->getContext() );
}

public static function provideInvalidSitelink(): \Generator {
public static function provideInvalidSitelink(): Generator {
yield 'missing title' => [
new MissingFieldException( 'title' ),
SitelinkValidator::CODE_TITLE_MISSING,
Expand Down
42 changes: 0 additions & 42 deletions repo/domains/search/ruleset.xml

This file was deleted.

0 comments on commit 52e602b

Please sign in to comment.