diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index deef99c..10b872c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,17 +7,17 @@ on: branches: [ master ] jobs: - build: + ci: runs-on: ubuntu-latest strategy: matrix: - php-versions: [ '8.1', '8.2', '8.3' ] + php-versions: [ '8.3', '8.4', '8.5' ] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: - fetch-depth: 0 # To avoid "Shallow clone detected" error in SonarCloud report + fetch-depth: 0 #~ PHP Setup - name: Setup PHP ${{ matrix.php-versions }} @@ -48,30 +48,18 @@ jobs: #~ CI part - name: Dependencies - run: make deps + run: make php/deps - name: Check Code Style - run: make phpcs + run: make php/check - name: Units Tests - run: make tests + run: make php/tests - name: Fix unit tests report path run: | sed -i 's+'$GITHUB_WORKSPACE'+/github/workspace+g' build/reports/phpunit/clover.xml sed -i 's+'$GITHUB_WORKSPACE'+/github/workspace+g' build/reports/phpunit/unit.xml - - name: PHP 8.1 Compatibility - run: make php81compatibility - - - name: PHP 8.3 Compatibility - run: make php83compatibility - - name: PHP Static Analyze - run: make analyze - - - name: SonarCloud Scan - uses: SonarSource/sonarcloud-github-action@v2.1.1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + run: make php/analyze diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml new file mode 100644 index 0000000..9130fbb --- /dev/null +++ b/.github/workflows/sonarcloud.yml @@ -0,0 +1,46 @@ +name: SonarQube + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + sonarcloud: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 # To avoid "Shallow clone detected" error in SonarCloud report + + #~ PHP Setup + - name: Setup PHP 8.3 # Minimum version + uses: shivammathur/setup-php@v2 + with: + php-version: '8.3' + + #~ Composer Cache + - name: Get Composer Cache Directory + id: composer-cache + run: | + echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT + + - uses: actions/cache@v3 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-composer- + + - name: Install dependencies + if: steps.composer-cache.outputs.cache-hit != 'true' + run: make install + + - name: Units Tests + run: make php/tests # To generate the coverage report + + - name: SonarQube Scan + uses: SonarSource/sonarqube-scan-action@v7 + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index b0ac8d3..d21eb4c 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -4,7 +4,7 @@ //~ Rules ->setRules( [ - '@PER-CS2.0' => true, + '@PER-CS3x0' => true, ] ) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5689ce6..dcb3feb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,22 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ``` ---- +## [6.0.0] - 2026-01-05 +[6.0.0]: https://github.com/eureka-framework/component-password/compare/5.0.0...6.0.0 +### Added +- Add support of PHP 8.3+ +- Add shipmonk dependency checker +### Removed +- Drop PHP 8.1 & 8.2 support +- Remove maglnet dependency checker +### Changed +- Code style fixes +- Dev dependencies upgrade +- Update Makefile +- Update CI config + +---- + ## [5.0.0] - 2023-06-14 [5.0.0]: https://github.com/eureka-framework/component-password/compare/4.2.0...5.0.0 ### Changed diff --git a/Makefile b/Makefile index 2e761ad..199be3e 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,8 @@ -.PHONY: validate install update deps phpcs phpcsf php81compatibility php83compatibility phpstan analyze tests testdox ci clean build/reports/phpunit build/reports/phpcs build/reports/phpstan +.PHONY: validate install update php/deps php/check php/fix php/min-compatibility php/max-compatibility php/phpstan php/analyze php/tests php/test php/testdox ci clean +PHP_MIN_VERSION := "8.3" +PHP_MAX_VERSION := "8.5" +COMPOSER_BIN := composer define header = @if [ -t 1 ]; then printf "\n\e[37m\e[100m \e[104m $(1) \e[0m\n"; else printf "\n### $(1)\n"; fi endef @@ -7,78 +10,71 @@ endef #~ Composer dependency validate: $(call header,Composer Validation) - @composer validate + @${COMPOSER_BIN} validate install: $(call header,Composer Install) - @composer install + @${COMPOSER_BIN} install update: $(call header,Composer Update) - @composer update - @composer bump --dev-only + @${COMPOSER_BIN} update + @${COMPOSER_BIN} bump --dev-only composer.lock: install #~ Vendor binaries dependencies -vendor/bin/php-cs-fixer: -vendor/bin/phpstan: -vendor/bin/phpunit: +vendor/bin/php-cs-fixer: composer.lock +vendor/bin/phpstan: composer.lock +vendor/bin/phpunit: composer.lock #~ Report directories dependencies build/reports/phpunit: @mkdir -p build/reports/phpunit -build/reports/phpcs: - @mkdir -p build/reports/cs - build/reports/phpstan: @mkdir -p build/reports/phpstan #~ main commands -deps: composer.json +php/deps: composer.json $(call header,Checking Dependencies) - @XDEBUG_MODE=off ./vendor/bin/composer-require-checker check --config-file="./ci/deps-config.json" + @XDEBUG_MODE=off ./vendor/bin/composer-dependency-analyser --config ./ci/composer-dependency-analyser.php # for shadow, unused required dependencies and ext-* missing dependencies -phpcs: vendor/bin/php-cs-fixer build/reports/phpcs +php/check: vendor/bin/php-cs-fixer $(call header,Checking Code Style) - @./vendor/bin/php-cs-fixer check - -phpcsf: vendor/bin/php-cs-fixer + @XDEBUG_MODE=off ./vendor/bin/php-cs-fixer check +php/fix: vendor/bin/php-cs-fixer $(call header,Fixing Code Style) - @./vendor/bin/php-cs-fixer fix -v + @XDEBUG_MODE=off ./vendor/bin/php-cs-fixer fix -v -php81compatibility: vendor/bin/phpstan build/reports/phpstan - $(call header,Checking PHP 8.1 compatibility) - @XDEBUG_MODE=off ./vendor/bin/phpstan analyse --configuration=./ci/php81-compatibility.neon --error-format=table +php/min-compatibility: vendor/bin/phpstan build/reports/phpstan + $(call header,Checking PHP ${PHP_MIN_VERSION} compatibility) + @XDEBUG_MODE=off ./vendor/bin/phpstan analyse --configuration=./ci/phpmin-compatibility.neon --error-format=table -php83compatibility: vendor/bin/phpstan build/reports/phpstan - $(call header,Checking PHP 8.3 compatibility) - @XDEBUG_MODE=off ./vendor/bin/phpstan analyse --configuration=./ci/php83-compatibility.neon --error-format=table +php/max-compatibility: vendor/bin/phpstan build/reports/phpstan #ci + $(call header,Checking PHP ${PHP_MAX_VERSION} compatibility) + @XDEBUG_MODE=off ./vendor/bin/phpstan analyse --configuration=./ci/phpmax-compatibility.neon --error-format=table -phpstan: vendor/bin/phpstan build/reports/phpstan - $(call header,Running Static Analyze) - @XDEBUG_MODE=off ./vendor/bin/phpstan analyse --error-format=checkstyle > ./build/reports/phpstan/phpstan.xml - -analyze: vendor/bin/phpstan build/reports/phpstan +php/analyze: vendor/bin/phpstan build/reports/phpstan #manual & ci $(call header,Running Static Analyze - Pretty tty format) @XDEBUG_MODE=off ./vendor/bin/phpstan analyse --error-format=table -tests: vendor/bin/phpunit build/reports/phpunit #ci +php/tests: vendor/bin/phpunit build/reports/phpunit #ci $(call header,Running Unit Tests) - @rm -rf ./tests/unit/Generated/Entity ./tests/unit/Generated/Infrastructure ./tests/unit/Generated/Repository - @XDEBUG_MODE=coverage php -dzend_extension=xdebug.so ./vendor/bin/phpunit --testsuite=unit --coverage-clover=./build/reports/phpunit/clover.xml --log-junit=./build/reports/phpunit/unit.xml --coverage-php=./build/reports/phpunit/unit.cov --coverage-html=./build/reports/coverage/ --fail-on-warning + @XDEBUG_MODE=coverage php ./vendor/bin/phpunit --testsuite=unit --coverage-clover=./build/reports/phpunit/clover.xml --log-junit=./build/reports/phpunit/unit.xml --coverage-php=./build/reports/phpunit/unit.cov --coverage-html=./build/reports/coverage/ --fail-on-warning + +php/test: php/tests -integration: vendor/bin/phpunit build/reports/phpunit #manual +php/integration: vendor/bin/phpunit build/reports/phpunit #manual $(call header,Running Integration Tests) @XDEBUG_MODE=coverage php -dzend_extension=xdebug.so ./vendor/bin/phpunit --testsuite=integration --fail-on-warning -testdox: vendor/bin/phpunit #manual +php/testdox: vendor/bin/phpunit #manual $(call header,Running Unit Tests (Pretty format)) @XDEBUG_MODE=coverage php -dzend_extension=xdebug.so ./vendor/bin/phpunit --testsuite=unit --fail-on-warning --testdox clean: - $(call header,Cleaning previous build) + $(call header,Cleaning previous build) #manual @if [ "$(shell ls -A ./build)" ]; then rm -rf ./build/*; fi; echo " done" -ci: clean validate deps install phpcs tests integration php81compatibility php83compatibility analyze +ci: clean validate install php/deps php/check php/tests php/integration php/min-compatibility php/max-compatibility php/analyze diff --git a/README.md b/README.md index d6e1429..3a29c32 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # component-password [![Current version](https://img.shields.io/packagist/v/eureka/component-password.svg?logo=composer)](https://packagist.org/packages/eureka/component-password) -[![Supported PHP version](https://img.shields.io/static/v1?logo=php&label=PHP&message=8.1%20-%208.3&color=777bb4)](https://packagist.org/packages/eureka/component-password) +[![Supported PHP version](https://img.shields.io/static/v1?logo=php&label=PHP&message=>%3D8.3&color=777bb4)](https://packagist.org/packages/eureka/component-password) ![CI](https://github.com/eureka-framework/component-password/workflows/CI/badge.svg) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=eureka-framework_component-password&metric=alert_status)](https://sonarcloud.io/dashboard?id=eureka-framework_component-password) [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=eureka-framework_component-password&metric=coverage)](https://sonarcloud.io/dashboard?id=eureka-framework_component-password) @@ -114,40 +114,40 @@ NB: For the components, the `composer.lock` file is not committed. #### Tests You can run unit tests (with coverage) on your side with following command: ```bash -make tests +make php/tests ``` You can run integration tests (without coverage) on your side with following command: ```bash -make integration +make php/integration ``` For prettier output (but without coverage), you can use the following command: ```bash -make testdox # run tests without coverage reports but with prettified output +make php/testdox # run tests without coverage reports but with prettified output ``` #### Code Style You also can run code style check with following commands: ```bash -make phpcs +make php/check ``` You also can run code style fixes with following commands: ```bash -make phpcsf +make php/fix ``` #### Check for missing explicit dependencies You can check if any explicit dependency is missing with the following command: ```bash -make deps +make php/deps ``` #### Static Analysis To perform a static analyze of your code (with phpstan, lvl 9 at default), you can use the following command: ```bash -make analyse +make php/analyse ``` To ensure you code still compatible with current supported version at Deezer and futures versions of php, you need to @@ -155,12 +155,12 @@ run the following commands (both are required for full support): Minimal supported version: ```bash -make php81compatibility +make php/min-compatibility ``` Maximal supported version: ```bash -make php83compatibility +make php/max-compatibility ``` #### CI Simulation diff --git a/ci/composer-dependency-analyser.php b/ci/composer-dependency-analyser.php new file mode 100644 index 0000000..accd527 --- /dev/null +++ b/ci/composer-dependency-analyser.php @@ -0,0 +1,13 @@ +addPathToScan(__DIR__ . '/../src', false) + ->addPathToScan(__DIR__ . '/../scripts', false) + ->addPathToScan(__DIR__ . '/../tests', true) + ->ignoreErrorsOnPackage('eureka/component-console', [ErrorType::DEV_DEPENDENCY_IN_PROD]) +; diff --git a/ci/deps-config.json b/ci/deps-config.json deleted file mode 100644 index d2c4fc0..0000000 --- a/ci/deps-config.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "symbol-whitelist": [ - "Eureka\\Component\\Console\\AbstractScript", - "Eureka\\Component\\Console\\Help", - "Eureka\\Component\\Console\\Option\\Option", - "Eureka\\Component\\Console\\Option\\Options" - ] -} diff --git a/ci/php81-compatibility.neon b/ci/phpmax-compatibility.neon similarity index 92% rename from ci/php81-compatibility.neon rename to ci/phpmax-compatibility.neon index e523201..c89932b 100644 --- a/ci/php81-compatibility.neon +++ b/ci/phpmax-compatibility.neon @@ -3,7 +3,7 @@ includes: - ./../vendor/phpstan/phpstan-phpunit/rules.neon parameters: - phpVersion: 80100 + phpVersion: 80500 level: 0 paths: - ./../src diff --git a/ci/php83-compatibility.neon b/ci/phpmin-compatibility.neon similarity index 100% rename from ci/php83-compatibility.neon rename to ci/phpmin-compatibility.neon diff --git a/composer.json b/composer.json index e82008d..ee19d6e 100644 --- a/composer.json +++ b/composer.json @@ -29,19 +29,19 @@ }, "require": { - "php": "8.1.*||8.2.*||8.3.*", + "php": ">=8.3", "ext-mbstring": "*" }, "require-dev": { - "friendsofphp/php-cs-fixer": "^3.51.0", - "eureka/component-console": "^6.1.0", - "maglnet/composer-require-checker": "^4.7.1", - "phpstan/phpstan": "^1.10.60", - "phpstan/phpstan-phpunit": "^1.3.16", - "phpstan/phpstan-strict-rules": "^1.5.2", - "phpunit/phpcov": "^9.0.2", - "phpunit/phpunit": "^10.5.12" + "friendsofphp/php-cs-fixer": "^3.92.4", + "eureka/component-console": "^7.0.0", + "phpstan/phpstan": "^2.1.33", + "phpstan/phpstan-phpunit": "^2.0.11", + "phpstan/phpstan-strict-rules": "^2.0.7", + "phpunit/phpcov": "^11.0.3", + "phpunit/phpunit": "^12.5.4", + "shipmonk/composer-dependency-analyser": "^1.8.4" }, "suggest": { diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 04e46e6..3c2a971 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -3,7 +3,7 @@ includes: - ./vendor/phpstan/phpstan-phpunit/rules.neon parameters: - phpVersion: 80100 + phpVersion: 80300 level: max paths: - ./src @@ -13,7 +13,4 @@ parameters: bootstrapFiles: - ./vendor/autoload.php - ignoreErrors: - - - message: '#Cannot cast array\|string to string.#' - path: ./src/StringGenerator.php + ignoreErrors: [] diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 925796d..30e0ffd 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,17 +1,25 @@ - - - ./tests/unit - - + displayDetailsOnTestsThatTriggerDeprecations="true" + cacheDirectory="build/.phpunit.cache" +> + ./src + + + + ./tests/unit + + + + + + diff --git a/scripts/Generator.php b/scripts/Generator.php index 3c68a73..751cdc2 100644 --- a/scripts/Generator.php +++ b/scripts/Generator.php @@ -17,11 +17,7 @@ use Eureka\Component\Password\StringGenerator; /** - * Console Abstraction class. - * Must be parent class for every console script class. - * - * @author Romain Cottard - * + * Sample script to generate password * @codeCoverageIgnore */ class Generator extends Console\AbstractScript diff --git a/src/PasswordGenerator.php b/src/PasswordGenerator.php index 102955a..e648410 100644 --- a/src/PasswordGenerator.php +++ b/src/PasswordGenerator.php @@ -31,7 +31,7 @@ public function generate( float $alpha = 0.6, float $numeric = 0.2, float $other = 0.2, - bool $removeAmbiguousChars = true + bool $removeAmbiguousChars = true, ): Password { return new Password($this->generateString($length, $alpha, $numeric, $other, $removeAmbiguousChars)); } @@ -52,7 +52,7 @@ public function generateString( float $alpha = 0.6, float $numeric = 0.2, float $other = 0.2, - bool $removeAmbiguousChars = true + bool $removeAmbiguousChars = true, ): string { if ($length <= 0 || $alpha < 0 || $numeric < 0 || $other < 0 || ($alpha + $numeric + $other) < 0.5) { @@ -67,7 +67,7 @@ public function generateString( $chars .= $this->generator->generate( (int) \ceil($alpha * $weight), StringGenerator::CHAR_ALPHA, - $removeAmbiguousChars + $removeAmbiguousChars, ); } @@ -75,7 +75,7 @@ public function generateString( $chars .= $this->generator->generate( (int) \ceil($numeric * $weight), StringGenerator::CHAR_DIGITS, - $removeAmbiguousChars + $removeAmbiguousChars, ); } @@ -83,7 +83,7 @@ public function generateString( $chars .= $this->generator->generate( (int) \ceil($other * $weight), StringGenerator::CHAR_SYMBOLS, - $removeAmbiguousChars + $removeAmbiguousChars, ); } diff --git a/tests/unit/PasswordTest.php b/tests/unit/PasswordTest.php index 49436c8..b8f49d5 100644 --- a/tests/unit/PasswordTest.php +++ b/tests/unit/PasswordTest.php @@ -21,13 +21,6 @@ */ class PasswordTest extends TestCase { - public function testICanInstantiatePasswordClass(): void - { - $password = new Password('SomeSecretPassword1!'); - - $this->assertInstanceOf(Password::class, $password); - } - public function testICanRetrievePlainPasswordFromPasswordInstance(): void { $password = new Password('SomeSecretPassword1!');