-
Notifications
You must be signed in to change notification settings - Fork 153
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
[Proposal] Version specific sniffs #17
Comments
Simple and efficient. I was personally thinking along the same line because I would like to see this version check right in the PHP code of the sniff itself. However, there are some alternatives (on top of this option 1 that you have documented) that are maybe nice to mention here for the purpose of a debate:
Option 2 leads to "invisibility" of the rules, in my opinion. Option 3 is nice but maybe leads to too many rulesets, while it also splits up the sniffs functionality (PHP class) and its compatibility (XML). Your option 1 combines both functionality and compatibility in one single place (PHP class). I'm personally in favour of option 1 (as suggested by you). Off-topic suggestion A: Make Off-topic suggestion B: Make it even easier for sniffs to reuse the Off-topic suggestion C: You mentioned that |
@jissereitsma
Now I'm thinking about public property, because in this case we can change the property value in the
😄 It was exactly what I wrote before, but the idea of Composition over Inheritance didn't leave my head so I changed to this. I think, you're right. The simplest approach here makes more sense.
Yes, it's correct. It's just a bad example. |
I have no objection against making As for the examle, the |
Maybe to throw some SOLID at it: The responsibility for the |
Hi @jissereitsma, a |
Thanks for the suggestion. I like the initial option the most as long as the "is-sniff-relevant-for-version-check" is not implemented in each and every sniff as already discussed. Regarding the cons:
IMHO, this is not too bad since usually, one develops for the latest version of Magento, so that the default behavior should be okay.
Not sure that you mean by that @lenaorobei. If a specific sniff just makes sense until e.g. version 2.1 and version 2.1 becomes EOL, we should simply delete this sniff. Of course this is still maintenance work, but since it is just deleting, it should not be too hard. Another thing to think of is a |
@sprankhub that's a good point. Based on our comments and suggestions, the implementation can be following. trait VersionHandler
{
public function isRelevant($introducedIn, $deprecatedIn = '')
{
$runtimeVersion = Config::getConfigData('magentoVersion');
if (($runtimeVersion === null) && ($deprecatedIn !== '')) {
return false;
}
if ($runtimeVersion !== null) {
$isGreaterOrEquals = version_compare($runtimeVersion, $introducedIn, '>=');
if ($deprecatedIn !== '') {
return $isGreaterThan && version_compare($runtimeVersion, $deprecatedIn, '<');
}
return $isGreaterOrEquals;
}
return true;
}
} Note: class SomeNewlyIntroducedSniff implements Sniff
{
use VersionHandler;
public $introducedIn = '2.0';
public $deprecatedIn = '2.3';
public function process(File $phpcsFile, $stackPtr)
{
if ($this->isRelevant($this->introducedIn, $this->deprecatedIn) === false) {
return;
}
//code goes here
}
} |
@lenaorobei this implementation looks good 👍 |
My 2 cents:
|
Hi |
…-coding-standard-216 [Imported] Run tests for all file types
Problem Overview
Some of the rules like
strict_types
were introduced in later Magento versions and are not applicable to earlier ones. Magento Marketplace still checks the code of extensions compatible with Magento 2.0, 2.1, 2.2. How to handle version specific rules?Solution
Provide mechanism of version specific sniffs using OOB PHP CodeSniffer functionality. By default PHP CodeSniffer will do check assuming the latest Magento version.
Implementation Details
Create new sniffs Group which will handle runtime parameter
magentoVersion
and run sniff only when it meets version requirement.For example
phpcs --runtime-set magentoVersion 2.2
Each sniff from version specific group will call
doRun
method that checks versions compatibiliy.Magento version specific sniff will contain code that determines whether the sniff needs to be executed.
Pros
Cons
The text was updated successfully, but these errors were encountered: