Skip to content

Commit

Permalink
update tooling
Browse files Browse the repository at this point in the history
  • Loading branch information
juliangut committed Jan 6, 2020
1 parent 1830ff8 commit a6e635e
Show file tree
Hide file tree
Showing 28 changed files with 186 additions and 162 deletions.
3 changes: 0 additions & 3 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ indent_size = 2
[*.json]
indent_size = 2

[*.neon]
indent_size = 2

[*.yml]
indent_size = 2

Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
composer.lock
cghooks.lock
vendor/
.yo-rc.json
*.cache
infection-log.*
build/
23 changes: 18 additions & 5 deletions .php_cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,18 @@ return Config::create()
'array_syntax' => [
'syntax' => 'short',
],
'binary_operator_spaces' => [
'align_double_arrow' => false,
'align_equals' => false,
],
'binary_operator_spaces' => true,
'blank_line_after_opening_tag' => true,
'cast_spaces' => true,
'class_attributes_separation' => true,
'combine_consecutive_unsets' => true,
'compact_nullable_typehint' => true,
'concat_space' => [
'spacing' => 'one'
],
'declare_equal_normalize' => true,
'declare_strict_types' => true,
'dir_constant' => true,
'function_typehint_space' => true,
'hash_to_slash_comment' => true,
'header_comment' => [
Expand All @@ -55,8 +54,14 @@ return Config::create()
'heredoc_to_nowdoc' => true,
'include' => true,
'linebreak_after_opening_tag' => true,
'list_syntax' => [
'syntax' => 'short',
],
'lowercase_cast' => true,
'lowercase_static_reference' => true,
'magic_constant_casing' => true,
'modernize_types_casting' => true,
'native_constant_invocation' => true,
'native_function_casing' => true,
'native_function_invocation' => true,
'new_with_braces' => true,
Expand All @@ -80,13 +85,17 @@ return Config::create()
'no_trailing_comma_in_singleline_array' => true,
'no_unneeded_control_parentheses' => true,
'no_unreachable_default_argument_value' => true,
'no_unneeded_final_method' => true,
'no_unset_on_property' => true,
'no_unused_imports' => true,
'no_useless_else' => true,
'no_useless_return' => true,
'no_whitespace_before_comma_in_array' => true,
'no_whitespace_in_blank_line' => true,
'normalize_index_brace' => true,
'ordered_imports' => true,
'ordered_imports' => [
'imports_order' => ['const', 'class', 'function'],
],
'php_unit_construct' => true,
'php_unit_dedicate_assert' => true,
'phpdoc_add_missing_param_annotation' => true,
Expand Down Expand Up @@ -115,16 +124,20 @@ return Config::create()
'space_before' => 'none',
],
'self_accessor' => true,
'set_type_to_cast' => true,
'short_scalar_cast' => true,
'single_blank_line_before_namespace' => true,
'single_quote' => true,
'space_after_semicolon' => true,
'standardize_increment' => true,
'standardize_not_equals' => true,
'ternary_operator_spaces' => true,
'ternary_to_null_coalescing' => true,
'trailing_comma_in_multiline_array' => true,
'trim_array_spaces' => true,
'unary_operator_spaces' => true,
'void_return' => true,
'whitespace_after_comma_in_array' => true,
'yoda_style' => false,
])
->setFinder($finder);
24 changes: 17 additions & 7 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
# language: php

build:
dependencies:
before:
- 'composer self-update'
- 'composer update --prefer-stable --prefer-source --no-interaction --no-progress --no-suggest'
cache:
directories:
- vendor/
nodes:
analysis:
project_setup:
override: true
tests:
override: [php-scrutinizer-run]

filter:
paths: [src/*]
excluded_paths: [tests/*, vendor/*]

before_commands:
- 'composer self-update'
- 'composer update --prefer-stable --prefer-source --no-interaction --no-scripts --no-progress --no-suggest'

coding_style:
php:
upper_lower_casing:
Expand All @@ -17,8 +28,8 @@ coding_style:
true_false_null: lower
spaces:
around_operators:
concatenation: true
negation: false
concatenation: true
negation: false
other:
after_type_cast: true

Expand All @@ -34,7 +45,6 @@ tools:
enabled: true
config:
ruleset: 'unusedcode,naming,design,controversial,codesize'

php_cpd: true
php_loc: true
php_pdepend: true
Expand Down
1 change: 1 addition & 0 deletions .styleci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ enabled:
- blank_line_after_opening_tag
- cast_spaces
- combine_consecutive_unsets
- compact_nullable_typehint
- concat_with_spaces
- declare_equal_normalize
- declare_strict_types
Expand Down
10 changes: 5 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,18 @@ env:
- COMPOSER_FLAGS="--prefer-stable --prefer-dist"

php:
- 7.1
- 7.2
- 7.3
- 7.4
- nightly

matrix:
fast_finish: true
include:
- php: 7
- php: 7.1
env:
- COMPOSER_FLAGS="--prefer-lowest --prefer-stable --prefer-dist"
- php: 7
- php: 7.1
env:
- TEST_VERSION=true
- COMPOSER_FLAGS="--prefer-stable --prefer-dist"
Expand All @@ -36,12 +37,11 @@ before_install:
- composer self-update --stable --no-progress

install:
- travis_retry composer update $COMPOSER_FLAGS --no-interaction --no-scripts --no-progress
- travis_retry composer update $COMPOSER_FLAGS --no-interaction --no-progress
- if [[ $TEST_VERSION ]]; then travis_retry composer require php-coveralls/php-coveralls $COMPOSER_FLAGS --no-interaction --no-scripts --no-progress ; fi

script:
- if [[ $TEST_VERSION ]]; then composer qa && composer report-phpunit-clover ; fi

- if [[ -z $TEST_VERSION ]]; then composer test-phpunit ; fi

after_script:
Expand Down
30 changes: 16 additions & 14 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": "^7.0",
"php": "^7.1",
"ext-json": "*",
"ext-simplexml": "*",
"ext-libxml": "*",
Expand All @@ -37,15 +37,18 @@
"brainmaestro/composer-git-hooks": "^2.1",
"doctrine/annotations": "^1.4",
"friendsofphp/php-cs-fixer": "^2.0",
"infection/infection": "^0.7.0",
"infection/infection": "^0.9",
"phpmd/phpmd": "^2.0",
"phpmetrics/phpmetrics": "^2.0",
"phpstan/phpstan": "^0.9",
"phpstan/phpstan-strict-rules": "^0.9",
"phpunit/phpunit": "^5.7|^6.0",
"povils/phpmnd": "^1.1",
"sebastian/phpcpd": "^2.0",
"squizlabs/php_codesniffer": "^2.0",
"phpstan/extension-installer": "^1.0.1",
"phpstan/phpstan": "~0.12",
"phpstan/phpstan-deprecation-rules": "~0.12",
"phpstan/phpstan-strict-rules": "~0.12",
"phpunit/phpunit": "^7.1|^8.0",
"povils/phpmnd": "^2.0",
"roave/security-advisories": "dev-master",
"sebastian/phpcpd": "^4.0",
"squizlabs/php_codesniffer": "^3.0",
"thecodingmachine/phpstan-strict-rules": "~0.12",
"symfony/yaml": "^3.1"
},
"suggest": {
Expand Down Expand Up @@ -82,7 +85,6 @@
"qa-phpstan": "phpstan analyse --level max --configuration=phpstan.neon --memory-limit=2G --no-progress src",
"test-phpunit": "phpunit",
"test-infection": "infection",
"report-phpmetrics": "phpmetrics --report-html=build/metrics --offline .",
"report-phpunit-coverage": "phpunit --coverage-html build/coverage",
"report-phpunit-clover": "phpunit --coverage-clover build/logs/clover.xml",
"lint": [
Expand All @@ -99,14 +101,14 @@
"@qa-phpmnd",
"@qa-phpstan"
],
"report": [
"@report-phpmetrics",
"@report-phpunit-coverage"
],
"security": "composer outdated",
"test": [
"@test-phpunit",
"@test-infection"
],
"report": [
"@report-phpunit-coverage",
"@report-phpunit-clover"
]
},
"extra": {
Expand Down
9 changes: 5 additions & 4 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
includes:
- vendor/phpstan/phpstan-strict-rules/rules.neon

parameters:
level: max
paths:
- src
checkGenericClassInNonGenericObjectType: false
ignoreErrors:
- '/^Call to function is_array\(\) will always evaluate to false\.$/'
- message: '/^Call to deprecated method registerLoader\(\) of class Doctrine\\Common\\Annotations\\AnnotationRegistry:\nthis method is deprecated and will be removed in doctrine\/annotations 2\.0\nautoloading should be deferred to the globally registered autoloader by then\. For now,\nuse @example AnnotationRegistry::registerLoader\(.+\)$/'
path: src/Driver/AbstractAnnotationDriver.php
- message: '/^Parameter #1 \$argument of class ReflectionClass constructor expects class-string<T of object>\|T of object, string given\.$/'
path: src/Driver/AbstractAnnotationDriver.php
6 changes: 5 additions & 1 deletion src/Annotation/AbstractAnnotation.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ abstract class AbstractAnnotation
/**
* Abstract annotation constructor.
*
* @param mixed[]|\Traversable $parameters
* @param mixed[]|\Traversable|mixed $parameters
*
* @throws AnnotationException
*/
Expand All @@ -32,6 +32,9 @@ public function __construct($parameters)
if (!\is_array($parameters) && !$parameters instanceof \Traversable) {
throw new AnnotationException('Parameters must be an iterable');
}
if ($parameters instanceof \Traversable) {
$parameters = \iterator_to_array($parameters);
}

$configs = \array_keys(\get_object_vars($this));

Expand All @@ -47,6 +50,7 @@ public function __construct($parameters)

foreach ($configs as $config) {
if (isset($parameters[$config])) {
/** @var callable $callback */
$callback = [$this, 'set' . \ucfirst($config)];

\call_user_func($callback, $parameters[$config]);
Expand Down
18 changes: 10 additions & 8 deletions src/Driver/AbstractAnnotationDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,15 @@ protected function getMappingClasses(): array
{
AnnotationRegistry::registerLoader('class_exists');

/** @var class-string[] $mappingClasses */
$mappingClasses = [];

foreach ($this->locator->getMappingFiles() as $annotationFile) {
$mappingClasses[] = $this->loadClassFromFile($annotationFile);
}

return \array_map(
function (string $sourceClass) {
function (string $sourceClass): \ReflectionClass {
return new \ReflectionClass($sourceClass);
},
\array_filter(\array_unique($mappingClasses))
Expand All @@ -86,7 +87,8 @@ function (string $sourceClass) {
*/
protected function loadClassFromFile(string $annotationFile): string
{
$tokens = \token_get_all(\file_get_contents($annotationFile));
$content = \file_get_contents($annotationFile);
$tokens = \token_get_all($content !== false ? $content : '');
$hasClass = false;
$class = null;
$hasNamespace = false;
Expand All @@ -99,32 +101,32 @@ protected function loadClassFromFile(string $annotationFile): string
continue;
}

if ($hasClass && $token[0] === T_STRING) {
if ($hasClass && $token[0] === \T_STRING) {
$class = $namespace . '\\' . $token[1];

break;
}

if ($hasNamespace && $token[0] === T_STRING) {
if ($hasNamespace && $token[0] === \T_STRING) {
$namespace = '';

do {
$namespace .= $token[1];

$token = $tokens[++$i];
} while ($i < $length && \is_array($token) && \in_array($token[0], [T_NS_SEPARATOR, T_STRING], true));
} while ($i < $length && \is_array($token) && \in_array($token[0], [\T_NS_SEPARATOR, \T_STRING], true));

$hasNamespace = false;
}

if ($token[0] === T_CLASS) {
if ($token[0] === \T_CLASS) {
$hasClass = true;
}
if ($token[0] === T_NAMESPACE) {
if ($token[0] === \T_NAMESPACE) {
$hasNamespace = true;
}
}

return $class ?: '';
return $class ?? '';
}
}
Loading

0 comments on commit a6e635e

Please sign in to comment.