From d4c1d8838b0cf5d563bb54be574416b19ff6c3e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Bok?= Date: Thu, 1 Feb 2024 14:28:49 +0100 Subject: [PATCH 1/2] DE-55463 Update Sonar Qube integration Added rector --- .github/workflows/main.yml | 128 ++++-------------- .github/workflows/sonar-qube-master.yml | 12 ++ .gitignore | 3 +- composer.json | 12 +- phpstan.neon | 2 +- phpunit.xml | 22 ++- rector.php | 31 +++++ .../DummyTestOperationProcessorAccessor.php | 5 +- src/UnitOfWork/NaiveUnitOfWorkExecutor.php | 7 +- src/UnitOfWork/OperationConsolidator.php | 3 +- src/UnitOfWork/ReducingUnitOfWorkExecutor.php | 10 +- src/UnitOfWork/UnitOfWorkReducer.php | 5 +- src/UnitOfWork/UnitOfWorkReducerTest.php | 2 +- src/UnitOfWork/UnitOfWorkTest.php | 1 + var/.gitkeep | 0 15 files changed, 99 insertions(+), 144 deletions(-) create mode 100644 .github/workflows/sonar-qube-master.yml create mode 100644 rector.php create mode 100644 var/.gitkeep diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index be4b559..758be38 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -4,126 +4,50 @@ on: [pull_request, workflow_dispatch] jobs: phpstan: - runs-on: ubuntu-latest strategy: - fail-fast: false matrix: php-version: - - 7.4 - 8.1 - - steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php-version }} - extensions: mbstring, sockets - - - name: Get composer cache directory - id: composercache - run: echo "::set-output name=dir::$(composer config cache-files-dir)" - - - name: Cache composer dependencies - uses: actions/cache@v2 - with: - path: ${{ steps.composercache.outputs.dir }} - key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} - restore-keys: ${{ runner.os }}-composer- - - - name: Install dependencies - run: composer install --prefer-dist - - - name: Run phpstan - run: composer phpstan - + - 8.2 + uses: BrandEmbassy/github-actions/.github/workflows/php-phpstan.yml@master + with: + PHP_VERSION: ${{ matrix.php-version }} ecs: - runs-on: ubuntu-latest strategy: fail-fast: false matrix: php-version: - - 7.4 - 8.1 + - 8.2 + uses: BrandEmbassy/github-actions/.github/workflows/php-ecs.yml@master + with: + PHP_VERSION: ${{ matrix.php-version }} - steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php-version }} - extensions: mbstring, sockets - - - name: Get composer cache directory - id: composercache - run: echo "::set-output name=dir::$(composer config cache-files-dir)" - - - name: Cache composer dependencies - uses: actions/cache@v2 - with: - path: ${{ steps.composercache.outputs.dir }} - key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} - restore-keys: ${{ runner.os }}-composer- - - - name: Install dependencies - run: composer install --prefer-dist - - - name: Run code-sniffer - run: composer check-cs - + rector: + uses: BrandEmbassy/github-actions/.github/workflows/php-rector.yml@master + with: + PHP_VERSION: '8.1' + RECTOR_CACHE_PATH: './var/rector' phpunit: - runs-on: ubuntu-latest strategy: - fail-fast: false matrix: composer-arg: - "install" - "update --prefer-lowest" php-version: - - 7.4 - 8.1 - - steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php-version }} - extensions: mbstring, sockets${{ matrix.php-version == '8.1' && matrix.composer-arg == 'install' && ', xdebug' || '' }} - - - name: Get composer cache directory - id: composercache - run: echo "::set-output name=dir::$(composer config cache-files-dir)" - - - name: Cache composer dependencies - uses: actions/cache@v2 - with: - path: ${{ steps.composercache.outputs.dir }} - key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} - restore-keys: ${{ runner.os }}-composer- - - - name: Install dependencies - run: composer ${{ matrix.composer-arg }} --prefer-dist - - - name: Run tests - run: composer test - if: matrix.php-version != '8.1' && matrix.composer-arg != 'install' - - - name: Run tests with coverage - run: composer test-with-coverage - if: matrix.php-version == '8.1' && matrix.composer-arg == 'install' - - - name: SonarQube Scan - uses: SonarSource/sonarqube-scan-action@master - if: matrix.php-version == '8.1' && matrix.composer-arg == 'install' - env: - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - SONAR_HOST_URL: "https://sonar.nice.com" + - 8.2 + exclude: + - composer-arg: install + php-version: 8.1 + uses: BrandEmbassy/github-actions/.github/workflows/php-phpunit.yml@master + with: + COMPOSER_ARG: ${{ matrix.composer-arg }} + PHP_VERSION: ${{ matrix.php-version }} + + phpunit-with-sonar-qube: + uses: BrandEmbassy/github-actions/.github/workflows/php-phpunit-with-sonar-qube.yml@master + secrets: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} diff --git a/.github/workflows/sonar-qube-master.yml b/.github/workflows/sonar-qube-master.yml new file mode 100644 index 0000000..08d9c87 --- /dev/null +++ b/.github/workflows/sonar-qube-master.yml @@ -0,0 +1,12 @@ +name: Sonar Qube on push to master + +on: + push: + branches: + - master + +jobs: + phpunit-with-sonar-qube: + uses: BrandEmbassy/github-actions/.github/workflows/php-phpunit-with-sonar-qube.yml@master + secrets: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} diff --git a/.gitignore b/.gitignore index 54d9347..431a825 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ vendor/ -temp/ +/var/* +!.gitkeep composer.lock .phpunit.cache coverage.xml diff --git a/composer.json b/composer.json index ec3326a..028cd21 100644 --- a/composer.json +++ b/composer.json @@ -7,15 +7,15 @@ } }, "require": { - "php": "^7.4 || >=8.1", + "php": ">=8.1", "beberlei/assert": "^3.2", "psr/log": "^1.1" }, "require-dev": { - "brandembassy/coding-standard": "10.0.0-beta", + "brandembassy/coding-standard": "^11.1", "mockery/mockery": "^1.5.1", "nette/utils": "^2.4 || ^3.0", - "phpunit/phpunit": "^9.6.6", + "phpunit/phpunit": "^10.0", "roave/security-advisories": "dev-latest" }, "scripts": { @@ -23,8 +23,10 @@ "fix-cs": "vendor/bin/ecs check --fix --ansi", "phpstan": "php -dxdebug.mode=off vendor/bin/phpstan analyse --memory-limit=-1", "phpstan-generate-baseline": "php -dxdebug.mode=off vendor/bin/phpstan analyse --memory-limit=-1 --generate-baseline", - "test": "./vendor/bin/phpunit", - "test-with-coverage": "php -dxdebug.mode=coverage ./vendor/bin/phpunit --coverage-clover=coverage.xml --log-junit=test-report.xml" + "phpunit": "./vendor/bin/phpunit --no-coverage", + "phpunit-cc": "php -dxdebug.mode=coverage ./vendor/bin/phpunit --coverage-clover=coverage.xml --log-junit=test-report.xml", + "check-rector": "vendor/bin/rector process --dry-run --ansi", + "fix-rector": "vendor/bin/rector process --ansi" }, "minimum-stability": "dev", "prefer-stable": true, diff --git a/phpstan.neon b/phpstan.neon index e896051..7f68b6f 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -6,4 +6,4 @@ parameters: paths: - src - tmpDir: temp/phpstan + tmpDir: var/phpstan diff --git a/phpunit.xml b/phpunit.xml index ef541cd..bf917ba 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,27 +1,23 @@ - + + failOnWarning="true"> src - - + src - + diff --git a/rector.php b/rector.php new file mode 100644 index 0000000..b43609a --- /dev/null +++ b/rector.php @@ -0,0 +1,31 @@ +phpstanConfig(__DIR__ . '/phpstan.neon'); + + $rectorConfig->cacheClass(FileCacheStorage::class); + $rectorConfig->cacheDirectory('./var/rector'); + + $rectorConfig->paths([ + __DIR__ . '/src', + ]); + + $skipList = []; + + $rectorConfig->skip( + array_merge( + $defaultSkipList, + $skipList + ) + ); +}; diff --git a/src/UnitOfWork/DummyTestOperationProcessorAccessor.php b/src/UnitOfWork/DummyTestOperationProcessorAccessor.php index 0e1b9ef..4feb245 100644 --- a/src/UnitOfWork/DummyTestOperationProcessorAccessor.php +++ b/src/UnitOfWork/DummyTestOperationProcessorAccessor.php @@ -7,10 +7,7 @@ */ class DummyTestOperationProcessorAccessor implements OperationProcessorAccessor { - /** - * @var OperationProcessor - */ - private $operationProcessor; + private OperationProcessor $operationProcessor; public function __construct(OperationProcessor $operationProcessor) diff --git a/src/UnitOfWork/NaiveUnitOfWorkExecutor.php b/src/UnitOfWork/NaiveUnitOfWorkExecutor.php index bffed4d..6bd9b1f 100644 --- a/src/UnitOfWork/NaiveUnitOfWorkExecutor.php +++ b/src/UnitOfWork/NaiveUnitOfWorkExecutor.php @@ -16,12 +16,9 @@ class NaiveUnitOfWorkExecutor implements UnitOfWorkExecutor /** * @var OperationProcessorAccessor[] */ - private $operationProcessorAccessors; + private array $operationProcessorAccessors; - /** - * @var LoggerInterface - */ - private $logger; + private LoggerInterface $logger; /** diff --git a/src/UnitOfWork/OperationConsolidator.php b/src/UnitOfWork/OperationConsolidator.php index 9b49f48..ecc3de4 100644 --- a/src/UnitOfWork/OperationConsolidator.php +++ b/src/UnitOfWork/OperationConsolidator.php @@ -5,7 +5,6 @@ use function array_pop; use function array_reverse; use function array_values; -use function count; /** * @final @@ -28,7 +27,7 @@ public function consolidate(array $operations): array /** @var Operation[] $merged */ $merged = [array_pop($operations)]; - while (count($operations) > 0) { + while ($operations !== []) { /** @var Operation $previous */ $previous = array_pop($merged); /** @var Operation $current */ diff --git a/src/UnitOfWork/ReducingUnitOfWorkExecutor.php b/src/UnitOfWork/ReducingUnitOfWorkExecutor.php index e5baf55..69f7e60 100644 --- a/src/UnitOfWork/ReducingUnitOfWorkExecutor.php +++ b/src/UnitOfWork/ReducingUnitOfWorkExecutor.php @@ -7,15 +7,9 @@ */ class ReducingUnitOfWorkExecutor implements UnitOfWorkExecutor { - /** - * @var OperationConsolidator - */ - private $consolidator; + private OperationConsolidator $consolidator; - /** - * @var UnitOfWorkExecutor - */ - private $unitOfWorkExecutor; + private UnitOfWorkExecutor $unitOfWorkExecutor; public function __construct(UnitOfWorkExecutor $unitOfWorkExecutor, OperationConsolidator $consolidator) diff --git a/src/UnitOfWork/UnitOfWorkReducer.php b/src/UnitOfWork/UnitOfWorkReducer.php index 551394f..7d35937 100644 --- a/src/UnitOfWork/UnitOfWorkReducer.php +++ b/src/UnitOfWork/UnitOfWorkReducer.php @@ -17,11 +17,12 @@ public function reduceFromBeginning(UnitOfWork $unitOfWorkToReduce, Operation $o $index = 0; while (count($operations) > $index && $operations[$index]->canBeMergedWith($operationToReduceBy)) { - $index++; + ++$index; } + while (count($operations) > $index) { $operationsAfterReduction[] = $operations[$index]; - $index++; + ++$index; } return UnitOfWork::fromOperations($operationsAfterReduction); diff --git a/src/UnitOfWork/UnitOfWorkReducerTest.php b/src/UnitOfWork/UnitOfWorkReducerTest.php index 37b605d..7e59cb9 100644 --- a/src/UnitOfWork/UnitOfWorkReducerTest.php +++ b/src/UnitOfWork/UnitOfWorkReducerTest.php @@ -31,7 +31,7 @@ public function testShouldReduceOperationsFromBeginning( $expectedOperationsCount = count($expectedOperationsAfterReduction); Assert::assertCount($expectedOperationsCount, $actualOperationsAfterReduction); - for ($i = 0; $i < $expectedOperationsCount; $i++) { + for ($i = 0; $i < $expectedOperationsCount; ++$i) { Assert::assertSame($expectedOperationsAfterReduction[$i], $actualOperationsAfterReduction[$i]); } } diff --git a/src/UnitOfWork/UnitOfWorkTest.php b/src/UnitOfWork/UnitOfWorkTest.php index 92dac62..3a56ffd 100644 --- a/src/UnitOfWork/UnitOfWorkTest.php +++ b/src/UnitOfWork/UnitOfWorkTest.php @@ -14,6 +14,7 @@ public function testShouldUnionUnitOfWork(): void { $unitOfWorkA = new UnitOfWork(); $unitOfWorkA->registerOperation(new MergeableOperation(1)); + $unitOfWorkB = new UnitOfWork(); $unitOfWorkB->registerOperation(new MergeableOperation(2)); diff --git a/var/.gitkeep b/var/.gitkeep new file mode 100644 index 0000000..e69de29 From 82cdf65a8f76e82acaf1a94b5a5501107bb03d57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Bok?= Date: Thu, 1 Feb 2024 15:15:30 +0100 Subject: [PATCH 2/2] DE-55463 Update phpunit.xml configuration --- composer.json | 2 +- phpunit.xml | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 028cd21..ac2fb37 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ "brandembassy/coding-standard": "^11.1", "mockery/mockery": "^1.5.1", "nette/utils": "^2.4 || ^3.0", - "phpunit/phpunit": "^10.0", + "phpunit/phpunit": "^10.5", "roave/security-advisories": "dev-latest" }, "scripts": { diff --git a/phpunit.xml b/phpunit.xml index bf917ba..af493bd 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,6 +1,6 @@ src + + + + + src + + src +