Skip to content
This repository was archived by the owner on Nov 5, 2022. It is now read-only.

Commit f0e886c

Browse files
committed
Merge branch 'feature/v-space' into develop
2 parents 542385f + 477ec20 commit f0e886c

17 files changed

+909
-51
lines changed

CodeIgniter4/Sniffs/WhiteSpace/FunctionClosingBraceSpaceSniff.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* @copyright 2017 Louis Linehan
88
* @license https://github.com/louisl/CodeIgniter4-Standard/blob/master/LICENSE MIT License
99
*/
10+
1011
namespace CodeIgniter4\Sniffs\WhiteSpace;
1112

1213
use PHP_CodeSniffer\Sniffs\Sniff;
@@ -15,7 +16,8 @@
1516
/**
1617
* Function Closing Brace Space Sniff
1718
*
18-
* Checks that there is one empty line before the closing brace of a function.
19+
* Checks that there is [allowedLines|allowedNestedLines] empty lines before the
20+
* closing brace of a function.
1921
*
2022
* @author Louis Linehan <louis.linehan@gmail.com>
2123
*/
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
/**
3+
* Vertical Empty Lines
4+
*
5+
* @package CodeIgniter4-Standard
6+
* @author Louis Linehan <louis.linehan@gmail.com>
7+
* @copyright 2017 Louis Linehan
8+
* @license https://github.com/louisl/CodeIgniter4-Standard/blob/master/LICENSE MIT License
9+
*/
10+
11+
namespace CodeIgniter4\Sniffs\WhiteSpace;
12+
13+
use PHP_CodeSniffer\Sniffs\Sniff;
14+
use PHP_CodeSniffer\Files\File;
15+
use CodeIgniter4\Util\Common;
16+
17+
/**
18+
* Vertical Empty Lines Sniff
19+
*
20+
* Checks for consecutive empty vertical lines.
21+
*
22+
* @author Louis Linehan <louis.linehan@gmail.com>
23+
*/
24+
class VerticalEmptyLinesSniff implements Sniff
25+
{
26+
27+
/**
28+
* Consecutive empty vertical lines allowed.
29+
*
30+
* @var integer
31+
*/
32+
public $allowed = 1;
33+
34+
35+
/**
36+
* Returns an array of tokens this test wants to listen for.
37+
*
38+
* @return array
39+
*/
40+
public function register()
41+
{
42+
return array(T_OPEN_TAG);
43+
44+
}//end register()
45+
46+
47+
/**
48+
* Processes this test, when one of its tokens is encountered.
49+
*
50+
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
51+
* @param int $stackPtr The position of the current token in
52+
* the stack passed in $tokens.
53+
*
54+
* @return int
55+
*/
56+
public function process(File $phpcsFile, $stackPtr)
57+
{
58+
$errors = array();
59+
$tokens = $phpcsFile->getTokens();
60+
for ($i = 1; $i < $phpcsFile->numTokens; $i++) {
61+
$nextContentPtr = $phpcsFile->findNext(T_WHITESPACE, ($i + 1), null, true);
62+
63+
$lines = ($tokens[$nextContentPtr]['line'] - $tokens[$i]['line'] - 1);
64+
$errorLine = (($nextContentPtr - $lines) + $this->allowed - 1);
65+
66+
if ($lines > ($this->allowed) && in_array($errorLine, $errors) === false) {
67+
$errors[] = $errorLine;
68+
69+
$data = array(
70+
$this->allowed,
71+
Common::pluralize('line', $this->allowed),
72+
);
73+
$error = 'Expected only %s empty %s';
74+
$fix = $phpcsFile->addFixableError($error, $errorLine, 'VerticalEmptyLines', $data);
75+
if ($fix === true) {
76+
$phpcsFile->fixer->replaceToken($errorLine, '');
77+
}
78+
}
79+
}
80+
81+
// Ignore the rest of the file.
82+
return ($phpcsFile->numTokens + 1);
83+
84+
}//end process()
85+
86+
87+
}//end class

CodeIgniter4/Tests/Arrays/ArrayDeclarationUnitTest.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
class MyClass {
34

45
protected $codes = [

CodeIgniter4/Tests/Arrays/ArrayDeclarationUnitTest.inc.fixed

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
class MyClass {
34

45
protected $codes = [

CodeIgniter4/Tests/Arrays/ArrayDeclarationUnitTest.php

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<?php
22
/**
3-
* Unit test class for the ArrayDeclarationTest sniff.
3+
* Array Declaration Unit Test
44
*
5-
* @author Greg Sherwood <gsherwood@squiz.net>
6-
* @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600)
7-
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
5+
* @package CodeIgniter4-Standard
6+
* @author Louis Linehan <louis.linehan@gmail.com>
7+
* @copyright 2017 Louis Linehan
8+
* @license https://github.com/louisl/CodeIgniter4-Standard/blob/master/LICENSE MIT License
89
*/
910

1011
namespace CodeIgniter4\Tests\Arrays;
@@ -41,35 +42,35 @@ public function setCliValues($testFile, $config)
4142
public function getErrorList()
4243
{
4344
return array(
44-
5 => 1,
4545
6 => 1,
4646
7 => 1,
4747
8 => 1,
4848
9 => 1,
4949
10 => 1,
5050
11 => 1,
5151
12 => 1,
52-
13 => 2,
53-
14 => 1,
52+
13 => 1,
53+
14 => 2,
5454
15 => 1,
55-
21 => 1,
56-
28 => 1,
55+
16 => 1,
56+
22 => 1,
5757
29 => 1,
58-
35 => 1,
59-
36 => 2,
60-
41 => 2,
58+
30 => 1,
59+
36 => 1,
60+
37 => 2,
6161
42 => 2,
6262
43 => 2,
6363
44 => 2,
64-
46 => 2,
64+
45 => 2,
6565
47 => 2,
6666
48 => 2,
67-
51 => 1,
68-
55 => 1,
69-
59 => 1,
67+
49 => 2,
68+
52 => 1,
69+
56 => 1,
7070
60 => 1,
7171
61 => 1,
72-
63 => 1,
72+
62 => 1,
73+
64 => 1,
7374
);
7475

7576
}//end getErrorList()
Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
<?php
2+
$i = 0;
3+
do {
4+
echo $i;
5+
} while ($i > 0);
6+
7+
do
8+
{
9+
echo $i;
10+
} while ($i > 0);
11+
12+
do
13+
{
14+
echo $i;
15+
}
16+
while ($i > 0);
17+
18+
do { echo $i; } while ($i > 0);
19+
20+
do{
21+
echo $i;
22+
}while($i > 0);
23+
24+
while ($i < 1) {
25+
echo $i;
26+
}
27+
28+
while($i < 1){
29+
echo $i;
30+
}
31+
32+
while ($i < 1) { echo $i; }
33+
34+
for ($i = 1; $i < 1; $i++) {
35+
echo $i;
36+
}
37+
38+
for($i = 1; $i < 1; $i++){
39+
echo $i;
40+
}
41+
42+
for ($i = 1; $i < 1; $i++) { echo $i; }
43+
44+
if ($i == 0) {
45+
$i = 1;
46+
}
47+
48+
if($i == 0){
49+
$i = 1;
50+
}
51+
52+
if ($i == 0) { $i = 1; }
53+
54+
if ($i == 0) {
55+
$i = 1;
56+
} else {
57+
$i = 0;
58+
}
59+
60+
if ($i == 0) {
61+
$i = 1;
62+
}else{
63+
$i = 0;
64+
}
65+
66+
if ($i == 0) { $i = 1; } else { $i = 0; }
67+
68+
if ($i == 0) {
69+
$i = 1;
70+
} else if ($i == 2) {
71+
$i = 0;
72+
}
73+
74+
if ($i == 0) {
75+
$i = 1;
76+
}else if($i == 2){
77+
$i = 0;
78+
}
79+
80+
if ($i == 0) { $i = 1; } else if ($i == 2) { $i = 0; }
81+
82+
if ($i == 0) { // comments are allowed
83+
$i = 1;
84+
}
85+
86+
if ($i == 0) {// comments are allowed
87+
$i = 1;
88+
}
89+
90+
if ($i == 0) { /* comments are allowed*/
91+
$i = 1;
92+
}
93+
94+
if ($i == 0)
95+
{ // this is ok
96+
$i = 1;
97+
}
98+
99+
if ($i == 0) /* this is ok */ {
100+
}
101+
102+
try {
103+
$code = 'this';
104+
} catch (Exception $e) {
105+
// Caught!
106+
}
107+
108+
try { $code = 'this'; } catch (Exception $e) {
109+
// Caught!
110+
}
111+
112+
do { echo $i;
113+
} while ($i > 0);
114+
115+
if ($i === 0) {
116+
117+
$i = 1
118+
}
119+
120+
if ($a) {
121+
122+
}
123+
elseif ($b) {
124+
}
125+
126+
foreach ($items as $item) {
127+
echo $item;
128+
}
129+
130+
foreach($items as $item){
131+
echo $item;
132+
}
133+
134+
if ($a && $b) // && $c)
135+
{
136+
}
137+
138+
if ($a == 5) :
139+
echo "a equals 5";
140+
echo "...";
141+
elseif ($a == 6) :
142+
echo "a equals 6";
143+
echo "!!!";
144+
else :
145+
echo "a is neither 5 nor 6";
146+
endif;
147+
148+
try {
149+
// try body
150+
}
151+
catch (FirstExceptionType $e) {
152+
// catch body
153+
}
154+
catch (OtherExceptionType $e) {
155+
// catch body
156+
}
157+
158+
switch($foo) {
159+
160+
case 'bar':
161+
break;
162+
163+
}
164+
165+
if ($foo) :
166+
endif;
167+
168+
?>
169+
170+
<?php while($row = $data->getRow()): ?>
171+
<p><?= $val ?></p>
172+
<?php endwhile; ?>
173+
174+
<?php
175+
if ($foo === 1) {
176+
?>
177+
<table><tr><td>
178+
<?php
179+
echo '2';
180+
?>
181+
</td></tr></table>
182+
<?php
183+
}
184+
185+
if ($test) { /*one space after the bracket*/
186+
echo 'true';
187+
}
188+
189+
?>
190+
<?php foreach($formset['Fieldset'] as $fieldset): ?>
191+
<?php foreach($fieldset['Field'] as $field): ?>
192+
<?php endforeach; ?>
193+
<?php endforeach; ?>
194+
195+
<?php foreach ($formset['Fieldset'] as $fieldset) : ?> hello
196+
<?php endforeach; ?>
197+
198+
<?php foreach ($formset['Fieldset'] as $fieldset) :
199+
?>
200+
hello
201+
<?php endforeach; ?>
202+
203+
<?php
204+
$a = 1; $b = true;
205+
if (1 === $a) :
206+
if ($b) {
207+
echo 'b';
208+
} else {
209+
echo 'not b';
210+
}
211+
else :
212+
echo 'not 1';
213+
endif;

0 commit comments

Comments
 (0)