-
Notifications
You must be signed in to change notification settings - Fork 154
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
[New Rule] Add declare(strict_types=1) to your PHP files #33
Comments
@lenaorobei I can implement this |
@larsroettig sounds good, but first we need to discuss the approach for version specific sniffs. |
When implementing, please remove a static test that cover the same thing. |
As per architects discussion we need to determine how strict this rule should be:
|
There is a good sniff which checks that your code satisfies php7 styling code (type hints, return types, declaring strict type etc) |
Any progress here? Is there help needed? |
@tmotyl |
Since PHP 8 is now released, is it time to drop support for PHP < 7.0 and merge this in? |
…-coding-standard-236 [Imported] AC-940: Create unit test for Magento2\Less\BracesFormattingSniff check
This comment was marked as outdated.
This comment was marked as outdated.
This is not true. |
Sorry, I was wrong. I've marked my comment as hidden to avoid confusion going forward. Thanks for calling this out. |
Rule
All new PHP files MUST have strict type mode enabled by starting with
declare(strict_types=1)
;. All updated PHP files SHOULD have strict type mode enabled. PHP interfaces SHOULD NOT have this declaration.Reason
Source: Magento Technical Guidelines.
With PHP 7, it is possible to add type hinting to your code. However, this doesn't mean that types are actually enforced, unless strict typing is enabled by adding
declare(strict_types=1)
to the top of each PHP file.PHP code becomes more robust when type hinting (argument types, return types) are added. With the
declare(strict_types=1)
added, there is less chance for bugs that related to type casting.Implementation
Please refer to ExtDN an generic PHP CodeSniffer (not merged yet) implementations.
Important details
This sniff should be applicable to Magento >=2.2, because older versions of Magento supports PHP 5.5 and 5.6.
Follow the discussion about version specific sniffs for more details.
The text was updated successfully, but these errors were encountered: