Skip to content

Commit 4834323

Browse files
authored
minor #21 Correct Style (apply fixes from PhpStan) and Travis improvement (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 ------- 58c6050 Correct Style (and apply fixes from PhpStan) befa495 Fix broken tests
2 parents 7730218 + befa495 commit 4834323

23 files changed

+183
-369
lines changed

.gitattributes

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ core.autocrlf=lf
66
.editorconfig
77
.gitattributes export-ignore
88
.gitignore export-ignore
9-
.php_cs export-ignore
9+
.php_cs.dist export-ignore
1010
.scrutinizer.yml export-ignore
11-
.styleci.yml export-ignore
1211
.travis.yml export-ignore
1312
.github export-ignore
1413
phpunit.xml.dist export-ignore
14+
phpstan.neon export-ignore
1515
/tests export-ignore
1616
/doc export-ignore

.php_cs

Lines changed: 0 additions & 163 deletions
This file was deleted.

.php_cs.dist

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
$header = <<<EOF
4+
This file is part of the RollerworksSearch package.
5+
6+
(c) Sebastiaan Stok <[email protected]>
7+
8+
This source file is subject to the MIT license that is bundled
9+
with this source code in the file LICENSE.
10+
EOF;
11+
12+
return PhpCsFixer\Config::create()
13+
->setRules([
14+
'@Symfony' => true,
15+
'@Symfony:risky' => true,
16+
'@PHP70Migration' => true,
17+
'@PHP71Migration' => true,
18+
'array_syntax' => array('syntax' => 'short'),
19+
'combine_consecutive_unsets' => true,
20+
'declare_strict_types' => true,
21+
'header_comment' => ['header' => $header],
22+
'heredoc_to_nowdoc' => true,
23+
'linebreak_after_opening_tag' => true,
24+
'no_extra_consecutive_blank_lines' => ['continue', 'extra', 'return', 'throw', 'use', 'parenthesis_brace_block', 'square_brace_block', 'curly_brace_block'],
25+
'no_short_echo_tag' => true,
26+
'no_unreachable_default_argument_value' => false,
27+
'no_useless_else' => true,
28+
'no_useless_return' => true,
29+
'ordered_class_elements' => false,
30+
'ordered_imports' => true,
31+
'phpdoc_add_missing_param_annotation' => false,
32+
'phpdoc_annotation_without_dot' => true,
33+
'phpdoc_no_empty_return' => false, // PHP 7 compatibility
34+
'phpdoc_order' => true,
35+
// This breaks for variable @var blocks
36+
'phpdoc_to_comment' => false,
37+
'phpdoc_var_without_name' => false,
38+
'semicolon_after_instruction' => true,
39+
'single_import_per_statement' => false,
40+
'strict_comparison' => false,
41+
'strict_param' => true,
42+
// Breaks with phpstan
43+
'phpdoc_inline_tag' => false,
44+
])
45+
->setRiskyAllowed(true)
46+
->setFinder(
47+
PhpCsFixer\Finder::create()
48+
->exclude('Fixtures')
49+
->in([__DIR__.'/src', __DIR__.'/tests'])
50+
)
51+
;

.styleci.yml

Lines changed: 0 additions & 25 deletions
This file was deleted.

.travis.yml

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,35 +17,36 @@ php:
1717
matrix:
1818
include:
1919
- php: 7.1
20-
env: deps='low'
20+
env: deps='low' lint=1
2121
- php: 7.1
2222
env: DB=pgsql
2323
- php: 7.1
2424
env: DB=sqlite
2525
- php: 7.1
2626
env: DB=mysql
2727
- php: 7.1
28-
env: deps='dev'
28+
env: deps='dev' lint=1
2929
fast_finish: true
3030

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

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

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

4846
script:
49-
- vendor/bin/simple-phpunit --verbose
47+
- export SYMFONY_DEPRECATIONS_HELPER=strict
48+
- vendor/bin/phpunit --verbose
5049
- if [ "$DB" != "" ] && [ "$DB" != "sqlite" ]; then vendor/bin/simple-phpunit --configuration tests/travis/$DB.travis.xml --exclude-group non-functional; fi;
5150
- if [ "$DB" = "sqlite" ]; then vendor/bin/simple-phpunit --configuration tests/travis/sqlite.travis.xml; fi;
51+
- if [[ $lint = 1 ]]; then php php-cs-fixer.phar fix --dry-run --diff --no-ansi; fi
52+
- if [[ $lint = 1 ]]; then phpstan analyse -c phpstan.neon -l5 --ansi src tests; fi

composer.json

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,22 @@
1616
],
1717
"require": {
1818
"php": "^7.1",
19-
"rollerworks/search": "^2.0@dev",
20-
"rollerworks/search-doctrine-dbal": "^2.0@dev",
19+
"rollerworks/search": "^2.0@dev, >v2.0.0-ALPHA4",
20+
"rollerworks/search-doctrine-dbal": "^2.0@dev,>=2.0.0-ALPHA2",
2121
"doctrine/orm": "^2.5"
2222
},
2323
"require-dev": {
24+
"moneyphp/money": "^3.0.7",
25+
"phpunit/phpunit": "^6.3",
2426
"symfony/phpunit-bridge": "^3.3.6",
25-
"moneyphp/money": "^3.0.7"
27+
"symfony/var-dumper": "^3.3"
2628
},
2729
"autoload": {
2830
"psr-4": {
2931
"Rollerworks\\Component\\Search\\Doctrine\\Orm\\": "src/",
3032
"Rollerworks\\Component\\Search\\Extension\\Doctrine\\Orm\\": "src/Extension/"
31-
}
33+
},
34+
"exclude-from-classmap": ["tests/"]
3235
},
3336
"autoload-dev": {
3437
"psr-4": {
@@ -41,5 +44,17 @@
4144
"branch-alias": {
4245
"dev-master": "2.0-dev"
4346
}
47+
},
48+
"config": {
49+
"platform": {
50+
"php": "7.1"
51+
},
52+
"preferred-install": {
53+
"doctrine/dbal": "source",
54+
"doctrine/orm": "source",
55+
"rollerworks/search-doctrine-dbal": "source",
56+
"*": "dist"
57+
},
58+
"sort-packages": true
4459
}
4560
}

mysql.travis.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
backupGlobals="false"
66
colors="true"
77
bootstrap="vendor/autoload.php"
8-
beStrictAboutTestsThatDoNotTestAnything="false"
98
beStrictAboutOutputDuringTests="true"
109
beStrictAboutTodoAnnotatedTests="true"
1110
>

phpstan.neon

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
parameters:
2+
autoload_files:
3+
- vendor/autoload.php
4+
ignoreErrors:
5+
- '#__construct\(\) does not call parent constructor from .+#'
6+
7+
# ValueHolder guard there own correctness. A ValuesBag never returns a wrong object (collection).
8+
# - '#Call to an undefined method Rollerworks\\Component\\Search\\Value\\ValueHolder\:\:#'
9+
10+
# False positive
11+
- "#Casting to string something that's already string#" # cannot fix this yet.
12+
- '#Call to an undefined method Rollerworks\\Component\\Search\\Doctrine\\Orm\\ConditionGenerator\:\:get[a-zA-Z]+#'
13+
- '#Call to an undefined method Doctrine\\Common\\Persistence\\ObjectManager\:\:getConfiguration\(\)#'
14+
- '#Call to an undefined method Doctrine\\Common\\Cache\\Cache\:\:flushAll()#'
15+
16+
# Tests
17+
- '#Call to an undefined method Prophecy\\Prophecy\\ObjectProphecy::[a-zA-Z0-9_]+\(\)#'
18+
# - '#Access to an undefined property Prophecy\\Prophecy\\ObjectProphecy::\$[a-zA-Z0-9_]+#'
19+
# - '#Call to an undefined method PHPUnit_Framework_MockObject_MockObject::[a-zA-Z0-9_]+\(\)#'
20+
- '#expects\s+[^\s]+, PHPUnit_Framework_MockObject_MockObject(\[\])? given#'
21+
# - '#does not accept PHPUnit_Framework_MockObject_MockObject#'
22+
# - '#but returns PHPUnit_Framework_MockObject_MockObject#'

phpunit.xml.dist

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
backupGlobals="false"
66
colors="true"
77
bootstrap="vendor/autoload.php"
8-
beStrictAboutTestsThatDoNotTestAnything="false"
98
beStrictAboutOutputDuringTests="true"
109
beStrictAboutTodoAnnotatedTests="true"
1110
>

src/AbstractCachedConditionGenerator.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ abstract class AbstractCachedConditionGenerator implements ConditionGenerator
6969
*/
7070
public function __construct(AbstractConditionGenerator $conditionGenerator, Cache $cacheDriver, int $ttl = null)
7171
{
72+
$this->conditionGenerator = $conditionGenerator;
7273
$this->cacheDriver = $cacheDriver;
7374
$this->ttl = $ttl;
7475
}

0 commit comments

Comments
 (0)