Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update build to add PHPCS and PHPStan #130

Merged
merged 6 commits into from
Aug 30, 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
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
.scrutinizer.yml export-ignore
.travis.yml export-ignore
phpunit.xml.dist export-ignore
/phpcs.xml.dist export-ignore
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
vendor/
composer.lock
build/
/phpcs.xml
/.phpcs-cache
45 changes: 34 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,44 @@
language: php
dist: trusty
sudo: false
language: php

cache:
directories:
- $HOME/.composer/cache

php:
- 7.1
- 7.2
- nightly

matrix:
fast_finish: true

before_install:
- if [[ $TRAVIS_PHP_VERSION = '7.1' ]]; then PHPUNIT_FLAGS="--coverage-clover clover.xml"; fi
- mv ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini{,.disabled} || echo "xdebug not available"

install:
- travis_retry composer -n --prefer-source install

script: ./vendor/bin/phpunit

jobs:
allow_failures:
- php: nightly

before_script:
- composer -n --prefer-source install
include:
- stage: Coverage
before_script:
- mv ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini{.disabled,}
- if [[ ! $(php -m | grep -si xdebug) ]]; then echo "xdebug required for coverage"; exit 1; fi
script:
- ./vendor/bin/phpunit --coverage-clover clover.xml
after_script:
- wget https://scrutinizer-ci.com/ocular.phar
- php ocular.phar code-coverage:upload --format=php-clover clover.xml

script:
- vendor/bin/phpunit $PHPUNIT_FLAGS
- stage: Coding standard
script:
- ./vendor/bin/phpcs

after_script:
- if [ -f clover.xml ]; then wget https://scrutinizer-ci.com/ocular.phar && php ocular.phar code-coverage:upload --format=php-clover clover.xml; fi
- stage: Lint
before_script:
- travis_retry composer require --dev --prefer-dist --prefer-stable phpstan/phpstan:^0.8
script: vendor/bin/phpstan analyse -l 3 lib
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
"php": "^7.1"
},
"require-dev": {
"phpunit/phpunit": "^5.7",
"doctrine/coding-standard": "~0.1@dev"
"phpunit/phpunit": "^6.3",
"doctrine/coding-standard": "^1.0",
"squizlabs/php_codesniffer": "^3.0"
},
"autoload": {
"psr-4": { "Doctrine\\Common\\Collections\\": "lib/Doctrine/Common/Collections" }
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/Common/Collections/ArrayCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ public function matching(Criteria $criteria)
$length = $criteria->getMaxResults();

if ($offset || $length) {
$filtered = array_slice($filtered, (int)$offset, $length);
$filtered = array_slice($filtered, (int) $offset, $length);
}

return $this->createFrom($filtered);
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/Common/Collections/Criteria.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Criteria
/**
* @var string
*/
const ASC = 'ASC';
const ASC = 'ASC';

/**
* @var string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ public static function getObjectFieldValue($object, $field)
}

// camelcase field name to support different variable naming conventions
$ccField = preg_replace_callback('/_(.?)/', function($matches) { return strtoupper($matches[1]); }, $field);
$ccField = preg_replace_callback('/_(.?)/', function ($matches) {
return strtoupper($matches[1]);
}, $field);

foreach ($accessors as $accessor) {
$accessor .= $ccField;
Expand Down Expand Up @@ -102,7 +104,7 @@ public static function getObjectFieldValue($object, $field)
public static function sortByField($name, $orientation = 1, \Closure $next = null)
{
if ( ! $next) {
$next = function() : int {
$next = function () : int {
return 0;
};
}
Expand Down Expand Up @@ -176,7 +178,7 @@ public function walkComparison(Comparison $comparison)
case Comparison::MEMBER_OF:
return function ($object) use ($field, $value) : bool {
$fieldValues = ClosureExpressionVisitor::getObjectFieldValue($object, $field);
if (!is_array($fieldValues)) {
if ( ! is_array($fieldValues)) {
$fieldValues = iterator_to_array($fieldValues);
}
return in_array($value, $fieldValues, true);
Expand Down Expand Up @@ -217,7 +219,7 @@ public function walkCompositeExpression(CompositeExpression $expr)
$expressionList[] = $this->dispatch($child);
}

switch($expr->getType()) {
switch ($expr->getType()) {
case CompositeExpression::TYPE_AND:
return $this->andExpressions($expressionList);

Expand Down
28 changes: 14 additions & 14 deletions lib/Doctrine/Common/Collections/Expr/Comparison.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@
*/
class Comparison implements Expression
{
const EQ = '=';
const NEQ = '<>';
const LT = '<';
const LTE = '<=';
const GT = '>';
const GTE = '>=';
const IS = '='; // no difference with EQ
const IN = 'IN';
const NIN = 'NIN';
const CONTAINS = 'CONTAINS';
const MEMBER_OF = 'MEMBER_OF';
const STARTS_WITH = 'STARTS_WITH';
const ENDS_WITH = 'ENDS_WITH';
const EQ = '=';
const NEQ = '<>';
const LT = '<';
const LTE = '<=';
const GT = '>';
const GTE = '>=';
const IS = '='; // no difference with EQ
const IN = 'IN';
const NIN = 'NIN';
const CONTAINS = 'CONTAINS';
const MEMBER_OF = 'MEMBER_OF';
const STARTS_WITH = 'STARTS_WITH';
const ENDS_WITH = 'ENDS_WITH';

/**
* @var string
Expand Down Expand Up @@ -68,7 +68,7 @@ public function __construct($field, $operator, $value)
}

$this->field = $field;
$this->op = $operator;
$this->op = $operator;
$this->value = $value;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
class CompositeExpression implements Expression
{
const TYPE_AND = 'AND';
const TYPE_OR = 'OR';
const TYPE_OR = 'OR';

/**
* @var string
Expand Down
3 changes: 1 addition & 2 deletions lib/Doctrine/Common/Collections/ExpressionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,5 @@ public function startsWith($field, $value)
public function endsWith($field, $value)
{
return new Comparison($field, Comparison::ENDS_WITH, new Value($value));
}

}
}
20 changes: 20 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0"?>
<ruleset>
<arg name="basepath" value="."/>
<arg name="extensions" value="php"/>
<arg name="parallel" value="80"/>
<arg name="cache" value=".phpcs-cache"/>
<arg name="colors" />

<!-- Ignore warnings and show progress of the run -->
<arg value="np"/>

<file>lib</file>
<file>tests</file>

<rule ref="Doctrine"/>

<rule ref="PSR1.Classes.ClassDeclaration.MultipleClasses">
<exclude-pattern>*/tests/*</exclude-pattern>
</rule>
</ruleset>
12 changes: 5 additions & 7 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
backupGlobals="false"
colors="true"
verbose="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTestsThatDoNotTestAnything="true"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this removed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tried explained on the commit message (cb7f39d) but the reason is that we were just repeating the default configuration, which is kind of redundant.

beStrictAboutTodoAnnotatedTests="true"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
colors="true"
verbose="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
>
<testsuites>
<testsuite name="Doctrine Collections Test Suite">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function testLazyCollection() : void
/** @var LazyArrayCollection $collection */
$collection = $this->buildCollection(['a', 'b', 'c']);

$this->assertFalse($collection->isInitialized());
$this->assertCount(3, $collection);
self::assertFalse($collection->isInitialized());
self::assertCount(3, $collection);
}
}
Loading