Skip to content
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
13 changes: 7 additions & 6 deletions .github/workflows/coverage_report.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Run coverage report and upload it to CodeClimate
# Run coverage report and upload it to Qlty
name: Coverage
on:
push:
Expand All @@ -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
106 changes: 106 additions & 0 deletions .qlty/qlty.toml
Original file line number Diff line number Diff line change
@@ -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"
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
}
},
"require-dev": {
"psalm/phar": "^5",
"psalm/phar": "^6",
"susina/coding-standard": "^2",
"pestphp/pest": "^2.35",
"mikey179/vfsstream": "^1.6"
Expand Down
2 changes: 1 addition & 1 deletion src/Converter.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php declare(strict_types=1);
/*
* Copyright (c) Cristiano Cinotti 2024.
* Copyright (c) Cristiano Cinotti 2024 - 2025.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
4 changes: 2 additions & 2 deletions src/Exception/ConverterException.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php declare(strict_types=1);
/*
* Copyright (c) Cristiano Cinotti 2024.
* Copyright (c) Cristiano Cinotti 2024 - 2025.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,7 +15,7 @@

namespace Susina\XmlToArray\Exception;

class ConverterException extends \RuntimeException
final class ConverterException extends \RuntimeException
{
/**
* Create an exception based on LibXMLError objects
Expand Down
26 changes: 15 additions & 11 deletions src/FileConverter.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php declare(strict_types=1);
/*
* Copyright (c) Cristiano Cinotti 2024.
* Copyright (c) Cristiano Cinotti 2024 - 2025.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,7 +15,7 @@

namespace Susina\XmlToArray;

class FileConverter
final class FileConverter
{
private Converter $converter;

Expand Down Expand Up @@ -47,9 +47,7 @@ public function __construct(array $options = [])
*/
public function convert(string $xmlFile): array
{
$this->assertValidFile($xmlFile);

return $this->converter->convert(file_get_contents($xmlFile));
return $this->converter->convert($this->readXmlFile($xmlFile));
}

/**
Expand All @@ -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.");
Expand All @@ -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;
}
}
2 changes: 1 addition & 1 deletion tests/Datasets/Inclusion.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php declare(strict_types=1);
/*
* Copyright (c) Cristiano Cinotti 2024.
* Copyright (c) Cristiano Cinotti 2024 - 2025.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion tests/Datasets/Xml.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php declare(strict_types=1);
/*
* Copyright (c) Cristiano Cinotti 2024.
* Copyright (c) Cristiano Cinotti 2024 - 2025.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion tests/Datasets/XmlNoTypes.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php declare(strict_types=1);
/*
* Copyright (c) Cristiano Cinotti 2024.
* Copyright (c) Cristiano Cinotti 2024 - 2025.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion tests/Datasets/XmlWithAttributes.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php declare(strict_types=1);
/*
* Copyright (c) Cristiano Cinotti 2024.
* Copyright (c) Cristiano Cinotti 2024 - 2025.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion tests/Functional/ConversionTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php declare(strict_types=1);
/*
* Copyright (c) Cristiano Cinotti 2024.
* Copyright (c) Cristiano Cinotti 2024 - 2025.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/ConverterTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php declare(strict_types=1);
/*
* Copyright (c) Cristiano Cinotti 2024.
* Copyright (c) Cristiano Cinotti 2024 - 2025.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
3 changes: 2 additions & 1 deletion tests/Unit/FileConverterTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php declare(strict_types=1);
/*
* Copyright (c) Cristiano Cinotti 2024.
* Copyright (c) Cristiano Cinotti 2024 - 2025.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -13,6 +13,7 @@
* limitations under the License.
*/

use org\bovigo\vfs\content\LargeFileContent;
use org\bovigo\vfs\vfsStream;
use Susina\XmlToArray\FileConverter;

Expand Down