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

Commit ec22dd4

Browse files
committed
Merge branch 'release/1.0.0-beta0009'
2 parents db2c7c9 + 1e09fe5 commit ec22dd4

26 files changed

+1190
-78
lines changed

.travis.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Travis CI (MIT License) configuration file
2+
# @link https://travis-ci.org/
3+
4+
# Use new container based environment
5+
sudo: false
6+
7+
# Declare project language.
8+
# @link http://about.travis-ci.org/docs/user/languages/php/
9+
language: php
10+
11+
# Declare versions of PHP to use. Use one decimal max.
12+
# @link http://docs.travis-ci.com/user/build-configuration/
13+
matrix:
14+
fast_finish: true
15+
16+
include:
17+
# aliased to a recent 5.4.x version
18+
# - php: '5.4'
19+
# aliased to a recent 5.5.x version
20+
# - php: '5.5'
21+
# aliased to a recent 5.6.x version
22+
# - php: '5.6'
23+
# env: SNIFF=1
24+
# aliased to a recent 7.x version
25+
# - php: '7.0'
26+
# aliased to a recent 7.x version
27+
- php: '7.1'
28+
env: SNIFF=1
29+
# aliased to a recent hhvm version
30+
- php: 'hhvm'
31+
# php nightly
32+
- php: 'nightly'
33+
34+
allow_failures:
35+
- php: 'hhvm'
36+
- php: nightly
37+
38+
before_install:
39+
# Install CodeIgniter4-Standard deps.
40+
- if [[ "$SNIFF" == "1" ]]; then composer self-update; fi
41+
- if [[ "$SNIFF" == "1" ]]; then composer require squizlabs/php_codesniffer:dev-master; fi
42+
- if [[ "$SNIFF" == "1" ]]; then composer require satooshi/php-coveralls:dev-master; fi
43+
- if [[ "$SNIFF" == "1" ]]; then composer install; fi
44+
- phpenv rehash
45+
46+
script:
47+
# Search for PHP syntax errors.
48+
- if [[ "$SNIFF" == "1" ]]; then find -L . -path ./vendor -prune -o -name '*.php' -print0 | xargs -0 -n 1 -P 4 php -l; fi
49+
# Change dir.
50+
- if [[ "$SNIFF" == "1" ]]; then cd ./vendor/squizlabs/php_codesniffer/; fi
51+
# Install php_codesniffer deps.
52+
- if [[ "$SNIFF" == "1" ]]; then composer install; fi
53+
# - Check files match the PHPCS standard.
54+
- if [[ "$SNIFF" == "1" ]]; then ./bin/phpcs --ignore=*/Tests/* ../../../CodeIgniter4; fi
55+
# - Change the default standard.
56+
- if [[ "$SNIFF" == "1" ]]; then ./bin/phpcs --config-set installed_paths ../../../CodeIgniter4; fi
57+
# - Verify it's installed.
58+
- if [[ "$SNIFF" == "1" ]]; then ./bin/phpcs -i; fi
59+
# - Run unit tests for CodeIgniter4 standard.
60+
- if [[ "$SNIFF" == "1" ]]; then ./vendor/bin/phpunit --debug --coverage-clover=../../../build/logs/clover.xml --filter CodeIgniter4 ./tests/AllTests.php; fi
61+
62+
after_success:
63+
- if [[ "$SNIFF" == "1" ]]; then cd ../../../; fi
64+
- if [[ "$SNIFF" == "1" ]]; then php ./vendor/bin/coveralls -v -x ./build/logs/clover.xml; fi

CodeIgniter4/Sniffs/Arrays/ArrayDeclarationSniff.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,8 @@ public function processSingleLineArray($phpcsFile, $stackPtr, $arrayStart, $arra
301301
* @param int $stackPtr The position of the current token
302302
* in the stack passed in $tokens.
303303
*
304+
* @todo This is 'brute force' at the moment and ought to be refactored.
305+
*
304306
* @return int|false
305307
*/
306308
public function arrayDeclaredAt($phpcsFile, $stackPtr)
@@ -319,6 +321,7 @@ public function arrayDeclaredAt($phpcsFile, $stackPtr)
319321
T_ARRAY_CAST => true,
320322
T_UNSET_CAST => true,
321323
T_OBJECT_CAST => true,
324+
T_STATIC => true,
322325
);
323326

324327
$before1 = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true);
@@ -332,11 +335,25 @@ public function arrayDeclaredAt($phpcsFile, $stackPtr)
332335
// Does it have visibility scope or a type hint?
333336
// - 'private $arr = [];'
334337
// - '(array) $arr = [];'.
338+
// - 'private static $arr = [];'.
335339
$before2 = $phpcsFile->findPrevious(T_WHITESPACE, ($before1 - 1), null, true);
336340
if ($before2 !== false && isset($preTokens[$tokens[$before2]['code']]) === true) {
337341
// It is preceded with scope or type.
338342
$indentStart = $before2;
343+
344+
// Could still need to go back one level if it's static.
345+
// - 'private static $arr = [];'.
346+
$before3 = $phpcsFile->findPrevious(T_WHITESPACE, ($before2 - 1), null, true);
347+
if ($before3 !== false && isset($preTokens[$tokens[$before3]['code']]) === true) {
348+
// It is preceded with scope or type.
349+
$indentStart = $before3;
350+
}
339351
}
352+
}//end if
353+
354+
// - $obj->arr[] = [];
355+
if ($tokens[$before1]['code'] === T_CLOSE_SQUARE_BRACKET) {
356+
$before1 = $phpcsFile->findPrevious(T_WHITESPACE, ($tokens[$before1]['bracket_opener'] - 1), null, true);
340357
}
341358

342359
// Is it a string?, if so expect object or constant.
@@ -393,8 +410,9 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array
393410
$prevNonWhitespaceToken = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true);
394411
if ($tokens[$prevNonWhitespaceToken]['code'] === T_EQUAL
395412
|| $tokens[$prevNonWhitespaceToken]['code'] === T_OPEN_PARENTHESIS
413+
|| $tokens[$prevNonWhitespaceToken]['code'] === T_RETURN
396414
) {
397-
// It's "=" or "(".
415+
// It's "=", "(" or "return".
398416
$indentStart = $this->arrayDeclaredAt($phpcsFile, $prevNonWhitespaceToken);
399417
} else if ($tokens[$prevNonWhitespaceToken]['code'] === T_DOUBLE_ARROW) {
400418
// It's an array in an array "=> []".

CodeIgniter4/Sniffs/Commenting/FileCommentSniff.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,21 @@ public function process(File $phpcsFile, $stackPtr)
151151
// Check each tag.
152152
$this->processTags($phpcsFile, $stackPtr, $commentStart);
153153

154+
// Check there is 1 empty line after.
155+
$commentCloser = $tokens[$commentStart]['comment_closer'];
156+
$nextContentPtr = $phpcsFile->findNext(T_WHITESPACE, ($commentCloser + 1), null, true);
157+
$lineDiff = ($tokens[$nextContentPtr]['line'] - $tokens[$commentCloser]['line']);
158+
if ($lineDiff === 1) {
159+
$data = array(1);
160+
$error = 'Expected %s empty line after file doc comment';
161+
$fix = $phpcsFile->addFixableError($error, ($commentCloser + 1), 'NoEmptyLineAfterFileDocComment', $data);
162+
if ($fix === true) {
163+
$phpcsFile->fixer->beginChangeset();
164+
$phpcsFile->fixer->addNewlineBefore($nextContentPtr);
165+
$phpcsFile->fixer->endChangeset();
166+
}
167+
}
168+
154169
// Ignore the rest of the file.
155170
return ($phpcsFile->numTokens + 1);
156171

CodeIgniter4/Sniffs/WhiteSpace/FunctionClosingBraceSpaceSniff.php

Lines changed: 7 additions & 14 deletions
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
*/
@@ -155,10 +157,6 @@ public function process(File $phpcsFile, $stackPtr)
155157
}//end if
156158
} else {
157159
if ($found !== (int) $this->allowedLines) {
158-
if ($found < 0) {
159-
$found = 0;
160-
}
161-
162160
if ($this->allowedLines === 1) {
163161
$plural = '';
164162
} else {
@@ -174,21 +172,16 @@ public function process(File $phpcsFile, $stackPtr)
174172
$fix = $phpcsFile->addFixableError($error, $closeBrace, 'SpacingBeforeClose', $data);
175173

176174
if ($fix === true) {
177-
if ($found > 1) {
175+
if ($found > $this->allowedLines) {
178176
$phpcsFile->fixer->beginChangeset();
179-
for ($i = ($prevContent + 1); $i < ($closeBrace - 1); $i++) {
177+
for ($i = ($prevContent + 1); $i < ($closeBrace); $i++) {
180178
$phpcsFile->fixer->replaceToken($i, '');
181179
}
182180

183-
$phpcsFile->fixer->replaceToken($i, $phpcsFile->eolChar);
181+
$phpcsFile->fixer->replaceToken(($closeBrace - 1), $phpcsFile->eolChar);
184182
$phpcsFile->fixer->endChangeset();
185183
} else {
186-
// Try to maintain indentation.
187-
if ($tokens[($closeBrace - 1)]['code'] === T_WHITESPACE) {
188-
$phpcsFile->fixer->addNewlineBefore($closeBrace - 1);
189-
} else {
190-
$phpcsFile->fixer->addNewlineBefore($closeBrace);
191-
}
184+
$phpcsFile->fixer->addNewlineBefore($closeBrace);
192185
}
193186
}
194187
}//end if
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: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
class MyClass {
34

45
protected $codes = [
@@ -53,4 +54,43 @@ class MyClass {
5354
( 'a', 'b' );
5455

5556
$a = array /* comment */ ( 'a', 'b' );
57+
58+
protected static $statusCodes = [
59+
// 1xx: Informational
60+
100 => 'Continue',
61+
101 => 'Switching Protocols',
62+
102 => 'Processing', // http://www.iana.org/go/rfc2518
63+
// 2xx: Success
64+
200 => 'OK',
65+
];
66+
67+
public function error()
68+
{
69+
return [
70+
'code' => '',
71+
'message' => pg_last_error($this->connID)
72+
];
73+
}
74+
75+
public function error2()
76+
{
77+
$this->QBWhere[] = ['condition' => $like_statement, 'escape' => $escape];
78+
79+
$this->QBWhere[] = [
80+
'condition' => $like_statement,
81+
'escape' => $escape,
82+
];
83+
}
84+
85+
public $arr = array( );
86+
87+
public $arr = [ ];
88+
89+
public $arr = [1,];
90+
91+
public $arr = [
92+
'a'=> 1,
93+
'b'=> 2,
94+
'c' => 3,
95+
];
5696
}

CodeIgniter4/Tests/Arrays/ArrayDeclarationUnitTest.inc.fixed

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

45
protected $codes = [
@@ -117,4 +118,46 @@ class MyClass {
117118
'a',
118119
'b',
119120
);
121+
122+
protected static $statusCodes = [
123+
// 1xx: Informational
124+
100 => 'Continue',
125+
101 => 'Switching Protocols',
126+
102 => 'Processing', // http://www.iana.org/go/rfc2518
127+
// 2xx: Success
128+
200 => 'OK',
129+
];
130+
131+
public function error()
132+
{
133+
return [
134+
'code' => '',
135+
'message' => pg_last_error($this->connID),
136+
];
137+
}
138+
139+
public function error2()
140+
{
141+
$this->QBWhere[] = [
142+
'condition' => $like_statement,
143+
'escape' => $escape,
144+
];
145+
146+
$this->QBWhere[] = [
147+
'condition' => $like_statement,
148+
'escape' => $escape,
149+
];
150+
}
151+
152+
public $arr = array();
153+
154+
public $arr = [];
155+
156+
public $arr = [1];
157+
158+
public $arr = [
159+
'a' => 1,
160+
'b' => 2,
161+
'c' => 3,
162+
];
120163
}

0 commit comments

Comments
 (0)