-
Notifications
You must be signed in to change notification settings - Fork 8
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is definitely a step forward!
I've noted a few questions I have on some of the sniffs, as well as a few I disagree with.
src/ZendCodingStandard/ruleset.xml
Outdated
is_double => is_float, | ||
is_integer => is_int, | ||
is_long => is_int, | ||
is_null => null, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens when this fix is applied? Seems like it might break code, unless null
here means null ===
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to look into this what it exactly does, but I think it is replaced with null ===
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does not replace the functions. It only displays an error:
19 | ERROR | The use of function chop() is forbidden; use rtrim()
| | instead
20 | ERROR | The use of function sizeof() is forbidden; use count()
| | instead
21 | ERROR | The use of function is_null() is forbidden
23 | ERROR | The use of function settype() is forbidden
30 | ERROR | The use of function extract() is forbidden
31 | ERROR | The use of function compact() is forbidden
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
null means there is no alternative. is_null
should be replaced with null ===
but changing this to that value gives the following error:
21 | ERROR | The use of function is_null() is forbidden; use 'null
| | ==='() instead
That looks like a weird function or so.
src/ZendCodingStandard/ruleset.xml
Outdated
<!-- Forbid backtick operator --> | ||
<rule ref="Generic.PHP.BacktickOperator"/> | ||
<!-- Forbid short open tag --> | ||
<rule ref="Generic.PHP.DisallowShortOpenTag"/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this disallow <?=
? I ask, as this is valid always starting in 5.4 or 5.5, and we recommend it for templates. If it doesn't, we're good; if it does, is there a way to make an exception for <?=
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if this can be used to validate templates. I've never tried it. But yes, if phpcs works with templates then it should be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The question is whether or not it flags <?=
as invalid. If it doesn't, we're fine. :)
src/ZendCodingStandard/ruleset.xml
Outdated
@category, | ||
@created, | ||
@package, | ||
@since, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this one considered forbidden? It's useful for noting API additions...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the reasoning behind it is that all info is in git log and the changelog. But I'll remove it since it's easy to look it up directly in the code where most developers look anyway.
src/ZendCodingStandard/ruleset.xml
Outdated
<!-- Require comments with single line written as one-liners --> | ||
<rule ref="SlevomatCodingStandard.Commenting.RequireOneLinePropertyDocComment"/> | ||
<!-- Forbid fancy yoda conditions --> | ||
<rule ref="SlevomatCodingStandard.ControlStructures.DisallowYodaComparison"/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Disagree with this one; we use (null|false|true) [!=]== <expression>
all over the place as a defensive programming approach.
<!-- Require the usage of assignment operators, eg `+=`, `.=` when possible --> | ||
<rule ref="SlevomatCodingStandard.Operators.RequireCombinedAssignmentOperator"/> | ||
<!-- Forbid `list(...)` syntax, use [...] instead --> | ||
<rule ref="SlevomatCodingStandard.PHP.ShortList"/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one will only work for libraries on PHP 7+; for those on 5.5, we'd need to disable this rule.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea is to tag this release 2.0 and include it ^7.1
packages. I don't see why we need to fix code for old packages. That's a lot of extra work and commits.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough!
src/ZendCodingStandard/ruleset.xml
Outdated
</properties> | ||
</rule> | ||
<!-- Forbid useless @var for constants --> | ||
<rule ref="SlevomatCodingStandard.TypeHints.UselessConstantTypeHint"/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I disagree with this one. The proposed phpdoc spec specifically states @var is the appropriate tag for use with constants.
src/ZendCodingStandard/ruleset.xml
Outdated
<!-- Forbid `global` --> | ||
<rule ref="Squiz.PHP.GlobalKeyword"/> | ||
<!-- Forbid functions inside functions --> | ||
<rule ref="Squiz.PHP.InnerFunctions"/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why? This is a valid way to make private functions...
mkdocs.yml
Outdated
site_name: Zend Coding Standard | ||
site_description: 'The coding standard ruleset for Zend Framework components.' | ||
repo_url: 'https://github.com/zendframework/zend-coding-standard' | ||
copyright: 'Copyright (c) 2016-2018 <a href="https://www.zend.com/">Zend Technologies USA Inc.</a>' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line can be removed, because this is not used in theme.
docs/book/index.html
Outdated
@@ -0,0 +1,9 @@ | |||
<div class="container"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the entire file, the same content is generated by the theme.
.travis.yml
Outdated
apt: | ||
packages: | ||
- libxml2-utils | ||
script: xmllint --noout --schema vendor/squizlabs/php_codesniffer/phpcs.xsd src/ZendCodingStandard/ruleset.xml |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice! 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Documentation proposal looks good! 👍
This is a very long list with a lot of useless info. Maybe a PHP-FIG PSR-2 style guide is better.
(i.e. \DateTimeImmutable)
Rule: All PHP files MUST use the Unix LF (linefeed) line ending only.
Caused warnings in zend-diactoros like: `Consider putting global function "parseCookieHeader" in a static class.`
Doing open source while sitting on the backseat with 200 kmh on the Autobahn :)
Using Squiz, Slevomat, General rules or a combination of those doesn't work and it becomes a mess really fast. The WebimpressCodingStandard has better rules for this, however they need some improvements.
Merged into develop |
This PR adds a stricter ruleset. #1 is adding a lot of extra code and custom rules which are hard to maintain and it's so huge that it is hard to review. The huge amount of work done in #1 is not lost and is moved to webimpress/coding-standard.
The purpose of this PR is to start over and importing rules from other packages where possible.
phpcs -s --standard=ZendCodingStandard src
CHANGELOG.md
entryBlocked by:
Poll: To align or not to align!ReferenceViaFallbackGlobalName is importing functions from the same namespace slevomat/coding-standard#477fixed in 4.8.0UselessParentheses removes also usefull parentheses in dev-master (4.8.0) slevomat/coding-standard#478fixed in 4.8.0Aligning double arrows in arraysTesting
Make sure you remove the global installation after testing from your global composer.json file!!!