Skip to content

Commit

Permalink
style #49 Correct Style (apply fixes from PhpStan) and Travis improve…
Browse files Browse the repository at this point in the history
…ment (sstok)

This PR was merged into the 2.0-dev branch.

Discussion
----------

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | 
| License       | MIT
| Doc PR        | 

- Set-up PHP-CS-Fixer using Travis
- Set-up PHPStan using Travis

And fix reported errors and style violations.

Commits
-------

0da0543 Correct Style (and apply fixes from PhpStan)
336a7c8 Travis configuration improvements
5cada45 Rename .php_cs to .php_cs.dist
69fe9dc Fix phpstan violation
  • Loading branch information
sstok authored Aug 17, 2017
2 parents 19d5033 + 69fe9dc commit 085d5b4
Show file tree
Hide file tree
Showing 16 changed files with 111 additions and 83 deletions.
4 changes: 2 additions & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ core.autocrlf=lf
.editorconfig
.gitattributes export-ignore
.gitignore export-ignore
.php_cs export-ignore
.php_cs.dist export-ignore
.scrutinizer.yml export-ignore
.styleci.yml export-ignore
.travis.yml export-ignore
.github export-ignore
phpunit.xml.dist export-ignore
phpstan.neon export-ignore
/tests export-ignore
/doc export-ignore
38 changes: 0 additions & 38 deletions .php_cs

This file was deleted.

51 changes: 51 additions & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

$header = <<<EOF
This file is part of the RollerworksSearch package.
(c) Sebastiaan Stok <[email protected]>
This source file is subject to the MIT license that is bundled
with this source code in the file LICENSE.
EOF;

return PhpCsFixer\Config::create()
->setRules([
'@Symfony' => true,
'@Symfony:risky' => true,
'@PHP70Migration' => true,
'@PHP71Migration' => true,
'array_syntax' => array('syntax' => 'short'),
'combine_consecutive_unsets' => true,
'declare_strict_types' => true,
'header_comment' => ['header' => $header],
'heredoc_to_nowdoc' => true,
'linebreak_after_opening_tag' => true,
'no_extra_consecutive_blank_lines' => ['continue', 'extra', 'return', 'throw', 'use', 'parenthesis_brace_block', 'square_brace_block', 'curly_brace_block'],
'no_short_echo_tag' => true,
'no_unreachable_default_argument_value' => false,
'no_useless_else' => true,
'no_useless_return' => true,
'ordered_class_elements' => false,
'ordered_imports' => true,
'phpdoc_add_missing_param_annotation' => false,
'phpdoc_annotation_without_dot' => true,
'phpdoc_no_empty_return' => false, // PHP 7 compatibility
'phpdoc_order' => true,
// This breaks for variable @var blocks
'phpdoc_to_comment' => false,
'phpdoc_var_without_name' => false,
'semicolon_after_instruction' => true,
'single_import_per_statement' => false,
'strict_comparison' => false,
'strict_param' => true,
// Breaks with phpstan
'phpdoc_inline_tag' => false,
])
->setRiskyAllowed(true)
->setFinder(
PhpCsFixer\Finder::create()
->exclude('Fixtures')
->in([__DIR__.'/src', __DIR__.'/tests'])
)
;
25 changes: 0 additions & 25 deletions .styleci.yml

This file was deleted.

22 changes: 14 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,37 @@ php:
matrix:
include:
- php: 7.1
env: deps='low'
env: deps='low' lint=1
- php: 7.1
env: DB=pgsql
- php: 7.1
env: DB=sqlite
- php: 7.1
env: DB=mysql
- php: 7.1
env: deps='dev'
env: deps='dev' lint=1
fast_finish: true

before_install:
- phpenv config-rm xdebug.ini || echo "xdebug not available"
- echo "memory_limit=-1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
- if [[ $lint = 1 ]]; then wget https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v2.3.2/php-cs-fixer.phar; fi
- if [[ $lint = 1 ]]; then composer global require --dev 'phpstan/phpstan:^0.8'; fi
- export PATH="$PATH:$HOME/.composer/vendor/bin"

install:
- export COMPOSER_ROOT_VERSION=dev-master
- export SYMFONY_PHPUNIT_REMOVE="symfony/yaml"
- export SYMFONY_PHPUNIT_VERSION=6.2
- if [[ ! $deps ]]; then composer update --prefer-source --no-progress --no-suggest --ansi; fi
- if [[ $deps = 'dev' ]]; then composer config minimum-stability dev && composer update --prefer-source --no-progress --no-suggest --ansi ; fi
- if [[ $deps = 'low' ]]; then composer update --prefer-source --no-progress --no-suggest --prefer-stable --prefer-lowest --ansi; fi
- if [[ ! $deps ]]; then composer update --no-progress --no-suggest --ansi; fi
- if [[ $deps = 'dev' ]]; then composer config minimum-stability dev && composer update --no-progress --no-suggest --ansi ; fi
- if [[ $deps = 'low' ]]; then composer update --no-progress --no-suggest --prefer-stable --prefer-lowest --ansi; fi

before_script:
- if [ "$DB" == "mysql" ]; then mysql -e 'create database search_tests;'; fi;

script:
- export SYMFONY_DEPRECATIONS_HELPER=strict
- export SYMFONY_PHPUNIT_REMOVE="symfony/yaml"
- export SYMFONY_PHPUNIT_VERSION=6.2
- vendor/bin/simple-phpunit --verbose
- if [ "$DB" != "" ]; then vendor/bin/simple-phpunit --configuration tests/travis/$DB.travis.xml; fi;
- if [[ $lint = 1 ]]; then php php-cs-fixer.phar fix --dry-run --diff --no-ansi; fi
- if [[ $lint = 1 ]]; then phpstan analyse -c phpstan.neon -l5 --ansi src tests; fi
13 changes: 12 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"psr-4": {
"Rollerworks\\Component\\Search\\Doctrine\\Dbal\\": "src/",
"Rollerworks\\Component\\Search\\Extension\\Doctrine\\Dbal\\": "src/Extension/"
}
},
"exclude-from-classmap": ["tests/"]
},
"autoload-dev": {
"psr-4": {
Expand All @@ -41,5 +42,15 @@
"branch-alias": {
"dev-master": "2.0-dev"
}
},
"config": {
"platform": {
"php": "7.1"
},
"preferred-install": {
"doctrine/dbal": "source",
"*": "dist"
},
"sort-packages": true
}
}
24 changes: 24 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
parameters:
autoload_files:
- vendor/autoload.php
ignoreErrors:
#- '#__construct\(\) does not call parent constructor from .+#'

# ValueHolder guard there own correctness. A ValuesBag never returns a wrong object (collection).
- '#expects Rollerworks\\Component\\Search\\Value\\[a-zA-Z]+\[\], Rollerworks\\Component\\Search\\Value\\ValueHolder\[\] given#'
# - '#Call to an undefined method Rollerworks\\Component\\Search\\Value\\ValueHolder\:\:#'

# False positive
- '#Call to an undefined method Doctrine\\DBAL\\Driver\\Connection\:\:sqliteCreateFunction\(\)#'
- '#Parameter \#2 \$type of method Doctrine\\DBAL\\Connection\:\:quote\(\) expects ([^\s]+)#'
- "#Casting to string something that's already string#" # cannot fix this yet.
- '#(DbalTestCase|FunctionalDbalTestCase|SearchIntegrationTestCase) not found and could not be autoloaded#' # properly a bug in PHPStan?

# Tests
# - '#Call to an undefined method Prophecy\\Prophecy\\ObjectProphecy::[a-zA-Z0-9_]+\(\)#'
# - '#Access to an undefined property Prophecy\\Prophecy\\ObjectProphecy::\$[a-zA-Z0-9_]+#'
# - '#Call to an undefined method PHPUnit_Framework_MockObject_MockObject::[a-zA-Z0-9_]+\(\)#'
# - '#expects\s+[^\s]+, PHPUnit_Framework_MockObject_MockObject(\[\])? given#'
# - '#does not accept PHPUnit_Framework_MockObject_MockObject#'
# - '#but returns PHPUnit_Framework_MockObject_MockObject#'
# - '#Call to an undefined static method Money\\Money\:\:#'
1 change: 0 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.2/phpunit.xsd"
colors="true"
bootstrap="tests/bootstrap.php"
beStrictAboutTestsThatDoNotTestAnything="false"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
>
Expand Down
2 changes: 1 addition & 1 deletion src/DoctrineDbalFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ final class DoctrineDbalFactory
/**
* @var Cache
*/
protected $cacheDriver;
private $cacheDriver;

/**
* Constructor.
Expand Down
4 changes: 3 additions & 1 deletion src/Extension/Conversion/AgeDateConversion.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ public function convertColumn(string $column, array $options, ConversionHints $h
}

/**
* {@inheritdoc}
* @inheritdoc
*
* @return string|int
*/
public function convertValue($value, array $options, ConversionHints $hints)
{
Expand Down
2 changes: 1 addition & 1 deletion src/QueryPlatform/AbstractQueryPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function getValueAsSql($value, QueryField $mappingConfig, string $column,
return $this->convertSqlValue($value, $mappingConfig, $column, $strategy);
}

return (string) $this->quoteValue(
return $this->quoteValue(
$mappingConfig->dbType->convertToDatabaseValue($value, $this->connection->getDatabasePlatform()),
$mappingConfig->dbType
);
Expand Down
4 changes: 2 additions & 2 deletions tests/Functional/FunctionalDbalTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,9 @@ protected function onNotSuccessfulTest(\Throwable $e)
function ($p) {
if (is_object($p)) {
return get_class($p);
} else {
return "'".var_export($p, true)."'";
}

return "'".var_export($p, true)."'";
},
$query['params'] ?: []
);
Expand Down
1 change: 1 addition & 0 deletions tests/Mocks/ConnectionMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
class ConnectionMock extends \Doctrine\DBAL\Connection
{
private $_fetchOneResult;
private $_platform;
private $_platformMock;
private $_lastInsertId = 0;
private $_inserts = [];
Expand Down
1 change: 0 additions & 1 deletion tests/travis/mysql.travis.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.2/phpunit.xsd"
colors="true"
bootstrap="../bootstrap.php"
beStrictAboutTestsThatDoNotTestAnything="false"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
>
Expand Down
1 change: 0 additions & 1 deletion tests/travis/pgsql.travis.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.2/phpunit.xsd"
colors="true"
bootstrap="../bootstrap.php"
beStrictAboutTestsThatDoNotTestAnything="false"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
>
Expand Down
1 change: 0 additions & 1 deletion tests/travis/sqlite.travis.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.2/phpunit.xsd"
colors="true"
bootstrap="../bootstrap.php"
beStrictAboutTestsThatDoNotTestAnything="false"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
>
Expand Down

0 comments on commit 085d5b4

Please sign in to comment.