Skip to content

Commit 641462e

Browse files
committed
Remove PrivateNoUnderscore since it's ancient and nobody writes php like that
1 parent 4457275 commit 641462e

File tree

2 files changed

+8
-19
lines changed

2 files changed

+8
-19
lines changed

src/Cdn77/Sniffs/NamingConventions/ValidVariableNameSniff.php

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -144,18 +144,13 @@ protected function processMemberVar(File $phpcsFile, $stackPtr): void
144144
$public = ($memberProps['scope'] !== 'private');
145145
$errorData = [$varName];
146146

147-
if ($public === true) {
148-
if (strpos($varName, '_') === 0) {
149-
$error = '%s member variable "%s" must not contain a leading underscore';
150-
$data = [
151-
ucfirst($memberProps['scope']),
152-
$errorData[0],
153-
];
154-
$phpcsFile->addError($error, $stackPtr, 'PublicHasUnderscore', $data);
155-
}
156-
} elseif (strpos($varName, '_') !== 0) {
157-
$error = 'Private member variable "%s" must contain a leading underscore';
158-
$phpcsFile->addError($error, $stackPtr, 'PrivateNoUnderscore', $errorData);
147+
if (($public === true) && strpos($varName, '_') === 0) {
148+
$error = '%s member variable "%s" must not contain a leading underscore';
149+
$data = [
150+
ucfirst($memberProps['scope']),
151+
$errorData[0],
152+
];
153+
$phpcsFile->addError($error, $stackPtr, 'PublicHasUnderscore', $data);
159154
}
160155

161156
// Remove a potential underscore prefix for testing CamelCaps.

tests/Sniffs/NamingConventions/ValidVariableNameSniffTest.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ class ValidVariableNameSniffTest extends TestCase
1717
public const CODE_NOT_CAMEL_CAPS = 'NotCamelCaps';
1818
public const CODE_MEMBER_NOT_CAMEL_CAPS = 'MemberNotCamelCaps';
1919
public const CODE_PUBLIC_HAS_UNDERSCORE = 'PublicHasUnderscore';
20-
public const CODE_PRIVATE_NO_UNDERSCORE = 'PrivateNoUnderscore';
2120
public const CODE_STRING_NOT_CAMEL_CAPS = 'StringNotCamelCaps';
2221

2322
public function testErrors(): void
@@ -34,7 +33,6 @@ public function testErrors(): void
3433
20 => self::CODE_MEMBER_NOT_CAMEL_CAPS,
3534
22 => self::CODE_PUBLIC_HAS_UNDERSCORE,
3635
25 => self::CODE_MEMBER_NOT_CAMEL_CAPS,
37-
27 => self::CODE_PRIVATE_NO_UNDERSCORE,
3836
31 => self::CODE_NOT_CAMEL_CAPS,
3937
33 => self::CODE_NOT_CAMEL_CAPS,
4038
36 => self::CODE_STRING_NOT_CAMEL_CAPS,
@@ -52,10 +50,6 @@ public function testErrors(): void
5250
106 => self::CODE_PUBLIC_HAS_UNDERSCORE,
5351
107 => self::CODE_PUBLIC_HAS_UNDERSCORE,
5452
108 => self::CODE_PUBLIC_HAS_UNDERSCORE,
55-
111 => self::CODE_PRIVATE_NO_UNDERSCORE,
56-
112 => self::CODE_PRIVATE_NO_UNDERSCORE,
57-
113 => self::CODE_PRIVATE_NO_UNDERSCORE,
58-
114 => self::CODE_PRIVATE_NO_UNDERSCORE,
5953
123 => self::CODE_PUBLIC_HAS_UNDERSCORE,
6054
138 => self::CODE_NOT_CAMEL_CAPS,
6155
141 => self::CODE_NOT_CAMEL_CAPS,
@@ -79,6 +73,6 @@ public function testErrors(): void
7973
}
8074
}
8175

82-
self::assertSame(38, $file->getErrorCount());
76+
self::assertSame(33, $file->getErrorCount());
8377
}
8478
}

0 commit comments

Comments
 (0)