From 6ac70cf735b4df808a76c8be981752d492b16658 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Kr=C3=A4mer?= Date: Fri, 18 Jul 2025 11:02:28 +0200 Subject: [PATCH 1/8] Refining the Box Config and App Versioning --- .gitignore | 2 +- box.json.dist | 6 +++++- src/Application.php | 4 ++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 89e29e1..08f09d0 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,4 @@ .env infection.log phive.phar -cognitive-analysis.phar +phpcca.phar diff --git a/box.json.dist b/box.json.dist index a1ca119..e7d40e9 100644 --- a/box.json.dist +++ b/box.json.dist @@ -1,8 +1,12 @@ { - "main": "./bin/phpcca", "compression": "GZ", "output": "phpcca.phar", "force-autodiscovery": true, + "compactors": [ + "KevinGH\\Box\\Compactor\\Json", + "KevinGH\\Box\\Compactor\\Php", + "KevinGH\\Box\\Compactor\\PhpScoper" + ], "files": [ "config.yml", "composer.json", diff --git a/src/Application.php b/src/Application.php index 065e409..1b8d064 100644 --- a/src/Application.php +++ b/src/Application.php @@ -231,6 +231,10 @@ private function registerCommands(): void private function configureApplication(): void { $this->containerBuilder->register(SymfonyApplication::class, SymfonyApplication::class) + ->setArguments([ + 'Cognitive Code Analysis', + '1.3.1' + ]) ->setPublic(true) ->addMethodCall('add', [new Reference(CognitiveMetricsCommand::class)]) ->addMethodCall('add', [new Reference(ChurnCommand::class)]); From 896c869682818b0a2d1a5e77636537b234ee4710 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Kr=C3=A4mer?= Date: Fri, 18 Jul 2025 11:05:09 +0200 Subject: [PATCH 2/8] Updating CI Action --- .github/workflows/ci.yaml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 31465a5..6e22e0a 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,6 +1,12 @@ name: CI -on: [push, pull_request] +on: + push: + branches: + - main + pull_request: + branches: + - '*' jobs: testsuite: From 1e94ff0839aed196b8529560eb794473bc656df4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Kr=C3=A4mer?= Date: Fri, 18 Jul 2025 17:00:08 +0200 Subject: [PATCH 3/8] Refining the version handling --- .github/workflows/phar-build.yaml | 5 ++++- src/Application.php | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/phar-build.yaml b/.github/workflows/phar-build.yaml index 972bcf6..5059428 100644 --- a/.github/workflows/phar-build.yaml +++ b/.github/workflows/phar-build.yaml @@ -17,13 +17,16 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: '8.2' + php-version: '8.4' extensions: json, fileinfo tools: composer - name: Install dependencies run: composer install --no-dev --optimize-autoloader + - name: Inject version from tag + run: sed -i "s/public const VERSION = .*/public const VERSION = '\${{ github.ref_name }}';/" src/Application.php + - name: Build PHAR run: composer build-phar diff --git a/src/Application.php b/src/Application.php index 1b8d064..9f0b448 100644 --- a/src/Application.php +++ b/src/Application.php @@ -49,6 +49,8 @@ */ class Application { + public const VERSION = '1.3.0'; + private ContainerBuilder $containerBuilder; public function __construct() @@ -233,7 +235,7 @@ private function configureApplication(): void $this->containerBuilder->register(SymfonyApplication::class, SymfonyApplication::class) ->setArguments([ 'Cognitive Code Analysis', - '1.3.1' + self::VERSION ]) ->setPublic(true) ->addMethodCall('add', [new Reference(CognitiveMetricsCommand::class)]) From 7083327a70dd95a3ec22196e943a5e7c95658b73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Kr=C3=A4mer?= Date: Fri, 18 Jul 2025 17:00:58 +0200 Subject: [PATCH 4/8] Revert "Refining the version handling" This reverts commit 1e94ff0839aed196b8529560eb794473bc656df4. --- .github/workflows/phar-build.yaml | 5 +---- src/Application.php | 4 +--- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/.github/workflows/phar-build.yaml b/.github/workflows/phar-build.yaml index 5059428..972bcf6 100644 --- a/.github/workflows/phar-build.yaml +++ b/.github/workflows/phar-build.yaml @@ -17,16 +17,13 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: '8.4' + php-version: '8.2' extensions: json, fileinfo tools: composer - name: Install dependencies run: composer install --no-dev --optimize-autoloader - - name: Inject version from tag - run: sed -i "s/public const VERSION = .*/public const VERSION = '\${{ github.ref_name }}';/" src/Application.php - - name: Build PHAR run: composer build-phar diff --git a/src/Application.php b/src/Application.php index 9f0b448..1b8d064 100644 --- a/src/Application.php +++ b/src/Application.php @@ -49,8 +49,6 @@ */ class Application { - public const VERSION = '1.3.0'; - private ContainerBuilder $containerBuilder; public function __construct() @@ -235,7 +233,7 @@ private function configureApplication(): void $this->containerBuilder->register(SymfonyApplication::class, SymfonyApplication::class) ->setArguments([ 'Cognitive Code Analysis', - self::VERSION + '1.3.1' ]) ->setPublic(true) ->addMethodCall('add', [new Reference(CognitiveMetricsCommand::class)]) From 6467c6de6178538b2dd2612fca989bab06c3890f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Kr=C3=A4mer?= Date: Fri, 18 Jul 2025 17:04:05 +0200 Subject: [PATCH 5/8] Refining the version handling --- .github/workflows/phar-build.yaml | 5 ++++- src/Application.php | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/phar-build.yaml b/.github/workflows/phar-build.yaml index 972bcf6..5059428 100644 --- a/.github/workflows/phar-build.yaml +++ b/.github/workflows/phar-build.yaml @@ -17,13 +17,16 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: '8.2' + php-version: '8.4' extensions: json, fileinfo tools: composer - name: Install dependencies run: composer install --no-dev --optimize-autoloader + - name: Inject version from tag + run: sed -i "s/public const VERSION = .*/public const VERSION = '\${{ github.ref_name }}';/" src/Application.php + - name: Build PHAR run: composer build-phar diff --git a/src/Application.php b/src/Application.php index 1b8d064..9f0b448 100644 --- a/src/Application.php +++ b/src/Application.php @@ -49,6 +49,8 @@ */ class Application { + public const VERSION = '1.3.0'; + private ContainerBuilder $containerBuilder; public function __construct() @@ -233,7 +235,7 @@ private function configureApplication(): void $this->containerBuilder->register(SymfonyApplication::class, SymfonyApplication::class) ->setArguments([ 'Cognitive Code Analysis', - '1.3.1' + self::VERSION ]) ->setPublic(true) ->addMethodCall('add', [new Reference(CognitiveMetricsCommand::class)]) From 7f5b62a54746823655a35ff67f503758778421c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Kr=C3=A4mer?= Date: Fri, 18 Jul 2025 17:08:34 +0200 Subject: [PATCH 6/8] Adding tag script --- scripts/tag.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100755 scripts/tag.sh diff --git a/scripts/tag.sh b/scripts/tag.sh new file mode 100755 index 0000000..b50f70a --- /dev/null +++ b/scripts/tag.sh @@ -0,0 +1,10 @@ +# Get the latest tag reachable from the previous commit +TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null) + +if [ -n "$TAG" ]; then + sed -i "s/public const VERSION = .*/public const VERSION = '$TAG';/" src/Application.php + git add src/Application.php + echo "Version set to $TAG" +else + echo "No previous tag found." +fi From 584c94dfc5b905b5a7dd2a973c2b4f70567ee014 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Kr=C3=A4mer?= Date: Tue, 22 Jul 2025 00:48:18 +0200 Subject: [PATCH 7/8] Reverting a change to the Box Config --- box.json.dist | 1 + 1 file changed, 1 insertion(+) diff --git a/box.json.dist b/box.json.dist index e7d40e9..bfd0e5b 100644 --- a/box.json.dist +++ b/box.json.dist @@ -1,4 +1,5 @@ { + "main": "bin/phpcca", "compression": "GZ", "output": "phpcca.phar", "force-autodiscovery": true, From c2298ac7898a50061593b47f39444ebab64027a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Kr=C3=A4mer?= Date: Tue, 22 Jul 2025 00:50:02 +0200 Subject: [PATCH 8/8] Minor refactoring / clean code --- src/Command/EventHandler/VerboseHandler.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/Command/EventHandler/VerboseHandler.php b/src/Command/EventHandler/VerboseHandler.php index 8d6a073..c408207 100644 --- a/src/Command/EventHandler/VerboseHandler.php +++ b/src/Command/EventHandler/VerboseHandler.php @@ -25,10 +25,7 @@ public function __construct( public function __invoke(SourceFilesFound|FileProcessed $event): void { - if ( - $this->input->hasOption(CognitiveMetricsCommand::OPTION_DEBUG) - && $this->input->getOption(CognitiveMetricsCommand::OPTION_DEBUG) === false - ) { + if (!$this->isDebugEnabled()) { return; } @@ -62,4 +59,13 @@ private function formatBytes(int $size): string return round($size, 2) . ' ' . $units[$index]; } + + /** + * @return bool + */ + public function isDebugEnabled(): bool + { + return $this->input->hasOption(CognitiveMetricsCommand::OPTION_DEBUG) + && $this->input->getOption(CognitiveMetricsCommand::OPTION_DEBUG) === false; + } }