Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Member variables and methods should not require DocBlock when properly typed #476

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from

Conversation

JacobBrownAustin
Copy link

…y typed

https://developer.adobe.com/commerce/php/coding-standards/docblock/
> Include all necessary information without duplication.

Example 1:

```
private ?ObjectManagerInterface $objectManager;
```
should not require a comment
```
/** @var ObjectManagerInterface|null $objectManager */
```
because all of that information is duplicated.  (Though the nullable is actually harder to read in DocBlock standard.)

Example 2:
```
    public function getWeakMap() : WeakMap
    {
        return $this->weakMap;
    }
```
This method is expressive. It is obvious what it does. It is strictly typed. There is no reason that it should need a DocBlock.

This change no longer requires DocBlock in these cases:

1: member variables that have defined types
2: methods where all parameters have defined types AND method has defined return type (__construct and __destruct won't require return type, since it isn't allowed)
Adding in code to check the namespace of the class/interfaces to see if it is API.
Magento's API code requires method Doc Blocks because it doesn't use Reflection for types.

https://developer.adobe.com/commerce/php/development/components/web-api/services/
@fredden
Copy link
Member

fredden commented Dec 15, 2023

@JacobBrownAustin thanks for raising this. Please can you add some tests to cover the changes being introduced here. I don't know why the automated test runs failed in GitHub Actions; do the tests run successfully on your system?

@JacobBrownAustin
Copy link
Author

Yeah; I'm working on updating tests now.

@fredden
Copy link
Member

fredden commented Dec 15, 2023

https://wiki.corp.adobe.com/pages/viewpage.action?spaceKey=MC&title=Proposal+to+change+magento-coding-standard+to+not+require+DocBlock+when+parameters+defined

This URL doesn't work for me. Is this an internal reference within Adobe? What does this page say?

@JacobBrownAustin
Copy link
Author

Yeah I'll update the details if this to include the info from that page. Basically, I proposed that we shouldn't need superfluous DockBlock for property or method if the type is already defined. It's also solving a separate issue I found more recently that readonly properties fail even when they have proper DockBlock.

@fredden
Copy link
Member

fredden commented Dec 16, 2023

There we're a lot of changes in PHP_CodeSniffer v3.8.0 related to readonly. It's possible that the bug you mention in passing here has already been solved. Perhaps you could open an issue here so that can be discussed/investigated.

@fredden
Copy link
Member

fredden commented Dec 18, 2023

See also #406

* Updated unit tests to cover new functionality reguarding when we can safely skip requiring DockBlocks
* Fix MethodArgumentsSniff to work on PHP files without namespaces
@JacobBrownAustin JacobBrownAustin force-pushed the parameters-defined-needs-no-docblock-except-complex branch 2 times, most recently from aa44722 to 1fa5365 Compare December 18, 2023 18:52
@JacobBrownAustin JacobBrownAustin force-pushed the parameters-defined-needs-no-docblock-except-complex branch from 1fa5365 to 59b5d46 Compare December 18, 2023 18:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Pull Request Progress
  
Review in Progress
Development

Successfully merging this pull request may close these issues.

None yet

2 participants