~ubuntu-branches/ubuntu/vivid/php-codesniffer/vivid

« back to all changes in this revision

Viewing changes to PHP_CodeSniffer-1.5.5/CodeSniffer/Standards/PEAR/Tests/Functions/FunctionCallSignatureUnitTest.inc

  • Committer: Package Import Robot
  • Author(s): David Prévot, Greg Sherwood, Alexey, Emily, David Prévot
  • Date: 2014-09-26 13:44:35 UTC
  • mfrom: (1.1.6)
  • Revision ID: package-import@ubuntu.com-20140926134435-wvjq16miqq4d60y0
Tags: 1.5.5-1
[ Greg Sherwood ]
* Improved closure support in Generic ScopeIndentSniff
* Improved indented PHP tag support in Generic ScopeIndentSniff
* Standards can now be located within hidden directories
 (further fix for bug #20323)
* Fixed bug #20373 : Inline comment sniff tab handling way
* Fixed bug #20378 : Report appended to existing file if no errors
  found in run
* Fixed bug #20381 : Invalid "Comment closer must be on a new line"
* PHP tokenizer no longer converts class/function names to special
  tokens types
* Fixed bug #20386 : Squiz.Commenting.ClassComment.SpacingBefore
  thrown if first block comment
* Squiz and PEAR FunctionCommentSnif now support _()
* PEAR ValidFunctionNameSniff no longer throws an error for _()
* Fixed bug #248 : FunctionCommentSniff expects ampersand on param name
* Fixed bug #248 in Squiz sniff as well
* Fixed bug #265 : False positives with type hints in ForbiddenFunctionsSniff
* Prepare for 1.5.5 release

[ Alexey ]
* Allowed single undersored methods and functions

[ Emily ]
* Added var_dump to discouraged functions sniff

[ David Prévot ]
* Revert "Add XS-Testsuite still needed for ci.d.n"
* Add self to uploaders
* Bump standards version to 3.9.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php test(
 
2
);
 
3
test();
 
4
test($arg, $arg2);
 
5
test ();
 
6
test( );
 
7
test() ;
 
8
test( $arg);
 
9
test( $arg );
 
10
test ( $arg );
 
11
 
 
12
if (is_array($arg) === true) {
 
13
 
 
14
}
 
15
 
 
16
$something = get($arg1, $arg2);
 
17
$something = get($arg1, $arg2) ;
 
18
$something = get($arg1, $arg2)   ;
 
19
 
 
20
// No errors as this test only checks for function calls.
 
21
class TestClass extends MyClass
 
22
{
 
23
 
 
24
    const const1 = 'hello';
 
25
    const CONST2 = 'hello';
 
26
 
 
27
    public function test () { }
 
28
}
 
29
 
 
30
make_foo($string/*the string*/, true/*test*/);
 
31
make_foo($string/*the string*/, true/*test*/ );
 
32
make_foo($string /*the string*/, true /*test*/);
 
33
make_foo(/*the string*/$string, /*test*/true);
 
34
make_foo( /*the string*/$string, /*test*/true);
 
35
 
 
36
// No errors should be throw here because
 
37
// this is multi-line.
 
38
throw new Exception(
 
39
    'Exception text'
 
40
);
 
41
 
 
42
// Objects are the same as a normal call.
 
43
$obj = new TestClass( );
 
44
 
 
45
// Heredocs dont need to be indented.
 
46
method_call(
 
47
<<<EOH
 
48
Anyone want to recomment parse errors?
 
49
 
 
50
EOH
 
51
);
 
52
 
 
53
fputs(
 
54
    STDOUT,
 
55
    'Examples:
 
56
    $ {$app} --all
 
57
    $ {$app} --all');
 
58
 
 
59
fputs(STDOUT,
 
60
    "Examples:
 
61
    $ {$app} --all
 
62
    $ {$app} --all",
 
63
$something
 
64
    );
 
65
 
 
66
// This is not a function call.
 
67
function &testFunction($arg1,
 
68
    $arg2,
 
69
) {
 
70
}
 
71
 
 
72
$array = array();
 
73
array_map(
 
74
    function($x)
 
75
    {
 
76
        return trim($x);
 
77
    },
 
78
    $array
 
79
);
 
80
 
 
81
array_map(
 
82
     function($x)
 
83
     {
 
84
         return trim($x);
 
85
     },
 
86
    $array
 
87
);
 
88
 
 
89
$bar = new stdClass(
 
90
    4,
 
91
    5,
 
92
    6
 
93
   
 
94
);
 
95
 
 
96
$bar = new stdClass(
 
97
    4,
 
98
    5,
 
99
    6
 
100
 
 
101
);
 
102
 
 
103
$foo = new stdClass(
 
104
    1,
 
105
    2,
 
106
    3);
 
107
 
 
108
public function doSomething()
 
109
{
 
110
    return $this->getFoo()
 
111
        ->doBar(
 
112
            $this->getX() // no comma here
 
113
                ->doY()  // this is still the first method argument
 
114
                ->doZ()  // this is still the first method argument
 
115
        );
 
116
}
 
117
 
 
118
$var = myFunction(
 
119
$foo,
 
120
$bar
 
121
);
 
122
 
 
123
// @codingStandardsChangeSetting PEAR.Functions.FunctionCallSignature allowMultipleArguments false
 
124
 
 
125
fputs(
 
126
    STDOUT,
 
127
    "Examples:
 
128
    $ {$app} , --all
 
129
    $ {$app} --all", $something
 
130
);
 
131
 
 
132
$array = array();
 
133
array_map(
 
134
    function($x)
 
135
    {
 
136
        return trim($x, $y);
 
137
    }, $foo
 
138
    $array
 
139
);
 
140
 
 
141
$bar = new stdClass(
 
142
    4, 5, 6
 
143
);
 
144
 
 
145
public function doSomething()
 
146
{
 
147
    return $this->getFoo()
 
148
        ->doBar(
 
149
            $this->getX() // no comma here
 
150
                ->doY()  // this is still the first method argument
 
151
                ->doZ()  // this is still the first method argument
 
152
        );
 
153
}
 
154
 
 
155
doError(
 
156
    404, // status code
 
157
    'Not Found', // error name
 
158
    'Check your id' // fix
 
159
);
 
160
 
 
161
// @codingStandardsChangeSetting PEAR.Functions.FunctionCallSignature allowMultipleArguments true
 
162
 
 
163
// Don't report errors for closing braces. Leave that to other sniffs.
 
164
foo(
 
165
    [
 
166
        'this',
 
167
        'is',
 
168
        'an',
 
169
        'array'
 
170
    ],
 
171
[
 
172
        'this',
 
173
        'is',
 
174
        'an',
 
175
        'array'
 
176
     ],
 
177
    array(
 
178
        'this',
 
179
        'is',
 
180
        'an',
 
181
        'array'
 
182
    ),
 
183
    array(
 
184
        'this',
 
185
        'is',
 
186
        'an',
 
187
        'array'
 
188
     ),
 
189
    function($x)
 
190
    {
 
191
         return trim($x);
 
192
   }
 
193
);
 
194
 
 
195
function foo()
 
196
{
 
197
    myFunction(
 
198
        'string'.
 
199
        // comment
 
200
        // comment 
 
201
        'string'.
 
202
        /* comment
 
203
         * comment
 
204
        */
 
205
        'string'.
 
206
    );
 
207
}
 
208
 
 
209
// @codingStandardsChangeSetting PEAR.Functions.FunctionCallSignature requiredSpacesAfterOpen 1
 
210
// @codingStandardsChangeSetting PEAR.Functions.FunctionCallSignature requiredSpacesBeforeClose 1
 
211
ftest($arg, $arg2);
 
212
test( $arg, $arg2 );
 
213
test(  $arg, $arg2  );
 
214
// @codingStandardsChangeSetting PEAR.Functions.FunctionCallSignature requiredSpacesAfterOpen 0
 
215
// @codingStandardsChangeSetting PEAR.Functions.FunctionCallSignature requiredSpacesBeforeClose 0