magento / magento/magento-coding-standard

Add sniff for Service Contracts

Open
#159 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

proposal
Dominant language
PHP
Stars
375
Forks
165
PR merge metrics
No merged PRs in 30d

Description

Rule

According to this page there are some very specific rules for service contracts. For example:

  • Valid object types include a fully qualified class name or a fully qualified interface name.
  • Any parameters or return values of type array can be denoted by following any of the previous types by an empty set of square brackets []

Wouldn't it make sense to have a sniff for these things?

Reason

I come across a lot of service contracts that don't include FQCN and/or have an array return type instead of FQCN[]. This goes against the rules set by Magento and might also break future (web api) implementations (due to reflection).

Implementation

Not sure at this moment how to implement this, but it seems to me that this can be done with a new sniff.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked Magento service-contract rules and inspect the repository's existing sniffs to determine the appropriate entry point for a new sniff. Define the checks for fully qualified class or interface names and array types written as FQCN[], then verify the sniff reports violations without false positives.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.