Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Nov 5, 2022. It is now read-only.

Commit 5a0b8f2

Browse files
authored
Merge pull request #15 from louisl/develop
Releasing 1.0.0-beta0012
2 parents 4ae78d0 + 5030d74 commit 5a0b8f2

19 files changed

+2344
-79
lines changed

‎.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
composer.phar
2-
/vendor/
2+
/vendor/
3+
/build

‎.travis.yml

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,67 @@
1-
# Travis CI (MIT License) configuration file
2-
# @link https://travis-ci.org/
1+
# Travis CI
32

43
# Use new container based environment
54
sudo: false
65

76
# Declare project language.
8-
# @link http://about.travis-ci.org/docs/user/languages/php/
97
language: php
108

11-
# Declare versions of PHP to use. Use one decimal max.
12-
# @link http://docs.travis-ci.com/user/build-configuration/
9+
env:
10+
global:
11+
# Name and folder of the the standard to test.
12+
- STANDARD="CodeIgniter4"
13+
# Upload covarage to coveralls.
14+
- COVERALLS="1"
15+
1316
matrix:
1417
fast_finish: true
1518

19+
# Declare versions of PHP to use. Use one decimal max.
1620
include:
1721
# aliased to a recent 5.4.x version
1822
# - php: '5.4'
1923
# aliased to a recent 5.5.x version
2024
# - php: '5.5'
2125
# aliased to a recent 5.6.x version
2226
# - php: '5.6'
23-
# env: SNIFF=1
2427
# aliased to a recent 7.x version
2528
# - php: '7.0'
2629
# aliased to a recent 7.x version
2730
- php: '7.1'
28-
env: SNIFF=1
2931
# aliased to a recent hhvm version
30-
- php: 'hhvm'
32+
#- php: 'hhvm'
3133
# php nightly
32-
- php: 'nightly'
34+
#- php: 'nightly'
3335

34-
allow_failures:
35-
- php: 'hhvm'
36-
- php: nightly
36+
#allow_failures:
37+
#- php: 'hhvm'
38+
#- php: 'nightly'
3739

3840
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
41+
# Remove xdebug. Needed for coverage.
42+
# - phpenv config-rm xdebug.ini
43+
44+
install:
45+
# Update composer to latest version.
46+
- composer self-update
47+
# Install project composer deps in composer.json
48+
- composer install --no-interaction
49+
50+
before_script:
51+
# Rehash the php environment if testing on several PHP versions.
52+
# - phpenv rehash
4553

4654
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
55+
# Check for PHP syntax errors.
56+
- find -L . -path ./vendor -prune -o -name '*.php' -print0 | xargs -0 -n 1 -P 4 php -l
5357
# - 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
58+
- ./vendor/bin/phpcs --ignore=*/Tests/* ./$STANDARD/ --standard=./vendor/squizlabs/php_codesniffer/phpcs.xml.dist
59+
# Change the default standard.
60+
- ./vendor/bin/phpcs --config-set installed_paths $TRAVIS_BUILD_DIR/$STANDARD
61+
# Verify it's installed.
62+
- ./vendor/bin/phpcs -i
63+
# Run unit tests for the standard.
64+
- ./vendor/bin/phpunit --debug --filter $STANDARD
6165

6266
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
67+
- if [[ "$COVERALLS" == "1" ]]; then ./vendor/bin/coveralls -v -x ./build/logs/coverage/clover/clover.xml; fi

‎CONTRIBUTING.md

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
### PHPUnit Testing
66

7-
***This is currently a work in progress. Not all unit tests are complete or working as intended.***
7+
***This is currently a work in progress.***
88

99
`cd /Path/To/CodeIgniter4-Standard`
1010

@@ -14,28 +14,16 @@
1414

1515
Verify PHP_Codesniffer works.
1616

17-
`./vendor/squizlabs/php_codesniffer/bin/phpcs -i`
17+
`./vendor/bin/phpcs -i`
1818

1919
Set installed standard to CodeIgniter4.
2020

21-
`./vendor/squizlabs/php_codesniffer/bin/phpcs --config-set installed_paths /Path/To/CodeIgniter4-Standard/CodeIgniter4`
21+
`./vendor/bin/phpcs --config-set installed_paths /Path/To/CodeIgniter4-Standard/CodeIgniter4`
2222

2323
Verify the CodeIgniter4 standard is installed.
2424

25-
`./vendor/squizlabs/php_codesniffer/bin/phpcs -i`
26-
27-
Change directory to 'php_codesniffer'.
28-
29-
`cd ./vendor/squizlabs/php_codesniffer/`
30-
31-
Install PHP_Codesniffer dependencies (PHPUnit).
32-
33-
`composer install`
34-
35-
Change directory back to 'CodeIgniter4-Standard'.
36-
37-
`cd ../../../`
25+
`./vendor/bin/phpcs -i`
3826

3927
Run unit tests.
4028

41-
`./vendor/squizlabs/php_codesniffer/vendor/bin/phpunit --debug --filter CodeIgniter4 ./vendor/squizlabs/php_codesniffer/tests/AllTests.php`
29+
`./vendor/bin/phpunit --debug --filter CodeIgniter4`

‎CodeIgniter4/Sniffs/Arrays/ArrayDeclarationSniff.php

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,24 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array
374374
case T_COMMA:
375375
// The end of an array line "[],".
376376
// Argument in a function "$item->save($data, [...], ...)".
377-
$firstOnLine = $phpcsFile->findFirstOnLine(array(T_VARIABLE, T_CLOSE_SHORT_ARRAY), $prevNonWhitespaceToken);
377+
$starts = array(
378+
T_VARIABLE,
379+
T_VAR,
380+
T_PUBLIC,
381+
T_PRIVATE,
382+
T_PROTECTED,
383+
T_ARRAY_CAST,
384+
T_UNSET_CAST,
385+
T_OBJECT_CAST,
386+
T_STATIC,
387+
T_CONST,
388+
T_RETURN,
389+
T_OBJECT_OPERATOR,
390+
T_CLOSE_SHORT_ARRAY,
391+
T_CONSTANT_ENCAPSED_STRING,
392+
);
393+
394+
$firstOnLine = $phpcsFile->findFirstOnLine($starts, $prevNonWhitespaceToken);
378395
$indentStart = $firstOnLine;
379396
break;
380397
default:
@@ -386,7 +403,7 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array
386403
// If this is the first argument in a function ensure the bracket to be right after the parenthesis. eg "array_combine([".
387404
if ($tokens[$prevNonWhitespaceToken]['code'] === T_OPEN_PARENTHESIS && $tokens[$stackPtr]['code'] === T_OPEN_SHORT_ARRAY) {
388405
if ($tokens[$stackPtr]['line'] > $tokens[$prevNonWhitespaceToken]['line']) {
389-
$error = 'Array open bracket should be after function open parenthesis "(["';
406+
$error = 'Array openening bracket should be after function open parenthesis "(["';
390407
$data = array();
391408
$fix = $phpcsFile->addFixableError($error, $stackPtr, 'ShortArrayOpenWrongLine', $data);
392409
if ($fix === true) {
@@ -400,11 +417,31 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array
400417
}
401418
}
402419

403-
// Check the closing bracket is on a new line.
420+
// Get content before closing array bracket/brace.
404421
$lastContent = $phpcsFile->findPrevious(T_WHITESPACE, ($arrayEnd - 1), $arrayStart, true);
422+
423+
// Check for ) after last Array end.
424+
$afterCloser = $phpcsFile->findNext(T_WHITESPACE, ($arrayEnd + 1), null, true);
425+
if ($tokens[$afterCloser]['code'] === T_CLOSE_PARENTHESIS) {
426+
if ($tokens[$afterCloser]['column'] !== ($tokens[$arrayEnd]['column'] + 1)) {
427+
$error = 'Closing parenthesis should be after array closing bracket "])"';
428+
$data = array();
429+
$fix = $phpcsFile->addFixableError($error, $afterCloser, 'CloseBracketAfterArrayBracket');
430+
if ($fix === true) {
431+
$phpcsFile->fixer->beginChangeset();
432+
for ($i = ($arrayEnd + 1); $i < $afterCloser; $i++) {
433+
$phpcsFile->fixer->replaceToken($i, '');
434+
}
435+
436+
$phpcsFile->fixer->endChangeset();
437+
}
438+
}
439+
}
440+
441+
// Check the closing bracket is on a new line.
405442
if ($tokens[$lastContent]['line'] === $tokens[$arrayEnd]['line']) {
406443
$error = 'Closing parenthesis of array declaration must be on a new line';
407-
$fix = $phpcsFile->addFixableError($error, $arrayEnd, 'CloseBraceNewLine');
444+
$fix = $phpcsFile->addFixableError($error, $arrayEnd, 'CloseArrayBraceNewLine');
408445
if ($fix === true) {
409446
$phpcsFile->fixer->addNewlineBefore($arrayEnd);
410447
}
@@ -425,7 +462,7 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array
425462
($found / $this->tabWidth),
426463
);
427464

428-
$fix = $phpcsFile->addFixableError($error, $arrayEnd, 'CloseBraceNotAligned', $data);
465+
$fix = $phpcsFile->addFixableError($error, $arrayEnd, 'CloseArrayBraceNotAligned', $data);
429466
if ($fix === true) {
430467
if ($found === 0) {
431468
$phpcsFile->fixer->addContent(($arrayEnd - 1), str_repeat('', $expected));
@@ -592,6 +629,10 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array
592629
true
593630
);
594631

632+
if ($nextContent === false) {
633+
break;
634+
}
635+
595636
$currentEntry['value'] = $nextContent;
596637
$indices[] = $currentEntry;
597638
$lastToken = $nextToken;

‎CodeIgniter4/Sniffs/Files/FilenameMatchesClassSniff.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,12 @@ public function process(File $phpcsFile, $stackPtr)
6969
return;
7070
}
7171

72-
$className = trim($phpcsFile->getDeclarationName($stackPtr));
72+
$className = trim($phpcsFile->getDeclarationName($stackPtr));
73+
74+
if (strpos($className, 'Migration') === 0 && strpos($fileName, '_') !== false) {
75+
return;
76+
}
77+
7378
$nextContentPtr = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
7479
$type = $tokens[$stackPtr]['content'];
7580

‎CodeIgniter4/Tests/Arrays/ArrayDeclarationUnitTest.inc

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,36 @@ class MyClass {
112112
'version' => $version,
113113
'name' => $this->name,
114114
]);
115+
116+
$message->setCustomProperty('user_info', array(
117+
'id' => $id,
118+
'name' => 'Test message'
119+
)
120+
);
121+
122+
$users = [
123+
[
124+
'id' => 1,
125+
'name' => 'John',
126+
'email' => 'john@example.com',
127+
'fact' => 'Loves coding',
128+
],
129+
[
130+
'id' => 2,
131+
'name' => 'Jim',
132+
'email' => 'jim@example.com',
133+
'fact' => 'Developed on CodeIgniter',
134+
],
135+
[
136+
'id' => 3,
137+
'name' => 'Jane',
138+
'email' => 'jane@example.com',
139+
'fact' => 'Lives in the USA', [
140+
'hobbies' => [
141+
'guitar',
142+
'cycling',
143+
],
144+
]
145+
],
146+
];
115147
}

‎CodeIgniter4/Tests/Arrays/ArrayDeclarationUnitTest.inc.fixed

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,4 +178,35 @@ class MyClass {
178178
'version' => $version,
179179
'name' => $this->name,
180180
]);
181+
182+
$message->setCustomProperty('user_info', [
183+
'id' => $id,
184+
'name' => 'Test message',
185+
]);
186+
187+
$users = [
188+
[
189+
'id' => 1,
190+
'name' => 'John',
191+
'email' => 'john@example.com',
192+
'fact' => 'Loves coding',
193+
],
194+
[
195+
'id' => 2,
196+
'name' => 'Jim',
197+
'email' => 'jim@example.com',
198+
'fact' => 'Developed on CodeIgniter',
199+
],
200+
[
201+
'id' => 3,
202+
'name' => 'Jane',
203+
'email' => 'jane@example.com',
204+
'fact' => 'Lives in the USA', [
205+
'hobbies' => [
206+
'guitar',
207+
'cycling',
208+
],
209+
]
210+
],
211+
];
181212
}

‎CodeIgniter4/Tests/Arrays/ArrayDeclarationUnitTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ public function getErrorList()
9292
107 => 1,
9393
112 => 1,
9494
113 => 1,
95+
116 => 1,
96+
117 => 1,
97+
118 => 1,
98+
119 => 1,
99+
120 => 1,
95100
);
96101

97102
}//end getErrorList()
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
if ($a AND $b === $c) {} // Fail
4+
if ($a === $b AND $c) {} // Fail
5+
if ($a === $b AND $a === $c) {} // Fail
6+
if ($a === $b && $a === $c) {} // Fail
7+
if ($a === 1 and $a === 2 AND $a === 3) {} // Fail 2 errors
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
if ($a && $b === $c) {} // Fail
4+
if ($a === $b && $c) {} // Fail
5+
if ($a === $b && $a === $c) {} // Fail
6+
if ($a === $b && $a === $c) {} // Fail
7+
if ($a === 1 && $a === 2 && $a === 3) {} // Fail 2 errors

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /