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

Releasing 1.0.0-beta0012 #15

Merged
merged 12 commits into from
Dec 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
composer.phar
/vendor/
/vendor/
/build
69 changes: 36 additions & 33 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,64 +1,67 @@
# Travis CI (MIT License) configuration file
# @link https://travis-ci.org/
# Travis CI

# Use new container based environment
sudo: false

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

# Declare versions of PHP to use. Use one decimal max.
# @link http://docs.travis-ci.com/user/build-configuration/
env:
global:
# Name and folder of the the standard to test.
- STANDARD="CodeIgniter4"
# Upload covarage to coveralls.
- COVERALLS="1"

matrix:
fast_finish: true

# Declare versions of PHP to use. Use one decimal max.
include:
# aliased to a recent 5.4.x version
# - php: '5.4'
# aliased to a recent 5.5.x version
# - php: '5.5'
# aliased to a recent 5.6.x version
# - php: '5.6'
# env: SNIFF=1
# aliased to a recent 7.x version
# - php: '7.0'
# aliased to a recent 7.x version
- php: '7.1'
env: SNIFF=1
# aliased to a recent hhvm version
- php: 'hhvm'
# - php: 'hhvm'
# php nightly
- php: 'nightly'
# - php: 'nightly'

allow_failures:
- php: 'hhvm'
- php: nightly
# allow_failures:
# - php: 'hhvm'
# - php: 'nightly'

before_install:
# Install CodeIgniter4-Standard deps.
- if [[ "$SNIFF" == "1" ]]; then composer self-update; fi
- if [[ "$SNIFF" == "1" ]]; then composer require squizlabs/php_codesniffer:dev-master; fi
- if [[ "$SNIFF" == "1" ]]; then composer require satooshi/php-coveralls:dev-master; fi
- if [[ "$SNIFF" == "1" ]]; then composer install; fi
- phpenv rehash
# Remove xdebug. Needed for coverage.
# - phpenv config-rm xdebug.ini

install:
# Update composer to latest version.
- composer self-update
# Install project composer deps in composer.json
- composer install --no-interaction

before_script:
# Rehash the php environment if testing on several PHP versions.
# - phpenv rehash

script:
# Search for PHP syntax errors.
- if [[ "$SNIFF" == "1" ]]; then find -L . -path ./vendor -prune -o -name '*.php' -print0 | xargs -0 -n 1 -P 4 php -l; fi
# Change dir.
- if [[ "$SNIFF" == "1" ]]; then cd ./vendor/squizlabs/php_codesniffer/; fi
# Install php_codesniffer deps.
- if [[ "$SNIFF" == "1" ]]; then composer install; fi
# Check for PHP syntax errors.
- find -L . -path ./vendor -prune -o -name '*.php' -print0 | xargs -0 -n 1 -P 4 php -l
# - Check files match the PHPCS standard.
- if [[ "$SNIFF" == "1" ]]; then ./bin/phpcs --ignore=*/Tests/* ../../../CodeIgniter4; fi
# - Change the default standard.
- if [[ "$SNIFF" == "1" ]]; then ./bin/phpcs --config-set installed_paths ../../../CodeIgniter4; fi
# - Verify it's installed.
- if [[ "$SNIFF" == "1" ]]; then ./bin/phpcs -i; fi
# - Run unit tests for CodeIgniter4 standard.
- if [[ "$SNIFF" == "1" ]]; then ./vendor/bin/phpunit --debug --coverage-clover=../../../build/logs/clover.xml --filter CodeIgniter4 ./tests/AllTests.php; fi
- ./vendor/bin/phpcs --ignore=*/Tests/* ./$STANDARD/ --standard=./vendor/squizlabs/php_codesniffer/phpcs.xml.dist
# Change the default standard.
- ./vendor/bin/phpcs --config-set installed_paths $TRAVIS_BUILD_DIR/$STANDARD
# Verify it's installed.
- ./vendor/bin/phpcs -i
# Run unit tests for the standard.
- ./vendor/bin/phpunit --debug --filter $STANDARD

after_success:
- if [[ "$SNIFF" == "1" ]]; then cd ../../../; fi
- if [[ "$SNIFF" == "1" ]]; then php ./vendor/bin/coveralls -v -x ./build/logs/clover.xml; fi
- if [[ "$COVERALLS" == "1" ]]; then ./vendor/bin/coveralls -v -x ./build/logs/coverage/clover/clover.xml; fi
22 changes: 5 additions & 17 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

### PHPUnit Testing

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

`cd /Path/To/CodeIgniter4-Standard`

Expand All @@ -14,28 +14,16 @@

Verify PHP_Codesniffer works.

`./vendor/squizlabs/php_codesniffer/bin/phpcs -i`
`./vendor/bin/phpcs -i`

Set installed standard to CodeIgniter4.

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

Verify the CodeIgniter4 standard is installed.

`./vendor/squizlabs/php_codesniffer/bin/phpcs -i`

Change directory to 'php_codesniffer'.

`cd ./vendor/squizlabs/php_codesniffer/`

Install PHP_Codesniffer dependencies (PHPUnit).

`composer install`

Change directory back to 'CodeIgniter4-Standard'.

`cd ../../../`
`./vendor/bin/phpcs -i`

Run unit tests.

`./vendor/squizlabs/php_codesniffer/vendor/bin/phpunit --debug --filter CodeIgniter4 ./vendor/squizlabs/php_codesniffer/tests/AllTests.php`
`./vendor/bin/phpunit --debug --filter CodeIgniter4`
51 changes: 46 additions & 5 deletions CodeIgniter4/Sniffs/Arrays/ArrayDeclarationSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,24 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array
case T_COMMA:
// The end of an array line "[],".
// Argument in a function "$item->save($data, [...], ...)".
$firstOnLine = $phpcsFile->findFirstOnLine(array(T_VARIABLE, T_CLOSE_SHORT_ARRAY), $prevNonWhitespaceToken);
$starts = array(
T_VARIABLE,
T_VAR,
T_PUBLIC,
T_PRIVATE,
T_PROTECTED,
T_ARRAY_CAST,
T_UNSET_CAST,
T_OBJECT_CAST,
T_STATIC,
T_CONST,
T_RETURN,
T_OBJECT_OPERATOR,
T_CLOSE_SHORT_ARRAY,
T_CONSTANT_ENCAPSED_STRING,
);

$firstOnLine = $phpcsFile->findFirstOnLine($starts, $prevNonWhitespaceToken);
$indentStart = $firstOnLine;
break;
default:
Expand All @@ -386,7 +403,7 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array
// If this is the first argument in a function ensure the bracket to be right after the parenthesis. eg "array_combine([".
if ($tokens[$prevNonWhitespaceToken]['code'] === T_OPEN_PARENTHESIS && $tokens[$stackPtr]['code'] === T_OPEN_SHORT_ARRAY) {
if ($tokens[$stackPtr]['line'] > $tokens[$prevNonWhitespaceToken]['line']) {
$error = 'Array open bracket should be after function open parenthesis "(["';
$error = 'Array openening bracket should be after function open parenthesis "(["';
$data = array();
$fix = $phpcsFile->addFixableError($error, $stackPtr, 'ShortArrayOpenWrongLine', $data);
if ($fix === true) {
Expand All @@ -400,11 +417,31 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array
}
}

// Check the closing bracket is on a new line.
// Get content before closing array bracket/brace.
$lastContent = $phpcsFile->findPrevious(T_WHITESPACE, ($arrayEnd - 1), $arrayStart, true);

// Check for ) after last Array end.
$afterCloser = $phpcsFile->findNext(T_WHITESPACE, ($arrayEnd + 1), null, true);
if ($tokens[$afterCloser]['code'] === T_CLOSE_PARENTHESIS) {
if ($tokens[$afterCloser]['column'] !== ($tokens[$arrayEnd]['column'] + 1)) {
$error = 'Closing parenthesis should be after array closing bracket "])"';
$data = array();
$fix = $phpcsFile->addFixableError($error, $afterCloser, 'CloseBracketAfterArrayBracket');
if ($fix === true) {
$phpcsFile->fixer->beginChangeset();
for ($i = ($arrayEnd + 1); $i < $afterCloser; $i++) {
$phpcsFile->fixer->replaceToken($i, '');
}

$phpcsFile->fixer->endChangeset();
}
}
}

// Check the closing bracket is on a new line.
if ($tokens[$lastContent]['line'] === $tokens[$arrayEnd]['line']) {
$error = 'Closing parenthesis of array declaration must be on a new line';
$fix = $phpcsFile->addFixableError($error, $arrayEnd, 'CloseBraceNewLine');
$fix = $phpcsFile->addFixableError($error, $arrayEnd, 'CloseArrayBraceNewLine');
if ($fix === true) {
$phpcsFile->fixer->addNewlineBefore($arrayEnd);
}
Expand All @@ -425,7 +462,7 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array
($found / $this->tabWidth),
);

$fix = $phpcsFile->addFixableError($error, $arrayEnd, 'CloseBraceNotAligned', $data);
$fix = $phpcsFile->addFixableError($error, $arrayEnd, 'CloseArrayBraceNotAligned', $data);
if ($fix === true) {
if ($found === 0) {
$phpcsFile->fixer->addContent(($arrayEnd - 1), str_repeat(' ', $expected));
Expand Down Expand Up @@ -592,6 +629,10 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array
true
);

if ($nextContent === false) {
break;
}

$currentEntry['value'] = $nextContent;
$indices[] = $currentEntry;
$lastToken = $nextToken;
Expand Down
7 changes: 6 additions & 1 deletion CodeIgniter4/Sniffs/Files/FilenameMatchesClassSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,12 @@ public function process(File $phpcsFile, $stackPtr)
return;
}

$className = trim($phpcsFile->getDeclarationName($stackPtr));
$className = trim($phpcsFile->getDeclarationName($stackPtr));

if (strpos($className, 'Migration') === 0 && strpos($fileName, '_') !== false) {
return;
}

$nextContentPtr = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
$type = $tokens[$stackPtr]['content'];

Expand Down
32 changes: 32 additions & 0 deletions CodeIgniter4/Tests/Arrays/ArrayDeclarationUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,36 @@ class MyClass {
'version' => $version,
'name' => $this->name,
]);

$message->setCustomProperty('user_info', array(
'id' => $id,
'name' => 'Test message'
)
);

$users = [
[
'id' => 1,
'name' => 'John',
'email' => '[email protected]',
'fact' => 'Loves coding',
],
[
'id' => 2,
'name' => 'Jim',
'email' => '[email protected]',
'fact' => 'Developed on CodeIgniter',
],
[
'id' => 3,
'name' => 'Jane',
'email' => '[email protected]',
'fact' => 'Lives in the USA', [
'hobbies' => [
'guitar',
'cycling',
],
]
],
];
}
31 changes: 31 additions & 0 deletions CodeIgniter4/Tests/Arrays/ArrayDeclarationUnitTest.inc.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,35 @@ class MyClass {
'version' => $version,
'name' => $this->name,
]);

$message->setCustomProperty('user_info', [
'id' => $id,
'name' => 'Test message',
]);

$users = [
[
'id' => 1,
'name' => 'John',
'email' => '[email protected]',
'fact' => 'Loves coding',
],
[
'id' => 2,
'name' => 'Jim',
'email' => '[email protected]',
'fact' => 'Developed on CodeIgniter',
],
[
'id' => 3,
'name' => 'Jane',
'email' => '[email protected]',
'fact' => 'Lives in the USA', [
'hobbies' => [
'guitar',
'cycling',
],
]
],
];
}
5 changes: 5 additions & 0 deletions CodeIgniter4/Tests/Arrays/ArrayDeclarationUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ public function getErrorList()
107 => 1,
112 => 1,
113 => 1,
116 => 1,
117 => 1,
118 => 1,
119 => 1,
120 => 1,
);

}//end getErrorList()
Expand Down
7 changes: 7 additions & 0 deletions CodeIgniter4/Tests/Operators/BooleanAndUnitTest.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

if ($a AND $b === $c) {} // Fail
if ($a === $b AND $c) {} // Fail
if ($a === $b AND $a === $c) {} // Fail
if ($a === $b && $a === $c) {} // Fail
if ($a === 1 and $a === 2 AND $a === 3) {} // Fail 2 errors
7 changes: 7 additions & 0 deletions CodeIgniter4/Tests/Operators/BooleanAndUnitTest.inc.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

if ($a && $b === $c) {} // Fail
if ($a === $b && $c) {} // Fail
if ($a === $b && $a === $c) {} // Fail
if ($a === $b && $a === $c) {} // Fail
if ($a === 1 && $a === 2 && $a === 3) {} // Fail 2 errors
Loading