google / google/site-kit-wp

Add PHP return type declarations, and enforce them in lint

Open
#13,236 1 comment 0 reactions 0 assignees View on GitHub
P2 PHP Team S Type: Infrastructure
Dominant language
JavaScript
Stars
1.4k
Forks
384
Avg merge
4d 14h
Merged PRs (30d)
77

Description

## Feature Description

The plugin runs on PHP 7.4 and up, so a method can declare the type it returns. The codebase doesn't use return type declarations.

A package like `slevomat/coding-standard` ships a fixable sniff that writes the type from the `@return` docblock. `rector/rector` can read the method body instead of the docblock, which should be safer.

Make a return type the rule here, so every method states what it returns. Add a lint check that reports a method without one, and update the code already written.

This is a follow-up to [a review comment on #13118](https://github.com/google/site-kit-wp/pull/13118#discussion_r3614153271), which asked for this ticket.

---------------

_Do not alter or remove anything below. The following sections will be managed by moderators only._

## Acceptance criteria

*

## Implementation Brief

* [ ]

### Test Coverage

*

## QA Brief

*

## Changelog entry

*

Contributor guide

Open the contributing guide

Research direction

Start by reviewing the PHP codebase's existing lint configuration and the available Rector and slevomat/coding-standard approaches. Determine how to add a check for missing return types and update existing methods across the codebase; done means every method declares a return type and lint reports omissions.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.