Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DE-55463 Update Sonar Qube integration #19

Merged
merged 2 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 26 additions & 102 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
12 changes: 12 additions & 0 deletions .github/workflows/sonar-qube-master.yml
Original file line number Diff line number Diff line change
@@ -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 }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
vendor/
temp/
/var/*
!.gitkeep
composer.lock
.phpunit.cache
coverage.xml
Expand Down
12 changes: 7 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,26 @@
}
},
"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.5",
"roave/security-advisories": "dev-latest"
},
"scripts": {
"check-cs": "vendor/bin/ecs check --ansi",
"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,
Expand Down
2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ parameters:
paths:
- src

tmpDir: temp/phpstan
tmpDir: var/phpstan
30 changes: 17 additions & 13 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheResultFile=".phpunit.cache/test-results"
colors="true"
cacheDirectory="var/.phpunit.cache"
executionOrder="depends,defects"
forceCoversAnnotation="false"
beStrictAboutCoversAnnotation="true"
requireCoverageMetadata="false"
beStrictAboutCoverageMetadata="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
convertDeprecationsToExceptions="true"
failOnRisky="true"
failOnWarning="true"
verbose="true">
failOnWarning="true">
<testsuites>
<testsuite name="default">
<directory>src</directory>
</testsuite>
</testsuites>

<coverage cacheDirectory=".phpunit.cache/code-coverage"
processUncoveredFiles="true">
<coverage>
<report>
<html outputDirectory="./var/code-coverage" lowUpperBound="50" highLowerBound="80"/>
</report>
</coverage>
<source>
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
<exclude>
<directory suffix="Test.php">src</directory>
</exclude>
</source>
</phpunit>
31 changes: 31 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php declare(strict_types = 1);

use Rector\Caching\ValueObject\Storage\FileCacheStorage;
use Rector\CodeQuality\Rector\Concat\JoinStringConcatRector;
use Rector\CodingStyle\Rector\Stmt\NewlineAfterStatementRector;
use Rector\Config\RectorConfig;
use Rector\Php74\Rector\LNumber\AddLiteralSeparatorToNumberRector;
use Rector\PHPUnit\Set\PHPUnitSetList;

return static function (RectorConfig $rectorConfig): void {
$defaultRectorConfigurationSetup = require 'vendor/brandembassy/coding-standard/default-rector.php';
$defaultSkipList = $defaultRectorConfigurationSetup($rectorConfig);

$rectorConfig->phpstanConfig(__DIR__ . '/phpstan.neon');

$rectorConfig->cacheClass(FileCacheStorage::class);
$rectorConfig->cacheDirectory('./var/rector');

$rectorConfig->paths([
__DIR__ . '/src',
]);

$skipList = [];

$rectorConfig->skip(
array_merge(
$defaultSkipList,
$skipList
)
);
};
5 changes: 1 addition & 4 deletions src/UnitOfWork/DummyTestOperationProcessorAccessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
*/
class DummyTestOperationProcessorAccessor implements OperationProcessorAccessor
{
/**
* @var OperationProcessor
*/
private $operationProcessor;
private OperationProcessor $operationProcessor;


public function __construct(OperationProcessor $operationProcessor)
Expand Down
7 changes: 2 additions & 5 deletions src/UnitOfWork/NaiveUnitOfWorkExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,9 @@ class NaiveUnitOfWorkExecutor implements UnitOfWorkExecutor
/**
* @var OperationProcessorAccessor[]
*/
private $operationProcessorAccessors;
private array $operationProcessorAccessors;

/**
* @var LoggerInterface
*/
private $logger;
private LoggerInterface $logger;


/**
Expand Down
3 changes: 1 addition & 2 deletions src/UnitOfWork/OperationConsolidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use function array_pop;
use function array_reverse;
use function array_values;
use function count;

/**
* @final
Expand All @@ -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 */
Expand Down
10 changes: 2 additions & 8 deletions src/UnitOfWork/ReducingUnitOfWorkExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions src/UnitOfWork/UnitOfWorkReducer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/UnitOfWork/UnitOfWorkReducerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/UnitOfWork/UnitOfWorkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public function testShouldUnionUnitOfWork(): void
{
$unitOfWorkA = new UnitOfWork();
$unitOfWorkA->registerOperation(new MergeableOperation(1));

$unitOfWorkB = new UnitOfWork();
$unitOfWorkB->registerOperation(new MergeableOperation(2));

Expand Down
Empty file added var/.gitkeep
Empty file.