Skip to content

Commit 1e77b4e

Browse files
committed
Merge branch 'feature/issue-1152-trait-naming-conventions' of https://github.com/jrfnl/PHP_CodeSniffer
2 parents 43b8f6a + 03d24fd commit 1e77b4e

File tree

6 files changed

+138
-8
lines changed

6 files changed

+138
-8
lines changed

CodeSniffer/Standards/PEAR/Sniffs/NamingConventions/ValidClassNameSniff.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public function register()
4242
return array(
4343
T_CLASS,
4444
T_INTERFACE,
45+
T_TRAIT,
4546
);
4647

4748
}//end register()

CodeSniffer/Standards/PEAR/Tests/NamingConventions/ValidClassNameUnitTest.inc

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,24 @@ class Invalid__Name {}
4545

4646
interface Invalid__Name {}
4747

48-
?>
48+
trait Valid_Name {}
49+
50+
trait invalid_Name {}
51+
52+
trait invalid_name {}
53+
54+
trait Invalid_name {}
55+
56+
trait VALID_Name {}
57+
58+
trait VALID_NAME {}
59+
60+
trait VALID_Name {}
61+
62+
trait ValidName {}
63+
64+
trait _Invalid_Name {}
65+
66+
trait ___ {}
67+
68+
trait Invalid__Name {}

CodeSniffer/Standards/PEAR/Tests/NamingConventions/ValidClassNameUnitTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ public function getErrorList()
5555
42 => 2,
5656
44 => 1,
5757
46 => 1,
58+
50 => 1,
59+
52 => 2,
60+
54 => 1,
61+
64 => 1,
62+
66 => 2,
63+
68 => 1,
5864
);
5965

6066
}//end getErrorList()

CodeSniffer/Standards/Squiz/Sniffs/Classes/ValidClassNameSniff.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public function register()
4141
return array(
4242
T_CLASS,
4343
T_INTERFACE,
44+
T_TRAIT,
4445
);
4546

4647
}//end register()

CodeSniffer/Standards/Squiz/Tests/Classes/ValidClassNameUnitTest.inc

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,91 @@ class Base
4848
};
4949
}
5050
}
51+
52+
// Valid interface name.
53+
interface ValidCamelCaseClass extends MyClass {}
54+
55+
56+
// Incorrect usage of camel case.
57+
interface invalidCamelCaseClass extends MyClass {}
58+
interface Invalid_Camel_Case_Class_With_Underscores implements MyClass {}
59+
60+
61+
// All lowercase.
62+
interface invalidlowercaseclass extends MyClass {}
63+
interface invalid_lowercase_class_with_underscores extends MyClass {}
64+
65+
66+
// All uppercase.
67+
interface VALIDUPPERCASECLASS extends MyClass {}
68+
interface INVALID_UPPERCASE_CLASS_WITH_UNDERSCORES extends MyClass {}
69+
70+
71+
// Mix camel case with uppercase.
72+
interface ValidCamelCaseClassWithUPPERCASE extends MyClass {}
73+
74+
75+
// Usage of numeric characters.
76+
interface ValidCamelCaseClassWith1Number extends MyClass {}
77+
interface ValidCamelCaseClassWith12345Numbers extends MyClass {}
78+
interface 5InvalidCamelCaseClassStartingWithNumber extends MyClass {}
79+
interface ValidCamelCaseClassEndingWithNumber5 extends MyClass {}
80+
interface 12345 extends MyClass {}
81+
82+
interface Testing{}
83+
84+
interface Base
85+
{
86+
protected $anonymous;
87+
88+
public function __construct();
89+
}
90+
91+
92+
// Valid trait name.
93+
trait ValidCamelCaseClass extends MyClass {}
94+
95+
96+
// Incorrect usage of camel case.
97+
trait invalidCamelCaseClass extends MyClass {}
98+
trait Invalid_Camel_Case_Class_With_Underscores implements MyClass {}
99+
100+
101+
// All lowercase.
102+
trait invalidlowercaseclass extends MyClass {}
103+
trait invalid_lowercase_class_with_underscores extends MyClass {}
104+
105+
106+
// All uppercase.
107+
trait VALIDUPPERCASECLASS extends MyClass {}
108+
trait INVALID_UPPERCASE_CLASS_WITH_UNDERSCORES extends MyClass {}
109+
110+
111+
// Mix camel case with uppercase.
112+
trait ValidCamelCaseClassWithUPPERCASE extends MyClass {}
113+
114+
115+
// Usage of numeric characters.
116+
trait ValidCamelCaseClassWith1Number extends MyClass {}
117+
trait ValidCamelCaseClassWith12345Numbers extends MyClass {}
118+
trait 5InvalidCamelCaseClassStartingWithNumber extends MyClass {}
119+
trait ValidCamelCaseClassEndingWithNumber5 extends MyClass {}
120+
trait 12345 extends MyClass {}
121+
122+
trait Testing{}
123+
124+
trait Base
125+
{
126+
protected $anonymous;
127+
128+
public function __construct()
129+
{
130+
$this->anonymous = new class extends ArrayObject
131+
{
132+
public function __construct()
133+
{
134+
parent::__construct(['a' => 1, 'b' => 2]);
135+
}
136+
};
137+
}
138+
}

CodeSniffer/Standards/Squiz/Tests/Classes/ValidClassNameUnitTest.php

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,27 @@ class Squiz_Tests_Classes_ValidClassNameUnitTest extends AbstractSniffUnitTest
4343
public function getErrorList()
4444
{
4545
return array(
46-
9 => 1,
47-
10 => 1,
48-
14 => 1,
49-
15 => 1,
50-
20 => 1,
51-
30 => 1,
52-
32 => 1,
46+
9 => 1,
47+
10 => 1,
48+
14 => 1,
49+
15 => 1,
50+
20 => 1,
51+
30 => 1,
52+
32 => 1,
53+
57 => 1,
54+
58 => 1,
55+
62 => 1,
56+
63 => 1,
57+
68 => 1,
58+
78 => 1,
59+
80 => 1,
60+
97 => 1,
61+
98 => 1,
62+
102 => 1,
63+
103 => 1,
64+
108 => 1,
65+
118 => 1,
66+
120 => 1,
5367
);
5468

5569
}//end getErrorList()

0 commit comments

Comments
 (0)