Skip to content

Commit

Permalink
Fix and enable FunctionComment.MissingReturn PHPCS rule
Browse files Browse the repository at this point in the history
It looks like this is worth it. There are not that many issues
found, which implies that almost all of this codebase was already
following this rule.

I tried to apply the most minimal fixes as well as reduce
duplication by utilizing the @inheritdoc feature. It effectively
marks a method as "intentionally undocumented".

Change-Id: I394ad1fc9b918b0b7896bb47d60723587e174f83
  • Loading branch information
thiemowmde committed Oct 17, 2023
1 parent 9edb1d1 commit d461c15
Show file tree
Hide file tree
Showing 25 changed files with 47 additions and 123 deletions.
1 change: 0 additions & 1 deletion .phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<exclude name="MediaWiki.Commenting.FunctionComment.MissingDocumentationProtected" />
<exclude name="MediaWiki.Commenting.FunctionComment.MissingDocumentationPublic" />
<exclude name="MediaWiki.Commenting.FunctionComment.MissingParamTag" />
<exclude name="MediaWiki.Commenting.FunctionComment.MissingReturn" />
<!-- Note: NotPunctuationReturnType can be enabled when the sniff accepts array shapes -->
<exclude name="MediaWiki.Commenting.FunctionComment.NotPunctuationReturnType" />
<!-- Note: ParamNameNoMatch is probably a great candidate for the next round of fixes -->
Expand Down
1 change: 1 addition & 0 deletions client/includes/MaintenanceShellStart.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use Wikibase\Client\WikibaseClient;

// phpcs:disable Squiz.Functions.GlobalFunction.Found
// phpcs:disable MediaWiki.Commenting.FunctionComment.MissingReturn
// phpcs:disable MediaWiki.NamingConventions.PrefixedGlobalFunctions.wfPrefix

if ( !function_exists( 'mws' ) ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ private function mockTitle( $baseURL, $titleText ) {

/**
* @param string|null $timestamp
* @return RevisionLookup
*/
private function createMockRevisionLookup( $timestamp ) {
$revisionRecord = $this->createMock( RevisionRecord::class );
Expand Down
32 changes: 19 additions & 13 deletions lib/packages/wikibase/data-model/tests/unit/NewItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class NewItem {
private $descriptions = [];

/**
* @var array[] Indexed by language on the first level
* @var array<string,string[]> Indexed by language code on the first level
*/
private $aliases = [];

Expand Down Expand Up @@ -86,15 +86,15 @@ public function build() {
}

/**
* @see andId
* @param ItemId|string $itemId
* @return self
*/
public static function withId( $itemId ) {
return ( new self() )->andId( $itemId );
}

/**
* @param ItemId|string $itemId
*
* @return self
*/
public function andId( $itemId ) {
Expand All @@ -107,7 +107,9 @@ public function andId( $itemId ) {
}

/**
* @see andLabel
* @param string $languageCode
* @param string $label
* @return self
*/
public static function withLabel( $languageCode, $label ) {
return ( new self() )->andLabel( $languageCode, $label );
Expand All @@ -116,7 +118,6 @@ public static function withLabel( $languageCode, $label ) {
/**
* @param string $languageCode
* @param string $label
*
* @return self
*/
public function andLabel( $languageCode, $label ) {
Expand All @@ -126,7 +127,9 @@ public function andLabel( $languageCode, $label ) {
}

/**
* @see andDescription
* @param string $languageCode
* @param string $description
* @return self
*/
public static function withDescription( $languageCode, $description ) {
return ( new self() )->andDescription( $languageCode, $description );
Expand All @@ -135,7 +138,6 @@ public static function withDescription( $languageCode, $description ) {
/**
* @param string $languageCode
* @param string $description
*
* @return self
*/
public function andDescription( $languageCode, $description ) {
Expand All @@ -145,7 +147,9 @@ public function andDescription( $languageCode, $description ) {
}

/**
* @see andAliases
* @param string $languageCode
* @param string[]|string $aliases
* @return self
*/
public static function withAliases( $languageCode, $aliases ) {
return ( new self() )->andAliases( $languageCode, $aliases );
Expand All @@ -154,7 +158,6 @@ public static function withAliases( $languageCode, $aliases ) {
/**
* @param string $languageCode
* @param string[]|string $aliases
*
* @return self
*/
public function andAliases( $languageCode, $aliases ) {
Expand All @@ -164,7 +167,11 @@ public function andAliases( $languageCode, $aliases ) {
}

/**
* @see andSiteLink
* @param string $siteId
* @param string $pageName
* @param ItemId[]|string[]|ItemId|string|null $badges Zero or more item ID references as either
* strings or ItemId objects. Can be an array or a single value.
* @return self
*/
public static function withSiteLink( $siteId, $pageName, $badges = null ) {
return ( new self() )->andSiteLink( $siteId, $pageName, $badges );
Expand All @@ -175,7 +182,6 @@ public static function withSiteLink( $siteId, $pageName, $badges = null ) {
* @param string $pageName
* @param ItemId[]|string[]|ItemId|string|null $badges Zero or more item ID references as either
* strings or ItemId objects. Can be an array or a single value.
*
* @return self
*/
public function andSiteLink( $siteId, $pageName, $badges = null ) {
Expand All @@ -190,15 +196,15 @@ public function andSiteLink( $siteId, $pageName, $badges = null ) {
}

/**
* @see andStatement
* @param NewStatement|Statement|Snak $statement
* @return self
*/
public static function withStatement( $statement ) {
return ( new self() )->andStatement( $statement );
}

/**
* @param NewStatement|Statement|Snak $statement
*
* @return self
*/
public function andStatement( $statement ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,8 @@ private function givenItemDoesNotExist( $itemId ) {

/**
* @param string $itemId
* phpcs:ignore MediaWiki.Commenting.FunctionComment.ObjectTypeHintReturn
* @return object
*/
private function givenItemExists( $itemId ) {
$title = $this->createMock( Title::class );
Expand Down
10 changes: 1 addition & 9 deletions repo/includes/ChangeOp/ChangeOpAliases.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,7 @@ private function updateAliases( AliasGroupList $aliases ) {
$aliases->setAliasesForLanguage( $this->languageCode, $newAliases );
}

/**
* @see ChangeOp::apply()
*
* @param EntityDocument $entity
* @param Summary|null $summary
*
* @throws InvalidArgumentException
* @throws ChangeOpException
*/
/** @inheritDoc */
public function apply( EntityDocument $entity, Summary $summary = null ) {
if ( !( $entity instanceof AliasesProvider ) ) {
throw new InvalidArgumentException( '$entity must be a AliasesProvider' );
Expand Down
10 changes: 1 addition & 9 deletions repo/includes/ChangeOp/ChangeOpDescription.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,7 @@ private function buildResult( EntityId $entityId = null, Term $oldDescription =
return new ChangeOpDescriptionResult( $entityId, $this->languageCode, $oldDescriptionText, $newDescriptionText, $isEntityChanged );
}

/**
* @see ChangeOp::apply()
*
* @param EntityDocument $entity
* @param Summary|null $summary
*
* @throws InvalidArgumentException
* @throws ChangeOpException
*/
/** @inheritDoc */
public function apply( EntityDocument $entity, Summary $summary = null ) {
if ( !( $entity instanceof DescriptionsProvider ) ) {
throw new InvalidArgumentException( '$entity must be a DescriptionsProvider' );
Expand Down
9 changes: 1 addition & 8 deletions repo/includes/ChangeOp/ChangeOpLabel.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,7 @@ private function buildResult( EntityId $entityId = null, Term $oldLabel = null,
return new ChangeOpLabelResult( $entityId, $this->languageCode, $oldLabelText, $newLabelText, $isEntityChanged );
}

/**
* @see ChangeOp::apply()
*
* @param EntityDocument $entity
* @param Summary|null $summary
*
* @throws InvalidArgumentException
*/
/** @inheritDoc */
public function apply( EntityDocument $entity, Summary $summary = null ) {
if ( !( $entity instanceof LabelsProvider ) ) {
throw new InvalidArgumentException( '$entity must be a LabelsProvider' );
Expand Down
7 changes: 1 addition & 6 deletions repo/includes/ChangeOp/ChangeOpMainSnak.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,10 @@ public function getStatementGuid() {
}

/**
* @see ChangeOp::apply()
* - a new claim with $snak as mainsnak gets added when $claimGuid is empty and $snak is set
* - the claim's mainsnak gets set to $snak when $claimGuid and $snak are set
*
* @param EntityDocument $entity
* @param Summary|null $summary
*
* @throws InvalidArgumentException
* @throws ChangeOpException
* @inheritDoc
*/
public function apply( EntityDocument $entity, Summary $summary = null ) {
if ( !( $entity instanceof StatementListProvider ) ) {
Expand Down
7 changes: 1 addition & 6 deletions repo/includes/ChangeOp/ChangeOpQualifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,10 @@ public function __construct( $statementGuid, Snak $snak, $snakHash, SnakValidato
}

/**
* @see ChangeOp::apply()
* - a new qualifier gets added when $snakHash is empty and $snak is set
* - the qualifier gets set to $snak when $snakHash and $snak are set
*
* @param EntityDocument $entity
* @param Summary|null $summary
*
* @throws InvalidArgumentException
* @throws ChangeOpException
* @inheritDoc
*/
public function apply( EntityDocument $entity, Summary $summary = null ) {
if ( !( $entity instanceof StatementListProvider ) ) {
Expand Down
10 changes: 1 addition & 9 deletions repo/includes/ChangeOp/ChangeOpQualifierRemove.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,7 @@ public function __construct( $statementGuid, $snakHash ) {
$this->snakHash = $snakHash;
}

/**
* @see ChangeOp::apply()
*
* @param EntityDocument $entity
* @param Summary|null $summary
*
* @throws InvalidArgumentException
* @throws ChangeOpException
*/
/** @inheritDoc */
public function apply( EntityDocument $entity, Summary $summary = null ) {
if ( !( $entity instanceof StatementListProvider ) ) {
throw new InvalidArgumentException( '$entity must be a StatementListProvider' );
Expand Down
7 changes: 1 addition & 6 deletions repo/includes/ChangeOp/ChangeOpReference.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,10 @@ public function __construct(
}

/**
* @see ChangeOp::apply()
* - a new reference gets added when $referenceHash is empty and $reference is set
* - the reference gets set to $reference when $referenceHash and $reference are set
*
* @param EntityDocument $entity
* @param Summary|null $summary
*
* @throws InvalidArgumentException
* @throws ChangeOpException
* @inheritDoc
*/
public function apply( EntityDocument $entity, Summary $summary = null ) {
if ( !( $entity instanceof StatementListProvider ) ) {
Expand Down
10 changes: 1 addition & 9 deletions repo/includes/ChangeOp/ChangeOpReferenceRemove.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,7 @@ public function __construct( $statementGuid, $referenceHash ) {
$this->referenceHash = $referenceHash;
}

/**
* @see ChangeOp::apply()
*
* @param EntityDocument $entity
* @param Summary|null $summary
*
* @throws InvalidArgumentException
* @throws ChangeOpException
*/
/** @inheritDoc */
public function apply( EntityDocument $entity, Summary $summary = null ) {
if ( !( $entity instanceof StatementListProvider ) ) {
throw new InvalidArgumentException( '$entity must be a StatementListProvider' );
Expand Down
10 changes: 1 addition & 9 deletions repo/includes/ChangeOp/ChangeOpRemoveStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,7 @@ public function __construct( $guid ) {
$this->guid = $guid;
}

/**
* @see ChangeOp::apply
*
* @param EntityDocument $entity
* @param Summary|null $summary
*
* @throws InvalidArgumentException
* @throws ChangeOpException
*/
/** @inheritDoc */
public function apply( EntityDocument $entity, Summary $summary = null ) {
if ( !( $entity instanceof StatementListProvider ) ) {
throw new InvalidArgumentException( '$entity must be a StatementListProvider' );
Expand Down
10 changes: 1 addition & 9 deletions repo/includes/ChangeOp/ChangeOpStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,7 @@ public function __construct(
$this->index = $index;
}

/**
* @see ChangeOp::apply
*
* @param EntityDocument $entity
* @param Summary|null $summary
*
* @throws InvalidArgumentException
* @throws ChangeOpException
*/
/** @inheritDoc */
public function apply( EntityDocument $entity, Summary $summary = null ) {
if ( !( $entity instanceof StatementListProvider ) ) {
throw new InvalidArgumentException( '$entity must be a StatementListProvider' );
Expand Down
10 changes: 1 addition & 9 deletions repo/includes/ChangeOp/ChangeOpStatementRank.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,7 @@ public function __construct( $statementGuid, $rank ) {
$this->rank = $rank;
}

/**
* @see ChangeOp::apply()
*
* @param EntityDocument $entity
* @param Summary|null $summary
*
* @throws InvalidArgumentException
* @throws ChangeOpException
*/
/** @inheritDoc */
public function apply( EntityDocument $entity, Summary $summary = null ) {
if ( !( $entity instanceof StatementListProvider ) ) {
throw new InvalidArgumentException( '$entity must be a StatementListProvider' );
Expand Down
10 changes: 1 addition & 9 deletions repo/includes/ChangeOp/ChangeOps.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,7 @@ public function getChangeOps() {
return $this->changeOps;
}

/**
* @see ChangeOp::apply()
* Applies all changes to the given entity
*
* @param EntityDocument $entity
* @param Summary|null $summary
*
* @throws ChangeOpException
*/
/** @inheritDoc */
public function apply( EntityDocument $entity, Summary $summary = null ) {
$changeOpsResults = [];

Expand Down
1 change: 1 addition & 0 deletions repo/includes/ChangeOp/ChangeOpsMerge.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ private function getSiteLinkChangeOpFactory() {

/**
* @throws ChangeOpException
* @return ChangeOpResult
*/
public function apply() {
// NOTE: we don't want to validate the ChangeOps individually, since they represent
Expand Down
7 changes: 1 addition & 6 deletions repo/includes/ChangeOp/NullChangeOp.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,7 @@ public function validate( EntityDocument $entity ) {
return Result::newSuccess();
}

/**
* @see ChangeOp::apply
*
* @param EntityDocument $entity
* @param Summary|null $summary Unused
*/
/** @inheritDoc */
public function apply( EntityDocument $entity, Summary $summary = null ) {
// no op

Expand Down
1 change: 1 addition & 0 deletions repo/includes/MaintenanceShellStart.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use Wikibase\Repo\WikibaseRepo;

// phpcs:disable Squiz.Functions.GlobalFunction.Found
// phpcs:disable MediaWiki.Commenting.FunctionComment.MissingReturn
// phpcs:disable MediaWiki.NamingConventions.PrefixedGlobalFunctions.wfPrefix

if ( !function_exists( 'mws' ) ) {
Expand Down
2 changes: 0 additions & 2 deletions repo/includes/RepoHooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,6 @@ public static function onSetupAfterCache() {
return $entityContentFactory->getContentHandlerForType( $entityType );
};
}

return true;
}

/**
Expand Down
Loading

0 comments on commit d461c15

Please sign in to comment.