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

Commit a888543

Browse files
authored
issue 11
Feature/issue 11 exclude migrations filename sniff
2 parents 72d1d37 + 12379ce commit a888543

11 files changed

+2228
-47
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

CodeIgniter4/Sniffs/Arrays/ArrayDeclarationSniff.php

Lines changed: 22 additions & 1 deletion
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:
@@ -592,6 +609,10 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array
592609
true
593610
);
594611

612+
if ($nextContent === false) {
613+
break;
614+
}
615+
595616
$currentEntry['value'] = $nextContent;
596617
$indices[] = $currentEntry;
597618
$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' => '[email protected]',
127+
'fact' => 'Loves coding',
128+
],
129+
[
130+
'id' => 2,
131+
'name' => 'Jim',
132+
'email' => '[email protected]',
133+
'fact' => 'Developed on CodeIgniter',
134+
],
135+
[
136+
'id' => 3,
137+
'name' => 'Jane',
138+
'email' => '[email protected]',
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: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,4 +178,36 @@ 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+
188+
$users = [
189+
[
190+
'id' => 1,
191+
'name' => 'John',
192+
'email' => '[email protected]',
193+
'fact' => 'Loves coding',
194+
],
195+
[
196+
'id' => 2,
197+
'name' => 'Jim',
198+
'email' => '[email protected]',
199+
'fact' => 'Developed on CodeIgniter',
200+
],
201+
[
202+
'id' => 3,
203+
'name' => 'Jane',
204+
'email' => '[email protected]',
205+
'fact' => 'Lives in the USA', [
206+
'hobbies' => [
207+
'guitar',
208+
'cycling',
209+
],
210+
]
211+
],
212+
];
181213
}

CodeIgniter4/Tests/Arrays/ArrayDeclarationUnitTest.php

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

97101
}//end getErrorList()

CodeIgniter4/ruleset.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@
4040
Methods and functions MUST have a doc block comment.
4141
-->
4242
<rule ref="Squiz.Commenting.FunctionComment"/>
43+
<rule ref="Squiz.Commenting.FunctionComment.ParamCommentFullStop">
44+
<severity>0</severity>
45+
</rule>
4346
<!--
4447
Doc block comment alignment.
4548
-->

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
"require": {
1515
},
1616
"require-dev": {
17-
"squizlabs/php_codesniffer": "dev-master"
17+
"squizlabs/php_codesniffer": "^3.1",
18+
"satooshi/php-coveralls": "^1.0",
19+
"phpunit/phpunit": "^6.5"
1820
}
1921
}

0 commit comments

Comments
 (0)