From e7898e2237bc4d51219bd19eed4893ede4b591a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaroslav=20Hansl=C3=ADk?= Date: Tue, 13 Dec 2022 14:56:12 +0100 Subject: [PATCH] SlevomatCodingStandard.Attributes.AttributeAndTargetSpacing: Fixed fixer --- .../Sniffs/Attributes/AttributeAndTargetSpacingSniff.php | 5 ++++- .../Attributes/AttributeAndTargetSpacingSniffTest.php | 4 +++- .../data/attributeAndTargetSpacingErrors.fixed.php | 8 ++++++++ .../Attributes/data/attributeAndTargetSpacingErrors.php | 6 ++++++ 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/SlevomatCodingStandard/Sniffs/Attributes/AttributeAndTargetSpacingSniff.php b/SlevomatCodingStandard/Sniffs/Attributes/AttributeAndTargetSpacingSniff.php index 73c196607..3443db635 100644 --- a/SlevomatCodingStandard/Sniffs/Attributes/AttributeAndTargetSpacingSniff.php +++ b/SlevomatCodingStandard/Sniffs/Attributes/AttributeAndTargetSpacingSniff.php @@ -84,7 +84,10 @@ public function process(File $phpcsFile, $attributeOpenerPointer): void } if ($areOnSameLine) { - $indentation = IndentationHelper::getIndentation($phpcsFile, $attributeOpenerPointer); + $indentation = IndentationHelper::getIndentation( + $phpcsFile, + TokenHelper::findFirstNonWhitespaceOnLine($phpcsFile, $pointerAfter) + ); $phpcsFile->fixer->beginChangeset(); diff --git a/tests/Sniffs/Attributes/AttributeAndTargetSpacingSniffTest.php b/tests/Sniffs/Attributes/AttributeAndTargetSpacingSniffTest.php index 79f9075b4..13a387ca9 100644 --- a/tests/Sniffs/Attributes/AttributeAndTargetSpacingSniffTest.php +++ b/tests/Sniffs/Attributes/AttributeAndTargetSpacingSniffTest.php @@ -17,12 +17,14 @@ public function testErrors(): void { $report = self::checkFile(__DIR__ . '/data/attributeAndTargetSpacingErrors.php'); - self::assertSame(4, $report->getErrorCount()); + self::assertSame(6, $report->getErrorCount()); self::assertSniffError($report, 6, AttributeAndTargetSpacingSniff::CODE_INCORRECT_LINES_COUNT_BETWEEN_ATTRIBUTE_AND_TARGET); self::assertSniffError($report, 12, AttributeAndTargetSpacingSniff::CODE_INCORRECT_LINES_COUNT_BETWEEN_ATTRIBUTE_AND_TARGET); self::assertSniffError($report, 18, AttributeAndTargetSpacingSniff::CODE_INCORRECT_LINES_COUNT_BETWEEN_ATTRIBUTE_AND_TARGET); self::assertSniffError($report, 22, AttributeAndTargetSpacingSniff::CODE_INCORRECT_LINES_COUNT_BETWEEN_ATTRIBUTE_AND_TARGET); + self::assertSniffError($report, 28, AttributeAndTargetSpacingSniff::CODE_INCORRECT_LINES_COUNT_BETWEEN_ATTRIBUTE_AND_TARGET); + self::assertSniffError($report, 29, AttributeAndTargetSpacingSniff::CODE_INCORRECT_LINES_COUNT_BETWEEN_ATTRIBUTE_AND_TARGET); self::assertAllFixedInFile($report); } diff --git a/tests/Sniffs/Attributes/data/attributeAndTargetSpacingErrors.fixed.php b/tests/Sniffs/Attributes/data/attributeAndTargetSpacingErrors.fixed.php index c8d2a0873..2d86ee37b 100644 --- a/tests/Sniffs/Attributes/data/attributeAndTargetSpacingErrors.fixed.php +++ b/tests/Sniffs/Attributes/data/attributeAndTargetSpacingErrors.fixed.php @@ -21,4 +21,12 @@ public function method( { } + public function __construct( + #[ORM\Column(unique: true)] + protected string $name, + #[ORM\Cache] #[ORM\ManyToOne(targetEntity: 'State', inversedBy: 'cities')] #[ORM\JoinColumn(name: 'state_id', referencedColumnName: 'id')] + protected State|null $state = null, + ) { + } + } diff --git a/tests/Sniffs/Attributes/data/attributeAndTargetSpacingErrors.php b/tests/Sniffs/Attributes/data/attributeAndTargetSpacingErrors.php index 02d9bbf8d..65161e6bf 100644 --- a/tests/Sniffs/Attributes/data/attributeAndTargetSpacingErrors.php +++ b/tests/Sniffs/Attributes/data/attributeAndTargetSpacingErrors.php @@ -24,4 +24,10 @@ public function method( { } + public function __construct( + #[ORM\Column(unique: true)] protected string $name, + #[ORM\Cache] #[ORM\ManyToOne(targetEntity: 'State', inversedBy: 'cities')] #[ORM\JoinColumn(name: 'state_id', referencedColumnName: 'id')] protected State|null $state = null, + ) { + } + }