-
Notifications
You must be signed in to change notification settings - Fork 3
Add Cyrillic Sniff, method call consistency rule, namespace consistency rule #22
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
Conversation
config/phpstan.services.neon
Outdated
| - | ||
| class: \FiveLab\Component\CiRules\PhpStan\MethodCallConsistencyRule | ||
| arguments: | ||
| - @reflectionProvider |
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.
Use only one parameter, so that the code is the same please use one line for arguments.
| use PHP_CodeSniffer\Files\File; | ||
| use PHP_CodeSniffer\Sniffs\Sniff; | ||
|
|
||
| class CyrillicSniff implements Sniff |
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 sniff should check only ASCII codes, without any cyrillic map, because must only support ASCII printable characters (character code 32-127).
| public function register(): array | ||
| { | ||
| return [ | ||
| T_VARIABLE, |
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.
PHP not allow use special chars on variables, interfaces, classes.
| use PHPStan\Analyser\Scope; | ||
| use PHPStan\Rules\Rule; | ||
|
|
||
| class NamespaceConsistencyRule implements 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.
phpstan more checks logic, but not strings, correct names, etc... As result, for this we should add phpcs rule, not phpstan.
| __DIR__.'/Resources/cyrillic/wrong.php', | ||
| [ | ||
| //phpcs:ignore | ||
| 'message' => 'Use cyrillic symbols 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.
We can't use cyrillic. For test, please use ord function.
| $className, | ||
| $methodReflection->getName() | ||
| )) | ||
| ->identifier('methodCallConsistency.error') |
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.
We use methodCall namespace. As result, please set methodCall.consistency
| $className, | ||
| $methodReflection->getName() | ||
| )) | ||
| ->identifier('methodCallConsistency.error') |
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.
see comment above
src/PhpCs/FiveLab/ErrorCodes.php
Outdated
| public const LINE_AFTER_NOT_ALLOWED = 'LineAfterNotAllowed'; | ||
| public const LINE_BEFORE_NOT_ALLOWED = 'LineBeforeNotAllowed'; | ||
| public const MISSED_CONSTANT_TYPE = 'MissedConstantType'; | ||
| public const NAMESPACE_WRONG = 'NamespaceWrong'; |
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.
Please align all constants.
| $content = $tokens[$stackPtr]['content']; | ||
| $forbiddenSymbols = []; | ||
|
|
||
| foreach (mb_str_split($content) as $char) { |
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.
Should be \ before call function in global namespace. And please check this moment below.
No description provided.