~ubuntu-branches/ubuntu/wily/php-codesniffer/wily

« back to all changes in this revision

Viewing changes to PHP_CodeSniffer-2.3.2/CodeSniffer/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.1.inc.fixed

  • Committer: Package Import Robot
  • Author(s): David Prévot, Greg Sherwood
  • Date: 2015-04-30 18:14:08 UTC
  • mfrom: (1.1.8)
  • Revision ID: package-import@ubuntu.com-20150430181408-1lpm509oq0mo1mmi
Tags: 2.3.2-1
[ Greg Sherwood ]
Prepare for 2.3.2 release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
@codingStandardsChangeSetting Generic.WhiteSpace.ScopeIndent tabIndent false
 
2
<meta name="twitter:site" content="<?php echo $metaTagsData['twitter:site']; ?>">
 
3
<?php
 
4
class Test {
 
5
    function __construct()
 
6
    {
 
7
        $this->hello();
 
8
    }
 
9
 
 
10
    function hello()
 
11
    {
 
12
        echo 'hello';
 
13
    }//end hello()
 
14
 
 
15
    function hello2()
 
16
    {
 
17
        if (TRUE) {
 
18
            echo 'hello'; // no error here as its more than 4 spaces.
 
19
        } else {
 
20
            echo 'bye';
 
21
        }
 
22
 
 
23
        while (TRUE) {
 
24
            echo 'hello';
 
25
        }
 
26
 
 
27
        do {
 
28
            echo 'hello';
 
29
        } while (TRUE);
 
30
    }
 
31
 
 
32
    function hello3()
 
33
    {
 
34
        switch ($hello) {
 
35
            case 'hello':
 
36
            break;
 
37
        }
 
38
    }
 
39
 
 
40
}
 
41
 
 
42
?>
 
43
<pre>
 
44
</head>
 
45
<body>
 
46
<?php
 
47
if ($form->validate()) {
 
48
    $safe = $form->getSubmitValues();
 
49
}
 
50
?>
 
51
</pre>
 
52
<?php
 
53
 
 
54
class Test2
 
55
{
 
56
    function __construct()
 
57
    {
 
58
        //    $this->open(); // error here
 
59
    }
 
60
 
 
61
    public function open()
 
62
    {
 
63
        // Some inline stuff that shouldn't error
 
64
        if (TRUE) echo 'hello';
 
65
        foreach ($tokens as $token) echo $token;
 
66
    }
 
67
 
 
68
    /**
 
69
     * This is a comment 1.
 
70
     * This is a comment 2.
 
71
     * This is a comment 3.
 
72
     * This is a comment 4.
 
73
     */
 
74
    public function close()
 
75
    {
 
76
        // All ok.
 
77
        if (TRUE) {
 
78
            if (TRUE) {
 
79
            } else if (FALSE) {
 
80
                foreach ($tokens as $token) {
 
81
                    switch ($token) {
 
82
                        case '1':
 
83
                        case '2':
 
84
                            if (true) {
 
85
                                if (false) {
 
86
                                    if (false) {
 
87
                                        if (false) {
 
88
                                            echo 'hello';
 
89
                                        }
 
90
                                    }
 
91
                                }
 
92
                            }
 
93
                        break;
 
94
                        case '5':
 
95
                        break;
 
96
                    }
 
97
                    do {
 
98
                        while (true) {
 
99
                            foreach ($tokens as $token) {
 
100
                                for ($i = 0; $i < $token; $i++) {
 
101
                                    echo 'hello';
 
102
                                }
 
103
                            }
 
104
                        }
 
105
                    } while (true);
 
106
                }
 
107
            }
 
108
        }
 
109
    }
 
110
 
 
111
    /*
 
112
      This is another c style comment 1.
 
113
      This is another c style comment 2.
 
114
      This is another c style comment 3.
 
115
      This is another c style comment 4.
 
116
      This is another c style comment 5.
 
117
    */
 
118
 
 
119
    /* This is a T_COMMENT
 
120
    *
 
121
    *
 
122
    *
 
123
    */
 
124
 
 
125
    /** This is a T_DOC_COMMENT
 
126
   */
 
127
 
 
128
    /*
 
129
      This T_COMMENT has a newline in it.
 
130
 
 
131
    */
 
132
 
 
133
    public function read()
 
134
    {
 
135
        echo 'hello';
 
136
 
 
137
        // no errors below.
 
138
        $array = array(
 
139
                  'this',
 
140
                  'that' => array(
 
141
                             'hello',
 
142
                             'hello again' => array(
 
143
                                               'hello',
 
144
                                              ),
 
145
                            ),
 
146
                 );
 
147
    }
 
148
}
 
149
 
 
150
abstract class Test3
 
151
{
 
152
    public function parse()
 
153
    {
 
154
 
 
155
        foreach ($t as $ndx => $token) {
 
156
            if (is_array($token)) {
 
157
                echo 'here';
 
158
            } else {
 
159
                $ts[] = array("token" => $token, "value" => '');
 
160
 
 
161
                $last = count($ts) - 1;
 
162
 
 
163
                switch ($token) {
 
164
                    case '(':
 
165
 
 
166
                        if ($last >= 3 &&
 
167
                            $ts[0]['token'] != T_CLASS &&
 
168
                            $ts[$last - 2]['token'] == T_OBJECT_OPERATOR &&
 
169
                            $ts[$last - 3]['token'] == T_VARIABLE ) {
 
170
 
 
171
 
 
172
                            if (true) {
 
173
                                echo 'hello';
 
174
                            }
 
175
                        }
 
176
                        array_push($braces, $token);
 
177
                    break;
 
178
                }
 
179
            }
 
180
        }
 
181
    }
 
182
}
 
183
 
 
184
public function test()
 
185
{
 
186
    $o = <<<EOF
 
187
this is some text
 
188
this is some text
 
189
this is some text
 
190
this is some text
 
191
this is some text
 
192
this is some text
 
193
EOF;
 
194
 
 
195
    return $o;
 
196
}
 
197
 
 
198
if ($a === true || $a === true || $a === true || $a === true ||
 
199
    $a === true || $a === true || $a === true || $a === true) {
 
200
 
 
201
    echo 'hello';
 
202
}
 
203
 
 
204
if ($true) {
 
205
    /* First comment line
 
206
    *
 
207
    * Comment test here
 
208
    * Comment test here
 
209
    *
 
210
    */
 
211
 
 
212
    /* First comment line
 
213
    *
 
214
    * Comment test here
 
215
    * Comment test here
 
216
    *
 
217
    this si something */
 
218
}
 
219
 
 
220
function test()
 
221
{
 
222
    /* taken from http://de3.php.net/manual/en/reserved.php */
 
223
    # $m[] = 'declare';
 
224
    /* taken from http://de3.php.net/manual/en/reserved.php */
 
225
    # $m[] = 'declare';
 
226
}
 
227
 
 
228
foreach ($elements as $element) {
 
229
    if ($something) {
 
230
        // Do IF.
 
231
    } else if ($somethingElse) {
 
232
        // Do ELSE.
 
233
    }
 
234
}
 
235
 
 
236
if ($condition) {
 
237
    echo "This is a long
 
238
string that spans $numLines lines
 
239
without indenting.
 
240
";
 
241
}
 
242
 
 
243
if ($condition) {
 
244
    echo 'This is a long
 
245
    string that spans nultiple lines
 
246
    with indenting.
 
247
    ';
 
248
}
 
249
 
 
250
if ($condition) {
 
251
    echo 'This is a long
 
252
          string that spans nultiple lines
 
253
          with indenting.';
 
254
}
 
255
 
 
256
switch ($foo) {
 
257
    case 1:
 
258
        switch ($bar) {
 
259
            default:
 
260
                echo $string{1};
 
261
        }
 
262
    break;
 
263
}
 
264
 
 
265
function temp($foo, $bar) {
 
266
    switch ($foo) {
 
267
        case 1:
 
268
            switch ($bar) {
 
269
                default:
 
270
                return $foo;
 
271
            }
 
272
        break;
 
273
    }
 
274
}
 
275
 
 
276
switch ($foo) {
 
277
    case 1:
 
278
        switch ($bar) {
 
279
            default:
 
280
                if ($something) {
 
281
                    echo $string{1};
 
282
                } else if ($else) {
 
283
                    switch ($else) {
 
284
                        default:
 
285
                    }
 
286
                }
 
287
        }
 
288
    break;
 
289
}
 
290
 
 
291
switch ($name) {
 
292
    case "1":
 
293
    case "2":
 
294
    case "3":
 
295
        return true;
 
296
}
 
297
 
 
298
switch ($name) {
 
299
    case "1":
 
300
    case "2":
 
301
    case "3":
 
302
    default :
 
303
        return true;
 
304
}
 
305
 
 
306
function myFunction()
 
307
{
 
308
    ?>
 
309
    <dynamic_content>
 
310
 
 
311
   </dynamic_content>
 
312
    <?php
 
313
 
 
314
}
 
315
 
 
316
switch ($name) {
 
317
    case "1":
 
318
        switch ($name2) {
 
319
            case "1":
 
320
            break;
 
321
            case "2":
 
322
            break;
 
323
        }
 
324
    break;
 
325
    case "2":
 
326
    break;
 
327
}
 
328
 
 
329
switch (true) {
 
330
    case true: {
 
331
    }
 
332
    echo 'hi';
 
333
    break;
 
334
    case false:
 
335
    case null:{
 
336
        echo 'hi';
 
337
    }
 
338
    break;
 
339
}
 
340
 
 
341
switch (true) {
 
342
    case true: {
 
343
        echo 'hi';
 
344
    }
 
345
    // No break here.
 
346
    case false:
 
347
    case true:
 
348
    case null:{
 
349
        echo 'hi';
 
350
        echo 'hi';
 
351
    }
 
352
    break;
 
353
}
 
354
 
 
355
switch (true) {
 
356
    case true: {
 
357
        if (true) {
 
358
            echo 'hi';
 
359
        }
 
360
    }
 
361
    break;
 
362
}
 
363
 
 
364
// Testing anon function.
 
365
class a {
 
366
    function c()
 
367
    {
 
368
        $this->doSomething(
 
369
            function () {
 
370
                echo 123;
 
371
            }
 
372
        );
 
373
    }
 
374
}
 
375
 
 
376
some_function(
 
377
    function() {
 
378
        $a = 403;
 
379
        if ($a === 404) {
 
380
            $a = 403;
 
381
        }
 
382
    }
 
383
);
 
384
 
 
385
some_function(
 
386
    function() {
 
387
        $a = 403;
 
388
        if ($a === 404) {
 
389
            $a = 403;
 
390
        }
 
391
    }
 
392
);
 
393
 
 
394
$myFunction = function() {
 
395
    $a = 403;
 
396
    if ($a === 404) {
 
397
        $a = 403;
 
398
    }
 
399
}
 
400
 
 
401
class Whatever
 
402
{
 
403
    protected $_protectedArray = array(
 
404
        'normalString' => 'That email address is already in use!',
 
405
        'offendingString' => <<<'STRING'
 
406
Each line of this string is always said to be at column 0, 
 
407
    no matter how many spaces are placed
 
408
                at the beginning of each line
 
409
and the ending STRING on the next line is reported as having to be indented.
 
410
STRING
 
411
    );
 
412
}
 
413
 
 
414
class MyClass
 
415
{
 
416
    public static function myFunction()
 
417
    {
 
418
        if (empty($keywords) === FALSE) {
 
419
            $keywords = 'foo';
 
420
            $existing = 'foo';
 
421
        }
 
422
 
 
423
        return $keywords;
 
424
 
 
425
    }//end myFunction()
 
426
 
 
427
}//end class
 
428
 
 
429
$var = call_user_func(
 
430
    $new_var = function () use (&$a) {
 
431
        if ($a > 0) {
 
432
            return $a++;
 
433
        } else {
 
434
            return $a--;
 
435
        }
 
436
    }
 
437
);
 
438
 
 
439
class AnonymousFn
 
440
{
 
441
    public function getAnonFn()
 
442
    {
 
443
        return array(
 
444
            'functions' => Array(
 
445
                'function1' => function ($a, $b, $c) {
 
446
                    $a = $b + $c;
 
447
                    $b = $c / 2;
 
448
                    return Array($a, $b, $c);
 
449
                },
 
450
            ),
 
451
        );
 
452
    }
 
453
}
 
454
?>
 
455
 
 
456
<div>
 
457
    <?php
 
458
    if ($myvar == 'test') {
 
459
        echo 'something';
 
460
    }
 
461
    ?>
 
462
<div>
 
463
<div>
 
464
    <?php
 
465
    if ($myvar == 'test') {
 
466
        echo 'something';
 
467
    }
 
468
    ?>
 
469
<div>
 
470
<div>
 
471
    <?php
 
472
    if ($myvar == 'test') {
 
473
        echo 'something';
 
474
    }
 
475
    ?>
 
476
<div>
 
477
<body>
 
478
    <?php
 
479
    if (isset($_GET["test"])) {
 
480
        if ($_GET["test"] <> "") {
 
481
            $test = true;
 
482
        } else {
 
483
            $test = true;
 
484
        }
 
485
    }
 
486
    ?>
 
487
</body>
 
488
 
 
489
<?php
 
490
if (true) {
 
491
    ?>
 
492
    <div>
 
493
        <div>
 
494
            <div>
 
495
            <?php
 
496
            if (true) {
 
497
                echo 'hello';
 
498
            } else {
 
499
                echo 'goodbye';
 
500
            }
 
501
            ?>
 
502
            </div>
 
503
        </div>
 
504
    </div>
 
505
    <?php
 
506
} else {
 
507
    echo 'else';
 
508
}
 
509
?>
 
510
<?php if (isset($param)) { ?>
 
511
   <h3>some text</h3>
 
512
<?php }
 
513
 
 
514
$list = [
 
515
    'fn' => function ($a) {
 
516
        if ($a === true) {
 
517
            echo 'hi';
 
518
        }
 
519
    }
 
520
];
 
521
 
 
522
$list = [
 
523
    'fn' => function ($a) {
 
524
        if ($a === true) {
 
525
            echo 'hi';
 
526
        }
 
527
    }
 
528
];
 
529
 
 
530
if ($foo) {
 
531
    foreach ($bar as $baz) {
 
532
        if ($baz) {
 
533
            ?>
 
534
            <div>
 
535
                <div>
 
536
                    <div>
 
537
            <?php
 
538
            if ($baz > 1) {
 
539
                echo '1';
 
540
            }
 
541
            ?>
 
542
                    </div>
 
543
                    <?php
 
544
                    if ($baz > 1) {
 
545
                        echo '1';
 
546
                    }
 
547
                    ?>
 
548
                </div>
 
549
                <?php
 
550
                if ($baz > 1) {
 
551
                    echo '1';
 
552
                }
 
553
                ?>
 
554
            </div>
 
555
            <?php
 
556
        }
 
557
    }
 
558
}
 
559
 
 
560
?>
 
561
<title><?= CHtml::encode($this->pageTitle); ?></title>
 
562
 
 
563
<?php
 
564
if ($foo) {
 
565
    echo '1';
 
566
        echo '2';
 
567
            echo '3';
 
568
}
 
569
 
 
570
$array = array();
 
571
array_map(
 
572
    function($x)
 
573
    {
 
574
        return trim($x);
 
575
    },
 
576
    $array
 
577
);
 
578
 
 
579
function foo(){return function(){};}
 
580
 
 
581
$mockedDatabase->expects($this->at(2))
 
582
    ->with($this->callback(
 
583
            function ($subject)
 
584
            {
 
585
            }
 
586
        )
 
587
    );
 
588
 
 
589
/** @var Database $mockedDatabase */
 
590
/** @var Container $mockedContainer */
 
591
 
 
592
echo $string->append('foo')
 
593
            ->appaend('bar')
 
594
            ->appaend('baz')
 
595
            ->outputUsing(
 
596
                function ()
 
597
                {
 
598
                }
 
599
            );
 
600
 
 
601
echo PHP_EOL;
 
602
 
 
603
switch ($arg) {
 
604
    case 1:
 
605
        break;
 
606
    case 2:
 
607
        if ($arg2 == 'foo') {
 
608
        }
 
609
    case 3:
 
610
    default:
 
611
        echo 'default';
 
612
}
 
613
 
 
614
if ($tokens[$stackPtr]['content']{0} === '#') {
 
615
} else if ($tokens[$stackPtr]['content']{0} === '/'
 
616
    && $tokens[$stackPtr]['content']{1} === '/'
 
617
) {
 
618
}
 
619
 
 
620
$var = call_user_func(
 
621
    function() {
 
622
        if ($foo) {
 
623
            $new_var = function() {
 
624
                if ($a > 0) {
 
625
                    return $a++;
 
626
                } else {
 
627
                    return $a--;
 
628
                }
 
629
            }
 
630
        }
 
631
    }
 
632
);
 
633
 
 
634
a(
 
635
    function() {
 
636
        $a = function() {
 
637
            $b = false;
 
638
        };
 
639
        true
 
640
    }
 
641
);
 
642
 
 
643
$var = [
 
644
    [
 
645
        '1' =>
 
646
            function () {
 
647
                return true;
 
648
            },
 
649
    ],
 
650
    [
 
651
        '1' =>
 
652
            function () {
 
653
                return true;
 
654
            },
 
655
        '2' => true,
 
656
    ]
 
657
];
 
658
 
 
659
if ($foo) {
 
660
    ?>
 
661
 </p>
 
662
    <?php
 
663
}
 
664
 
 
665
function foo()
 
666
{
 
667
    $failingTests[$testName][] = array(
 
668
                                  'comment'    => self::_replaceKeywords($failingComment, $result),
 
669
                                  'screenshot' => Test::getScreenshotPath(
 
670
                                      $projectid,
 
671
                                      $result['class_name'],
 
672
                                  ),
 
673
                                 );
 
674
 
 
675
}
 
676
 
 
677
$this->mockedDatabase
 
678
    ->with(
 
679
        $this->callback(
 
680
            function () {
 
681
                return;
 
682
            }
 
683
        )
 
684
    );
 
685
 
 
686
$this->subject->recordLogin();
 
687
 
 
688
function a()
 
689
{
 
690
    if (true) {
 
691
        static::$a[$b] =
 
692
            static::where($c)
 
693
                ->where($c)
 
694
                ->where(
 
695
                    function ($d) {
 
696
                        $d->whereNull();
 
697
                        $d->orWhere();
 
698
                    }
 
699
                )
 
700
                ->first();
 
701
 
 
702
        if (static::$a[$b] === null) {
 
703
            static::$a[$b] = new static(
 
704
                array(
 
705
                    'a' => $a->id,
 
706
                    'a' => $a->id,
 
707
                )
 
708
            );
 
709
        }
 
710
    }
 
711
 
 
712
    return static::$a[$b];
 
713
}
 
714
 
 
715
$foo->load(
 
716
    array(
 
717
        'bar' => function ($baz) {
 
718
            $baz->call();
 
719
        }
 
720
    )
 
721
);
 
722
 
 
723
hello();
 
724
 
 
725
$foo = array_unique(
 
726
    array_map(
 
727
        function ($entry) {
 
728
            return $entry * 2;
 
729
        },
 
730
        array()
 
731
    )
 
732
);
 
733
bar($foo);
 
734
 
 
735
class PHP_CodeSniffer_Tokenizers_JS
 
736
{
 
737
 
 
738
    public $scopeOpeners = array(
 
739
                            T_CASE => array(
 
740
                                       'end'    => array(
 
741
                                                    T_BREAK    => T_BREAK,
 
742
                                                    T_RETURN   => T_RETURN,
 
743
                                                   ),
 
744
                                       'strict' => true,
 
745
                                      ),
 
746
                           );
 
747
}
 
748
 
 
749
echo $string->
 
750
        append('foo')->
 
751
        appaend('bar')->
 
752
        appaend('baz')->
 
753
        outputUsing(
 
754
            function ()
 
755
            {
 
756
            }
 
757
        );
 
758
 
 
759
$str = 'the items I want to show are: ' .
 
760
    implode(
 
761
        ', ',
 
762
        array('a', 'b', 'c')
 
763
    );
 
764
 
 
765
echo $str;
 
766
 
 
767
$str = 'foo'
 
768
        . '1'
 
769
        . '2';
 
770
 
 
771
echo $str;
 
772
 
 
773
bar([
 
774
    'foo' => foo(function () {
 
775
        return 'foo';
 
776
    })
 
777
]);
 
778
 
 
779
$domains = array_unique(
 
780
    array_map(
 
781
        function ($url) {
 
782
            $urlObject = new \Purl\Url($url);
 
783
            return $urlObject->registerableDomain;
 
784
        },
 
785
        $sites
 
786
    )
 
787
);
 
788
 
 
789
return $domains;
 
790
 
 
791
if ($a == 5) :
 
792
    echo "a equals 5";
 
793
    echo "...";
 
794
elseif ($a == 6) :
 
795
    echo "a equals 6";
 
796
    echo "!!!";
 
797
else :
 
798
    echo "a is neither 5 nor 6";
 
799
endif;
 
800
 
 
801
if ($foo):
 
802
    if ($bar) $foo = 1;
 
803
    elseif ($baz) $foo = 2;
 
804
endif;
 
805
 
 
806
$this
 
807
    ->method(array(
 
808
        'foo' => 'bar',
 
809
    ), 'arg', array(
 
810
        'foo' => 'bar',
 
811
    ));
 
812
 
 
813
class Foo
 
814
{
 
815
    use Bar {
 
816
        myMethod as renamedMethod;
 
817
    }
 
818
}
 
819
 
 
820
class Foo
 
821
{
 
822
    use Bar {
 
823
        myMethod as renamedMethod;
 
824
    }
 
825
}
 
826
 
 
827
foo();
 
828
 
 
829
array(
 
830
 'key1' => function ($bar) {
 
831
    return $bar;
 
832
 },
 
833
 'key2' => function ($foo) {
 
834
    return $foo;
 
835
 },
 
836
);
 
837
 
 
838
try {
 
839
    echo 'foo';
 
840
} catch (\Exception $e) {
 
841
    echo 'catch';
 
842
} finally {
 
843
    if (false) {
 
844
        echo 'finally false';
 
845
    }
 
846
}
 
847
 
 
848
function foo()
 
849
{
 
850
    $foo = array(
 
851
    );
 
852
 
 
853
    if ($foo) {
 
854
        echo 'foo';
 
855
    }
 
856
 
 
857
    return false;
 
858
}
 
859
 
 
860
/*
 
861
$a = array(
 
862
    */
 
863
);
 
864
 
 
865
echo ""