From 69c31e4d8a336adf7996dde4034813003dcd49c0 Mon Sep 17 00:00:00 2001 From: Cristiano Cinotti Date: Mon, 21 Apr 2025 16:18:39 +0200 Subject: [PATCH 1/3] Fix Psalm issues --- composer.json | 2 +- src/Converter.php | 2 +- src/Exception/ConverterException.php | 4 ++-- src/FileConverter.php | 26 +++++++++++++++----------- tests/Datasets/Inclusion.php | 2 +- tests/Datasets/Xml.php | 2 +- tests/Datasets/XmlNoTypes.php | 2 +- tests/Datasets/XmlWithAttributes.php | 2 +- tests/Functional/ConversionTest.php | 2 +- tests/Unit/ConverterTest.php | 2 +- tests/Unit/FileConverterTest.php | 3 ++- 11 files changed, 27 insertions(+), 22 deletions(-) diff --git a/composer.json b/composer.json index cacc699..5fc8648 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,7 @@ } }, "require-dev": { - "psalm/phar": "^5", + "psalm/phar": "^6", "susina/coding-standard": "^2", "pestphp/pest": "^2.35", "mikey179/vfsstream": "^1.6" diff --git a/src/Converter.php b/src/Converter.php index 8a89084..7dc553a 100644 --- a/src/Converter.php +++ b/src/Converter.php @@ -1,6 +1,6 @@ assertValidFile($xmlFile); - - return $this->converter->convert(file_get_contents($xmlFile)); + return $this->converter->convert($this->readXmlFile($xmlFile)); } /** @@ -62,17 +60,15 @@ public function convert(string $xmlFile): array */ public function convertAndSave(string $xmlFile, string $saveFile): void { - $this->assertValidFile($xmlFile); - - $this->converter->convertAndSave(file_get_contents($xmlFile), $saveFile); + $this->converter->convertAndSave($this->readXmlFile($xmlFile), $saveFile); } /** - * Check if a file exists and is readable + * Read the content of a given xml file. * - * @throws \RuntimeException If the file is not writeable or the directory doesn't exist. + * @throws \RuntimeException If the file is not writeable, the directory doesn't exist or any other problem in reading the file. */ - private function assertValidFile(string $filename): void + private function readXmlFile(string $filename): string { if (!file_exists($filename)) { throw new \RuntimeException("The file `$filename` does not exist."); @@ -81,5 +77,13 @@ private function assertValidFile(string $filename): void if (!is_readable($filename)) { throw new \RuntimeException("The file `$filename` is not readable: do you have the correct permissions?"); } + + $content = file_get_contents($filename); + + if ($content === false) { + throw new \RuntimeException("Impossible to read `$filename` file."); + } + + return $content; } } diff --git a/tests/Datasets/Inclusion.php b/tests/Datasets/Inclusion.php index f5240bf..cac8e00 100644 --- a/tests/Datasets/Inclusion.php +++ b/tests/Datasets/Inclusion.php @@ -1,6 +1,6 @@ Date: Mon, 21 Apr 2025 16:24:32 +0200 Subject: [PATCH 2/3] Move from Codeclimate to Qlty --- .github/workflows/coverage_report.yml | 13 +++++++------ README.md | 4 ++-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/.github/workflows/coverage_report.yml b/.github/workflows/coverage_report.yml index 837397d..d4c3956 100644 --- a/.github/workflows/coverage_report.yml +++ b/.github/workflows/coverage_report.yml @@ -1,4 +1,4 @@ -# Run coverage report and upload it to CodeClimate +# Run coverage report and upload it to Qlty name: Coverage on: push: @@ -19,9 +19,10 @@ jobs: uses: ramsey/composer-install@v3 with: composer-options: "--prefer-dist --optimize-autoloader" - - name: Test & publish code coverage - uses: paambaati/codeclimate-action@v8.0.0 - env: - CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }} + - name: Build the code coverage report + run: composer coverage:clover + - name: Upload code coverage report + uses: qltysh/qlty-action/coverage@v1 with: - coverageCommand: "composer coverage:clover" + token: ${{ secrets.QLTY_COVERAGE_TOKEN }} + files: clover.xml \ No newline at end of file diff --git a/README.md b/README.md index 8ef113b..b06111d 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # Xml to Array Converter ![Test Suite](https://github.com/susina/xml-to-array/actions/workflows/test.yml/badge.svg) -[![Maintainability](https://api.codeclimate.com/v1/badges/df696c7f95bd65d7510c/maintainability)](https://codeclimate.com/github/susina/xml-to-array/maintainability) -[![Test Coverage](https://api.codeclimate.com/v1/badges/df696c7f95bd65d7510c/test_coverage)](https://codeclimate.com/github/susina/xml-to-array/test_coverage) +[![Maintainability](https://qlty.sh/badges/934769fe-a55a-425c-a87c-ed1ad27fe3f6/maintainability.svg)](https://qlty.sh/gh/susina/projects/xml-to-array) +[![Code Coverage](https://qlty.sh/badges/934769fe-a55a-425c-a87c-ed1ad27fe3f6/test_coverage.svg)](https://qlty.sh/gh/susina/projects/xml-to-array) ![GitHub License](https://img.shields.io/github/license/susina/xml-to-array) Xml to Array is a simple library to convert XML into PHP array. From 55d381571784cd36046e7783b993e5647f237f52 Mon Sep 17 00:00:00 2001 From: Cristiano Cinotti Date: Mon, 21 Apr 2025 16:37:23 +0200 Subject: [PATCH 3/3] Configure Qlty --- .qlty/qlty.toml | 106 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 .qlty/qlty.toml diff --git a/.qlty/qlty.toml b/.qlty/qlty.toml new file mode 100644 index 0000000..309c914 --- /dev/null +++ b/.qlty/qlty.toml @@ -0,0 +1,106 @@ +# This file was automatically generated by `qlty init`. +# You can modify it to suit your needs. +# We recommend you to commit this file to your repository. +# +# This configuration is used by both Qlty CLI and Qlty Cloud. +# +# Qlty CLI -- Code quality toolkit for developers +# Qlty Cloud -- Fully automated Code Health Platform +# +# Try Qlty Cloud: https://qlty.sh +# +# For a guide to configuration, visit https://qlty.sh/d/config +# Or for a full reference, visit https://qlty.sh/d/qlty-toml +config_version = "0" + +exclude_patterns = [ + "*_min.*", + "*-min.*", + "*.min.*", + "**/*.d.ts", + "**/.yarn/**", + "**/bower_components/**", + "**/build/**", + "**/cache/**", + "**/config/**", + "**/db/**", + "**/deps/**", + "**/dist/**", + "**/extern/**", + "**/external/**", + "**/generated/**", + "**/Godeps/**", + "**/gradlew/**", + "**/mvnw/**", + "**/node_modules/**", + "**/protos/**", + "**/seed/**", + "**/target/**", + "**/testdata/**", + "**/vendor/**", + "**/assets/**", +] + +test_patterns = [ + "**/test/**", + "**/spec/**", + "**/*.test.*", + "**/*.spec.*", + "**/*_test.*", + "**/*_spec.*", + "**/test_*.*", + "**/spec_*.*", + "**/tests/**" +] + +[smells] +mode = "comment" + +[[source]] +name = "default" +default = true + +[[plugin]] +name = "actionlint" + +[[plugin]] +name = "dotenv-linter" +mode = "comment" + +[[plugin]] +name = "golangci-lint" +mode = "comment" + +[[plugin]] +name = "markdownlint" +mode = "comment" + +[[plugin]] +name = "php-codesniffer" +mode = "comment" + +[[plugin]] +name = "php-cs-fixer" + +[[plugin]] +name = "prettier" + +[[plugin]] +name = "radarlint-php" + +[[plugin]] +name = "ripgrep" +mode = "comment" + +[[plugin]] +name = "trivy" +drivers = [ + "config", + "fs-vuln", +] + +[[plugin]] +name = "trufflehog" + +[[plugin]] +name = "yamllint"