File tree Expand file tree Collapse file tree 14 files changed +106
-6
lines changed Expand file tree Collapse file tree 14 files changed +106
-6
lines changed Original file line number Diff line number Diff line change 58
58
<test name =" topLevelVariableNaming" regexp =" /^[a-z_][a-zA-Z0-9]*$/" /> <!-- for top level variables -->
59
59
<test name =" localVariableNaming" regexp =" /^[a-z_][a-zA-Z0-9]*$/" /> <!-- for local variables (inside a class) -->
60
60
<test name =" memberVariableNaming" regexp =" /^[a-z_][a-zA-Z0-9]*$/" /> <!-- for member variables (inside a function) -->
61
+ <test name =" functionParameterNaming" regexp =" /^[a-z_][a-zA-Z0-9]*$/" /> <!-- for function parameters -->
61
62
62
63
<!-- Check Function Naming -->
63
64
<test name =" functionNaming" regexp =" /^[a-z][a-zA-Z0-9]*$/" level =" error" />
Original file line number Diff line number Diff line change 58
58
<test name =" topLevelVariableNaming" regexp =" /^[a-z_][a-zA-Z0-9]*$/" /> <!-- for top level variables -->
59
59
<test name =" localVariableNaming" regexp =" /^[a-z_][a-zA-Z0-9]*$/" /> <!-- for local variables (inside a class) -->
60
60
<test name =" memberVariableNaming" regexp =" /^[a-z_][a-zA-Z0-9]*$/" /> <!-- for member variables (inside a function) -->
61
+ <test name =" functionParameterNaming" regexp =" /^[a-z_][a-zA-Z0-9]*$/" /> <!-- for function parameters -->
61
62
62
63
<!-- Check Function Naming -->
63
64
<test name =" functionNaming" regexp =" /^[a-z][a-zA-Z0-9]*$/" level =" error" />
Original file line number Diff line number Diff line change 58
58
<test name =" topLevelVariableNaming" regexp =" /^[a-z_][a-zA-Z0-9]*$/" /> <!-- for top level variables -->
59
59
<test name =" localVariableNaming" regexp =" /^[a-z_][a-zA-Z0-9]*$/" /> <!-- for local variables (inside a class) -->
60
60
<test name =" memberVariableNaming" regexp =" /^[a-z_][a-zA-Z0-9]*$/" /> <!-- for member variables (inside a function) -->
61
+ <test name =" functionParameterNaming" regexp =" /^[a-z_][a-zA-Z0-9]*$/" /> <!-- for function parameters -->
61
62
62
63
<!-- Check Function Naming -->
63
64
<test name =" functionNaming" regexp =" /^[a-z][a-zA-Z0-9]*$/" level =" error" />
Original file line number Diff line number Diff line change 58
58
<test name =" topLevelVariableNaming" regexp =" /^[a-z_][a-zA-Z0-9]*$/" /> <!-- for top level variables -->
59
59
<test name =" localVariableNaming" regexp =" /^[a-z_][a-zA-Z0-9]*$/" /> <!-- for local variables (inside a class) -->
60
60
<test name =" memberVariableNaming" regexp =" /^[a-z_][a-zA-Z0-9]*$/" /> <!-- for member variables (inside a function) -->
61
+ <test name =" functionParameterNaming" regexp =" /^[a-z_][a-zA-Z0-9]*$/" /> <!-- for function parameters -->
61
62
62
63
<!-- Check Function Naming -->
63
64
<test name =" functionNaming" regexp =" /^[a-z][a-zA-Z0-9]*$/" level =" error" />
Original file line number Diff line number Diff line change 61
61
<test name =" topLevelVariableNaming" regexp =" /^[a-z_][a-zA-Z0-9]*$/" /> <!-- for top level variables -->
62
62
<test name =" localVariableNaming" regexp =" /^[a-z_][a-zA-Z0-9]*$/" /> <!-- for local variables (inside a class) -->
63
63
<test name =" memberVariableNaming" regexp =" /^[a-z_][a-zA-Z0-9]*$/" /> <!-- for member variables (inside a function) -->
64
+ <test name =" functionParameterNaming" regexp =" /^[a-z_][a-zA-Z0-9]*$/" /> <!-- for function parameters -->
64
65
65
66
<!-- Check Function Naming -->
66
67
<test name =" functionNaming" regexp =" /^[a-z][a-zA-Z0-9]*$/" level =" error" />
Original file line number Diff line number Diff line change 58
58
<test name =" topLevelVariableNaming" regexp =" /^[a-z_][a-zA-Z0-9]*$/" /> <!-- for top level variables -->
59
59
<test name =" localVariableNaming" regexp =" /^[a-z_][a-zA-Z0-9]*$/" /> <!-- for local variables (inside a class) -->
60
60
<test name =" memberVariableNaming" regexp =" /^[a-z_][a-zA-Z0-9]*$/" /> <!-- for member variables (inside a function) -->
61
+ <test name =" functionParameterNaming" regexp =" /^[a-z_][a-zA-Z0-9]*$/" /> <!-- for function parameters -->
61
62
62
63
<!-- Check Function Naming -->
63
64
<test name =" functionNaming" regexp =" /^[a-z][a-zA-Z0-9]*$/" level =" error" />
Original file line number Diff line number Diff line change 61
61
<test name =" topLevelVariableNaming" regexp =" /^[a-z_][a-zA-Z0-9]*$/" /> <!-- for top level variables -->
62
62
<test name =" localVariableNaming" regexp =" /^[a-z_][a-zA-Z0-9]*$/" /> <!-- for local variables (inside a class) -->
63
63
<test name =" memberVariableNaming" regexp =" /^[a-z_][a-zA-Z0-9]*$/" /> <!-- for member variables (inside a function) -->
64
+ <test name =" functionParameterNaming" regexp =" /^[a-z_][a-zA-Z0-9]*$/" /> <!-- for function parameters -->
64
65
65
66
<!-- Check Function Naming -->
66
67
<test name =" functionNaming" regexp =" /^[a-z][a-zA-Z0-9]*$/" level =" error" />
Original file line number Diff line number Diff line change 1
1
<phpunit bootstrap =" ./test/TestRunner.php" colors =" true" >
2
2
3
3
<testsuite name =" PHPUnitTestSuite" >
4
- <file >./test/AliasesTest.php</file >
4
+ <!-- < file>./test/AliasesTest.php</file>
5
5
<file>./test/CommentsTest.php</file>
6
6
<file>./test/DeprecationTest.php</file>
7
7
<file>./test/GoodTest.php</file>
8
8
<file>./test/IndentationTest.php</file>
9
- <file >./test/MetricsTest.php</file >
9
+ <file>./test/MetricsTest.php</file> -->
10
10
<file >./test/NamingTest.php</file >
11
- <file >./test/OptimizationTest.php</file >
11
+ <!-- < file>./test/OptimizationTest.php</file>
12
12
<file>./test/OtherTest.php</file>
13
13
<file>./test/PHPTagsTest.php</file>
14
14
<file>./test/ProhibitedTest.php</file>
15
15
<file>./test/StrictCompareTest.php</file>
16
- <file >./test/UnusedTest.php</file >
16
+ <file>./test/UnusedTest.php</file> -->
17
17
</testsuite >
18
18
19
19
<filter >
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ CONSTANT_NAMING="Constant %s name should follow the pattern %s."
16
16
VARIABLE_NAMING =" Variable %s name should follow the pattern %s."
17
17
LOCAL_VARIABLE_NAMING =" Local variable %s name should follow the pattern %s."
18
18
MEMBER_VARIABLE_NAMING =" Member variable %s name should follow the pattern %s."
19
+ FUNCTION_PARAMETER_NAMING =" Function parameter %s name should follow the pattern %s."
19
20
TOPLEVEL_VARIABLE_NAMING =" Top level variable %s name should follow the pattern %s."
20
21
FUNCNAME_SPACE_AFTER =" Whitespace must not be between the function %s and the opening brace '{'."
21
22
PRIVATE_FUNCNAME_NAMING =" Private function %s name should follow the pattern %s."
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ CONSTANT_NAMING="Le nom de la constante %s devrait suivre le pattern %s."
16
16
VARIABLE_NAMING =" Le nom de la variable %s devrait suivre le pattern %s."
17
17
LOCAL_VARIABLE_NAMING =" Le nom de la variable locale %s devrait suivre le pattern %s."
18
18
MEMBER_VARIABLE_NAMING =" Le nom de la variable de classe %s devrait suivre le pattern %s."
19
+ FUNCTION_PARAMETER_NAMING =" Le nom du paramètre de fonction %s devrait suivre le pattern %s."
19
20
TOPLEVEL_VARIABLE_NAMING =" Le nom de la variable globale %s devrait suivre le pattern %s."
20
21
FUNCNAME_SPACE_AFTER =" Supprimer l'espace entre le nom de fonction %s et la parenthèse ouvrante '{'."
21
22
PRIVATE_FUNCNAME_NAMING =" Le nom de la fonction privée %s devrait suivre le pattern %s."
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ CONSTANT_NAMING = "상수 %s 이름은 %s 패턴을 따라야합니다."
16
16
VARIABLE_NAMING = " 변수 %s 이름은 %s 패턴을 따라야합니다."
17
17
LOCAL_VARIABLE_NAMING = " 로컬 변수 %s 의 이름이 %s 패턴을 따라야합니다."
18
18
MEMBER_VARIABLE_NAMING = " 멤버 변수 %s 의 이름이 %s 패턴을 따라야합니다."
19
+ FUNCTION_PARAMETER_NAMING = " 멤버 변수 %s 의 이름이 %s 패턴을 따라야합니다."
19
20
TOPLEVEL_VARIABLE_NAMING = " 최상위 변수 %s 이름이 %s 패턴을 따라야합니다."
20
21
FUNCNAME_SPACE_AFTER = " 공백은 함수 %s 와 여는 중괄호 '{' 사이에 있어서는 안됩니다."
21
22
PRIVATE_FUNCNAME_NAMING = " Private 함수 %s 이름이 %s 패턴을 따라야합니다."
Original file line number Diff line number Diff line change @@ -1543,8 +1543,14 @@ private function _checkConstantNaming($text) {
1543
1543
*/
1544
1544
private function _checkVariableNaming ($ text ) {
1545
1545
if ($ this ->_inClass || $ this ->_inInterface ) {
1546
- if ($ this ->_inFunction || $ this ->_inFunctionStatement || $ this ->_inInterfaceStatement ) {
1547
- $ this ->_checkScopedVariableNaming ($ text , 'localVariableNaming ' , 'LOCAL_VARIABLE_NAMING ' );
1546
+ if ($ this ->_inFunctionStatement || $ this ->_inInterfaceStatement ) {
1547
+ $ this ->_checkScopedVariableNaming ($ text , 'functionParameterNaming ' , 'FUNCTION_PARAMETER_NAMING ' );
1548
+ } else if ($ this ->_inFunction ) {
1549
+ if (in_array ($ text , $ this ->_functionParameters )) {
1550
+ $ this ->_checkScopedVariableNaming ($ text , 'functionParameterNaming ' , 'FUNCTION_PARAMETER_NAMING ' );
1551
+ } else {
1552
+ $ this ->_checkScopedVariableNaming ($ text , 'localVariableNaming ' , 'LOCAL_VARIABLE_NAMING ' );
1553
+ }
1548
1554
} else {
1549
1555
$ this ->_checkScopedVariableNaming ($ text , 'memberVariableNaming ' , 'MEMBER_VARIABLE_NAMING ' );
1550
1556
}
Original file line number Diff line number Diff line change @@ -25,5 +25,29 @@ public function testNaming() {
25
25
$ this ->assertEquals (0 , $ errorCounts ['info ' ], 'We expect 0 info ' );
26
26
$ this ->assertEquals (5 , $ errorCounts ['warning ' ], 'We expect 5 warnings ' );
27
27
}
28
+
29
+
30
+
31
+
32
+ /**
33
+ * Test function naming rules.
34
+ */
35
+ public function testFunctionNaming () {
36
+ $ phpcheckstyle = $ GLOBALS ['PHPCheckstyle ' ];
37
+
38
+ // Change the default configuration, function parameters should start with "_"
39
+ $ phpcheckstyle ->getConfig ()->setTestProperty ('functionParameterNaming ' , 'regexp ' , "/^[_][a-zA-Z0-9]*$/ " );
40
+
41
+ $ phpcheckstyle ->processFiles (array (
42
+ './test/sample/good_function_naming.php '
43
+ ));
44
+
45
+ $ errorCounts = $ phpcheckstyle ->getErrorCounts ();
46
+
47
+ $ this ->assertEquals (0 , $ errorCounts ['error ' ], 'We expect 0 errors of naming ' );
48
+ $ this ->assertEquals (0 , $ errorCounts ['ignore ' ], 'We expect 0 ignored checks ' );
49
+ $ this ->assertEquals (0 , $ errorCounts ['info ' ], 'We expect 0 info ' );
50
+ $ this ->assertEquals (0 , $ errorCounts ['warning ' ], 'We expect 0 warnings ' );
51
+ }
28
52
}
29
53
?>
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ /**
4
+ * This file is an exemple of PHP file containing good naming with specific rule for function parameters.
5
+ */
6
+
7
+ // constant naming :: PHPCHECKSTYLE_CONSTANT_NAMING
8
+ define (NAMED_CONSTANT , "A_CONSTANT_VALUE " );
9
+
10
+ // constant naming :: PHPCHECKSTYLE_CONSTANT_NAMING
11
+ const CONSTANT = "CONSTANT " ;
12
+
13
+ // top level var naming :: PHPCHECKSTYLE_TOPLEVEL_VARIABLE_NAMING
14
+ $ foo = 1 ;
15
+
16
+ //
17
+ /**
18
+ * class naming :: PHPCHECKSTYLE_CLASSNAME_NAMING
19
+ *
20
+ * @SuppressWarnings checkUnusedVariables
21
+ */
22
+ class NamedClass {
23
+
24
+ // member level var naming :: PHPCHECKSTYLE_MEMBER_VARIABLE_NAMING
25
+ var $ bar = 1 ;
26
+
27
+ /**
28
+ * constructor Naming
29
+ */
30
+ function __construct () {}
31
+
32
+ /**
33
+ * function naming :: PHPCHECKSTYLE_FUNCNAME_NAMING
34
+ *
35
+ * @param $_myparam a param
36
+ */
37
+ function namedFunction ($ _myparam ) {
38
+
39
+ // local level var naming :: PHPCHECKSTYLE_LOCAL_VARIABLE_NAMING
40
+ $ fuu = 1 ;
41
+
42
+ $ _myparam = 0 ;
43
+ }
44
+ }
45
+
46
+ /**
47
+ * interface naming
48
+ */
49
+ interface MyInterface {
50
+
51
+ /**
52
+ * function naming :: PHPCHECKSTYLE_FUNCNAME_NAMING
53
+ *
54
+ * @param $_name a name
55
+ * @param $_var a var
56
+ */
57
+ public function setVariable ($ _name , $ _var );
58
+ }
59
+
60
+
You can’t perform that action at this time.
0 commit comments