diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 6042223..7164337 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -8,7 +8,7 @@ jobs:
fail-fast: false
matrix:
operating-system: [ubuntu-latest, windows-latest, macOS-latest]
- php-versions: ['8.2', '8.3']
+ php-versions: ['8.2', '8.3', '8.4']
runs-on: ${{ matrix.operating-system }}
steps:
- name: Set autocrlf on windows
@@ -26,8 +26,8 @@ jobs:
with:
composer-options: "--prefer-dist --optimize-autoloader"
- name: Coding standard
+ env:
+ PHP_CS_FIXER_IGNORE_ENV: true
run: composer cs:check
- - name: Psalm issues
- run: composer analytics
- name: Test suite
run: composer test
diff --git a/README.md b/README.md
index 2bdd9f8..8ef113b 100644
--- a/README.md
+++ b/README.md
@@ -195,7 +195,6 @@ You can configure the converters by passing an associative array to the construc
The available options are the following:
- [mergeAttributes](#mergeattributes): boolean, default true
-- [idAsKey](#idaskey): boolean, default true
- [typesAsString](#typesasstring): boolean, default false
- [preserveFirstTag](#preservefirsttag): boolean, default false
@@ -271,97 +270,6 @@ $array = Converter::create(['mergeAttributes' => false])->convert($xmlString);
*/
```
-### idAsKey
-
-> Default: __true__
-
-When this option is set to true, the value of an _id_ attribute or tag is considered as the key of an associative array, i.e.:
-
-```php
-
-
-
- Star Wars
- True
-
-
-
- actorC
- Carrie Fisher
-
-
-";
-
-//idAsKey is true by default
-$array = Converter::create()->convert($xmlString);
-
-/*
- * $array now contains the following array:
- *
- * 'movie' => [
- * 0 => [
- * 'title' => 'Star Wars',
- * 'starred' => true,
- * 'actorH' => ['name' => 'Harrison Ford'],
- * 'actorM' => ['name' => 'Mark Hamill'],
- * 'actorC' => ['name' => 'Carrie Fisher']
- * ]
- * ]
- */
-```
-
-Otherwise, if you set this option to _false_ no magic happens:
-
-```php
-
-
-
- Star Wars
- True
-
-
-
- actorC
- Carrie Fisher
-
-
-";
-
-$converter = new Converter(['idAsKey' => false]);
-$array = $converter->convert($xmlString);
-
-/*
- * $array now contains the following array:
- *
- * 'movie' => [
- * 0 => [
- * 'title' => 'Star Wars',
- * 'starred' => true,
- * 'actor' => [
- * 0 => [
- * 'id' => 'actorH',
- * 'name' => 'Harrison Ford'
- * ],
- * 1 => [
- * 'id' => 'actorM',
- * 'name' => 'Mark Hamill'
- * ],
- * 2 => [
- * 'id' => 'actorC',
- * 'name' => 'Carrie Fisher'
- * ]
- * ]
- * ]
- * ]
- */
-```
-
### typesAsString
> Default: __false__
diff --git a/src/Converter.php b/src/Converter.php
index 4e32659..8a89084 100644
--- a/src/Converter.php
+++ b/src/Converter.php
@@ -62,7 +62,6 @@ public function convert(string $xmlToParse): array
$array = $this->options['mergeAttributes'] === true ? $this->mergeAttributes($array) : $array;
$array = $this->options['typesAsString'] === false ? $this->convertBool($array) : $array;
$array = $this->options['typesAsString'] === false ? $this->convertEmptyArrayToNull($array) : $this->convertEmptyArrayToNull($array, true);
- $array = $this->options['idAsKey'] === true ? $this->idToKey($array) : $array;
return $array;
}
@@ -102,13 +101,11 @@ private function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'mergeAttributes' => true,
- 'idAsKey' => true,
'typesAsString' => false,
'preserveFirstTag' => false
]);
$resolver->setAllowedTypes('mergeAttributes', 'bool');
- $resolver->setAllowedTypes('idAsKey', 'bool');
$resolver->setAllowedTypes('typesAsString', 'bool');
$resolver->setAllowedTypes('preserveFirstTag', 'bool');
}
@@ -189,52 +186,6 @@ private function convertEmptyArrayToNull(array $array, bool $toString = false):
}, $array);
}
- /**
- * @psalm-suppress MixedAssignment
- * @psalm-suppress MixedArrayAssignment
- * @psalm-suppress MixedArrayOffset
- */
- private function idToKey(array $array): array
- {
- $out = [];
-
- foreach ($array as $key => $value) {
- if (!is_array($value)) {
- $out[$key] = $value;
- continue;
- }
-
- if (!$this->hasIdToMerge($value)) {
- $out[$key] = $this->idToKey($value);
- continue;
- }
-
- /** @var mixed $v */
- foreach ($value as $k => $v) {
- if (!is_array($v)) {
- $out[$key][$k] = $v;
- continue;
- }
-
- $out[$v['id']] = array_diff_key($v, ['id' => true]);
- }
- }
-
- return $out;
- }
-
- private function hasIdToMerge(array $array): bool
- {
- /** @var mixed $value */
- foreach ($array as $value) {
- if (is_array($value) && array_key_exists('id', $value)) {
- return true;
- }
- }
-
- return false;
- }
-
private function normalizeXml(string $xml): string
{
$xml = preg_replace_callback_array([
diff --git a/tests/Datasets/NoIdConversion.php b/tests/Datasets/NoIdConversion.php
deleted file mode 100644
index 7655033..0000000
--- a/tests/Datasets/NoIdConversion.php
+++ /dev/null
@@ -1,59 +0,0 @@
-
-
-
- Star Wars
- True
-
-
-
-
-
- The Lord Of The Rings
- false
-
-",
- [
- 'movie' => [
- 0 => [
- 'title' => 'Star Wars',
- 'starred' => true,
- 'actor' => [
- 0 => [
- 'id' => 'actorH',
- 'name' => 'Harrison Ford'
- ],
- 1 => [
- 'id' => 'actorM',
- 'name' => 'Mark Hamill'
- ],
- 2 => [
- 'id' => 'actorC',
- 'name' => 'Carrie Fisher'
- ]
- ]
- ],
- 1 => [
- 'title' => 'The Lord Of The Rings',
- 'starred' => false
- ]
- ]
- ]
- ]
-]);
diff --git a/tests/Datasets/TestId.php b/tests/Datasets/TestId.php
deleted file mode 100644
index 376c636..0000000
--- a/tests/Datasets/TestId.php
+++ /dev/null
@@ -1,133 +0,0 @@
-
-
-
- Star Wars
- True
-
-
-
-
-
- The Lord Of The Rings
- false
-
-",
- [
- 'movie' => [
- 0 => [
- 'title' => 'Star Wars',
- 'starred' => true,
- 'actorH' => ['name' => 'Harrison Ford'],
- 'actorM' => ['name' => 'Mark Hamill'],
- 'actorC' => ['name' => 'Carrie Fisher']
- ],
- 1 => [
- 'title' => 'The Lord Of The Rings',
- 'starred' => false
- ]
- ]
- ]
- ],
- [
- "
-
-
-
- Star Wars
-
-
-
-
-
- The empire strikes back
-
-
-
-
-
-",
- [
- 'director' => [
- 'name' => 'George Lucas',
- 'movie' => [
- 0 => [
- 'title' => 'Star Wars',
- 'actorH' => ['name' => 'Harrison Ford'],
- 'actorM' => ['name' => 'Mark Hamill'],
- 'actorC' => ['name' => 'Carrie Fisher']
- ],
- 1 => [
- 'title' => 'The empire strikes back',
- 'actorH' => ['name' => 'Harrison Ford'],
- 'actorM' => ['name' => 'Mark Hamill'],
- 'actorC' => ['name' => 'Carrie Fisher']
- ]
- ]
- ]
- ]
- ],
- [
- "
- Star Wars
-
-
-
- ",
- [
- 'title' => 'Star Wars',
- 'actorH' => ['name' => 'Harrison Ford'],
- 'actorM' => ['name' => 'Mark Hamill'],
- 'actorC' => ['name' => 'Carrie Fisher']
- ]
- ],
- [
- "
-
-
- Star Wars
- True
-
-
-
- Michelle Pfeiffer
-
-
- The Lord Of The Rings
- false
-
-",
- [
- 'movie' => [
- 0 => [
- 'title' => 'Star Wars',
- 'starred' => true,
- 'actorH' => ['name' => 'Harrison Ford'],
- 'actorM' => ['name' => 'Mark Hamill'],
- 'actorC' => ['name' => 'Carrie Fisher'],
- "actor" => [3 => 'Michelle Pfeiffer']
- ],
- 1 => [
- 'title' => 'The Lord Of The Rings',
- 'starred' => false
- ]
- ]
- ]
- ]
-]);
diff --git a/tests/Unit/ConverterTest.php b/tests/Unit/ConverterTest.php
index 57dd043..9291573 100644
--- a/tests/Unit/ConverterTest.php
+++ b/tests/Unit/ConverterTest.php
@@ -82,11 +82,6 @@
- Fatal 76: Opening and ending tag mismatch: movies line 2 and moviess
");
-it('converts Id attribute into an associative array key', function (string $xml, array $expected) {
- $actual = Converter::create()->convert($xml);
- expect($actual)->toBe($expected);
-})->with('TestId');
-
it('converts an XML string without merging @attributes key', function (string $xml, array $expected) {
$actual = Converter::create(['mergeAttributes' => false])->convert($xml);
expect($actual)->toBe($expected);
@@ -97,11 +92,6 @@
expect($actual)->toBe($expected);
})->with('XmlNoTypes');
-it('leave Id attribute as normal attribute', function (string $xml, array $expected) {
- $actual = Converter::create(['idAsKey' => false])->convert($xml);
- expect($actual)->toBe($expected);
-})->with('NoIdConversion');
-
it('converts an XML string preserving the first tag', function () {
$expected = [
'breakfast_menu' => [