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

Prototype #25

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class DocCommentAlignmentSniff implements Sniff
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
* @return array<int|string>
*/
public function register()
{
Expand Down Expand Up @@ -82,6 +82,8 @@ public function process(File $phpcsFile, $stackPtr)
$ignore = [
T_CLASS => true,
T_INTERFACE => true,
T_ENUM => true,
T_ENUM_CASE => true,
T_FUNCTION => true,
T_PUBLIC => true,
T_PRIVATE => true,
Expand All @@ -92,6 +94,7 @@ public function process(File $phpcsFile, $stackPtr)
T_OBJECT => true,
T_PROTOTYPE => true,
T_VAR => true,
T_READONLY => true,
];

if ($nextToken === false || isset($ignore[$tokens[$nextToken]['code']]) === false) {
Expand Down Expand Up @@ -127,7 +130,12 @@ public function process(File $phpcsFile, $stackPtr)
}

if ($tokens[$i]['column'] !== $requiredColumn) {
$error = 'Expected %s space(s) before asterisk; %s found';
$pluralizeSpace = 's';
if (($requiredColumn - 1) === 1) {
$pluralizeSpace = '';
}

$error = 'Expected %s space%s before asterisk; %s found';
$data = [
($requiredColumn - 1),
($tokens[$i]['column'] - 1),
Expand All @@ -141,7 +149,7 @@ public function process(File $phpcsFile, $stackPtr)
$phpcsFile->fixer->replaceToken(($i - 1), $padding);
}
}
}
}//end if
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤯

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This for loop needs refactoring 😉


if ($tokens[$i]['code'] !== T_DOC_COMMENT_STAR) {
continue;
Expand All @@ -162,6 +170,7 @@ public function process(File $phpcsFile, $stackPtr)
&& $tokens[($i + 1)]['content'] !== ' '
&& strtolower(substr($tokens[($i + 1)]['content'], 0, 3)) !== '@oa'
&& strtolower(substr($tokens[($i + 2)]['content'], 0, 3)) !== '@oa'
&& !str_starts_with(strtolower($tokens[($i + 1)]['content']), '@orm')
Copy link
Contributor

@matthias-ruester matthias-ruester Feb 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why using brackets in all the index statements? $i + 1 should work as expected without using ()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this was just a core hack to learn if it helps solving your problem I wouldn't go too deep into that. ^

) {
$error = 'Expected 1 space after asterisk; %s found';
$data = [$tokens[($i + 1)]['length']];
Expand Down
Loading