Skip to content

Commit 0ac027f

Browse files
rodrigoprimojrfnl
authored andcommitted
Generic/UpperCaseConstantName: minor improvement to the error message and metrics
This commit implements a minor improvement to the error message and metric recording when handling calls to `define()`. Now the line of the error or the line recorded in the metric will be the line of the constant name. Before it was the line of the T_DEFINE token.
1 parent 66837c3 commit 0ac027f

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/Standards/Generic/Sniffs/NamingConventions/UpperCaseConstantNameSniff.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,19 +133,19 @@ public function process(File $phpcsFile, $stackPtr)
133133

134134
if (strtoupper($constName) !== $constName) {
135135
if (strtolower($constName) === $constName) {
136-
$phpcsFile->recordMetric($stackPtr, 'Constant name case', 'lower');
136+
$phpcsFile->recordMetric($constPtr, 'Constant name case', 'lower');
137137
} else {
138-
$phpcsFile->recordMetric($stackPtr, 'Constant name case', 'mixed');
138+
$phpcsFile->recordMetric($constPtr, 'Constant name case', 'mixed');
139139
}
140140

141141
$error = 'Constants must be uppercase; expected %s but found %s';
142142
$data = [
143143
$prefix.strtoupper($constName),
144144
$prefix.$constName,
145145
];
146-
$phpcsFile->addError($error, $stackPtr, 'ConstantNotUpperCase', $data);
146+
$phpcsFile->addError($error, $constPtr, 'ConstantNotUpperCase', $data);
147147
} else {
148-
$phpcsFile->recordMetric($stackPtr, 'Constant name case', 'upper');
148+
$phpcsFile->recordMetric($constPtr, 'Constant name case', 'upper');
149149
}
150150

151151
}//end process()

src/Standards/Generic/Tests/NamingConventions/UpperCaseConstantNameUnitTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function getErrorList()
4141
40 => 1,
4242
41 => 1,
4343
45 => 1,
44-
47 => 1,
44+
51 => 1,
4545
];
4646

4747
}//end getErrorList()

0 commit comments

Comments
 (0)