diff --git a/.cs.php b/.cs.php index e4ab7fc..2bba5e9 100644 --- a/.cs.php +++ b/.cs.php @@ -1,6 +1,8 @@ setUsingCache(false) ->setRiskyAllowed(true) ->setRules( @@ -19,6 +21,12 @@ 'concat_space' => ['spacing' => 'one'], 'compact_nullable_typehint' => true, 'declare_equal_normalize' => ['space' => 'single'], + 'general_phpdoc_annotation_remove' => [ + 'annotations' => [ + 'author', + 'package', + ], + ], 'increment_style' => ['style' => 'post'], 'list_syntax' => ['syntax' => 'short'], 'echo_tag_syntax' => ['format' => 'long'], @@ -32,9 +40,22 @@ 'method_argument_space' => ['on_multiline' => 'ensure_fully_multiline'], 'ordered_imports' => [ 'sort_algorithm' => 'alpha', - 'imports_order' => ['class', 'const', 'function'] + 'imports_order' => ['class', 'const', 'function'], ], 'single_line_throw' => false, + 'declare_strict_types' => false, + 'blank_line_between_import_groups' => true, + 'fully_qualified_strict_types' => true, + 'no_null_property_initialization' => false, + 'operator_linebreak' => [ + 'only_booleans' => true, + 'position' => 'beginning', + ], + 'global_namespace_import' => [ + 'import_classes' => true, + 'import_constants' => null, + 'import_functions' => null + ] ] ) ->setFinder( diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..0a6abee --- /dev/null +++ b/.editorconfig @@ -0,0 +1,22 @@ +root = true + +[*] +charset = utf-8 +indent_style = space +end_of_line = lf + +[composer.json] +indent_size = 4 + +[*.js] +indent_size = 4 + +[*.neon] +indent_size = 4 +indent_style = tab + +[*.xml] +indent_size = 4 + +[*.yml] +indent_size = 4 diff --git a/.gitattributes b/.gitattributes index ce09969..5a3d341 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,27 +1,35 @@ -# Path-based git attributes -# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html - -public/* linguist-vendored -docs/* linguist-documentation - # Set the default behavior, in case people don't have core.autocrlf set. # Git will always convert line endings to LF on checkout. You should use # this for files that must keep LF endings, even on Windows. * text eol=lf +# ------------------------------------------------------------------------------ +# All the files and directories that can be excluded from dist, +# we could have a more clean vendor/ +# +# So when someone will install that package through with --prefer-dist option, +# all the files and directories listed in .gitattributes file will be excluded. +# This could have a big impact on big deployments and/or testing. +# ------------------------------------------------------------------------------ + +/tests export-ignore +/build export-ignore +/docs export-ignore +/build.xml export-ignore +/phpunit.xml export-ignore +/.gitattributes export-ignore +/.gitignore export-ignore +/.scrutinizer.* export-ignore +/.editorconfig export-ignore + # Define binary file attributes. # - Do not treat them as text. # - Include binary diff in patches instead of "binary files differ." +*.pdf binary +*.mo binary *.gif binary *.ico binary *.jpg binary +*.jpeg binary *.png binary -*.phar binary *.zip binary -*.gz binary -*.otf binary -*.eot binary -*.svg binary -*.ttf binary -*.woff binary -*.woff2 binary diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 50387d5..a4bf3d5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,48 +1,41 @@ name: build -on: [push, pull_request] +on: [ push, pull_request ] jobs: - run: - runs-on: ${{ matrix.operating-system }} - strategy: - matrix: - operating-system: [ubuntu-latest] - php-versions: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2'] - name: PHP ${{ matrix.php-versions }} Test on ${{ matrix.operating-system }} - - steps: - - name: Checkout - uses: actions/checkout@v1 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php-versions }} - extensions: mbstring, pdo, pdo_mysql, intl, zip - coverage: none - - - name: Check PHP Version - run: php -v - - - name: Check Composer Version - run: composer -V - - - name: Check PHP Extensions - run: php -m - - - name: Validate composer.json and composer.lock - run: composer validate - - - name: Install dependencies for PHP 7 - if: matrix.php-versions < '8.0' - run: composer update --prefer-dist --no-progress - - - name: Install dependencies for PHP 8 - if: matrix.php-versions >= '8.0' - run: composer update --prefer-dist --no-progress --ignore-platform-reqs - - - name: Run test suite - run: composer check - env: - PHP_CS_FIXER_IGNORE_ENV: 1 + run: + runs-on: ${{ matrix.operating-system }} + strategy: + matrix: + operating-system: [ ubuntu-latest ] + php-versions: [ '8.1', '8.2' ] + name: PHP ${{ matrix.php-versions }} Test on ${{ matrix.operating-system }} + + steps: + - name: Checkout + uses: actions/checkout@v1 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + extensions: mbstring, intl, zip + coverage: none + + - name: Check PHP Version + run: php -v + + - name: Check Composer Version + run: composer -V + + - name: Check PHP Extensions + run: php -m + + - name: Validate composer.json and composer.lock + run: composer validate + + - name: Install dependencies + run: composer install --prefer-dist --no-progress --no-suggest + + - name: Run test suite + run: composer test:all diff --git a/.gitignore b/.gitignore index cbbe3e9..a4689b6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,11 +1,7 @@ .idea/ -nbproject/ -composer.phar composer.lock -.DS_STORE -cache.properties -.php_cs.cache -.vscode +nbproject/ vendor/ build/ +.phpunit.cache/ .phpunit.result.cache \ No newline at end of file diff --git a/.scrutinizer.yml b/.scrutinizer.yml index e37aed8..3514e2e 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -1,6 +1,6 @@ filter: - paths: ["src/*"] - excluded_paths: ["vendor/*", "tests/*", "resources/", "public/"] + paths: [ "src/*" ] + excluded_paths: [ "vendor/*", "tests/*" ] checks: php: @@ -12,7 +12,10 @@ tools: build: environment: - php: 7.4 + php: + version: 8.1.2 + ini: + xdebug.mode: coverage mysql: false node: false postgresql: false @@ -30,11 +33,9 @@ build: dependencies: before: - composer self-update - - composer update --no-interaction --prefer-dist --no-progress tests: before: - - - command: composer test:coverage + - command: composer test:coverage coverage: file: 'build/logs/clover.xml' format: 'clover' diff --git a/LICENSE b/LICENSE index 0328ef6..bf7a9a3 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2020 odan +Copyright (c) 2023 odan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -19,3 +19,4 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + diff --git a/README.md b/README.md index 3ea96b0..42da7ca 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ the [notification pattern](https://martinfowler.com/articles/replaceThrowWithNot ## Requirements -* PHP 7.2+ or 8.0+ +* PHP 8.1+ ## Installation diff --git a/composer.json b/composer.json index 371e285..f97bee5 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,8 @@ { "name": "selective/validation", - "type": "library", "description": "Validation error collector and transformer", + "license": "MIT", + "type": "library", "keywords": [ "validation", "middleware", @@ -9,9 +10,8 @@ "slim4", "psr15" ], - "license": "MIT", "require": { - "php": "^7.2 || ^8.0", + "php": "^8.1", "ext-json": "*", "psr/http-factory": "^1.0.1", "psr/http-server-middleware": "^1.0.1" @@ -21,16 +21,13 @@ "fig/http-message-util": "^1.1", "friendsofphp/php-cs-fixer": "^3", "nyholm/psr7": "^1.4", - "overtrue/phplint": "^1.1", "phpstan/phpstan": "^1", - "phpunit/phpunit": "^8 || ^9", + "phpunit/phpunit": "^10", "relay/relay": "^2.0", "slim/psr7": "^1", - "squizlabs/php_codesniffer": "^3.5" - }, - "config": { - "sort-packages": true + "squizlabs/php_codesniffer": "^3" }, + "minimum-stability": "stable", "autoload": { "psr-4": { "Selective\\Validation\\": "src/" @@ -41,21 +38,27 @@ "Selective\\Validation\\Test\\": "tests/" } }, - "minimum-stability": "stable", + "config": { + "sort-packages": true + }, "scripts": { - "cs:check": "php-cs-fixer fix --dry-run --format=txt --verbose --diff --config=.cs.php", - "cs:fix": "php-cs-fixer fix --config=.cs.php", - "lint": "phplint ./ --exclude=vendor --no-interaction --no-cache", - "phpstan": "phpstan analyse src --level=max -c phpstan.neon --no-progress --ansi", + "cs:check": [ + "@putenv PHP_CS_FIXER_IGNORE_ENV=1", + "php-cs-fixer fix --dry-run --format=txt --verbose --diff --config=.cs.php --ansi" + ], + "cs:fix": [ + "@putenv PHP_CS_FIXER_IGNORE_ENV=1", + "php-cs-fixer fix --config=.cs.php --ansi --verbose" + ], "sniffer:check": "phpcs --standard=phpcs.xml", "sniffer:fix": "phpcbf --standard=phpcs.xml", - "test": "phpunit --configuration phpunit.xml --do-not-cache-result", + "stan": "phpstan analyse -c phpstan.neon --no-progress --ansi", + "test": "phpunit --configuration phpunit.xml --do-not-cache-result --colors=always", "test:all": [ - "@lint", "@cs:check", "@sniffer:check", - "@phpstan", - "@test:coverage" + "@stan", + "@test" ], "test:coverage": "php -d xdebug.mode=coverage -r \"require 'vendor/bin/phpunit';\" -- --configuration phpunit.xml --do-not-cache-result --colors=always --coverage-clover build/logs/clover.xml --coverage-html build/coverage" } diff --git a/phpcs.xml b/phpcs.xml index f19d341..f2f42d9 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -9,27 +9,8 @@ ./src ./tests - - + - - - warning - */tests/ - - - warning - - - warning - */config/ - - - warning - - - warning - warning @@ -45,4 +26,4 @@ - + \ No newline at end of file diff --git a/phpstan.neon b/phpstan.neon index 9e81988..d5512d5 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,5 @@ parameters: - level: max + level: 8 reportUnmatchedIgnoredErrors: false checkMissingIterableValueType: false checkGenericClassInNonGenericObjectType: false diff --git a/phpunit.xml b/phpunit.xml index 2250738..2927473 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -3,20 +3,22 @@ bootstrap="vendor/autoload.php" colors="true" backupGlobals="false" - backupStaticAttributes="false" - xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"> - + xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd" + cacheDirectory=".phpunit.cache" + backupStaticProperties="false"> + + + + tests + + + src - build vendor + build - - - - tests - - + diff --git a/tests/Exception/ValidationExceptionTest.php b/tests/Exception/ValidationExceptionTest.php index ed67a44..2163ac3 100644 --- a/tests/Exception/ValidationExceptionTest.php +++ b/tests/Exception/ValidationExceptionTest.php @@ -21,7 +21,7 @@ public function testSuccessAction(): void $service = new TestService(); $result = $service->process(1); - $this->assertSame('{"success":true}', (json_encode($result))); + $this->assertSame('{"success":true}', json_encode($result)); } /**