diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e4a3818..a0055f9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,7 +7,7 @@ on: name: "CI" env: - COMPOSER_ROOT_VERSION: "3.0-dev" + COMPOSER_ROOT_VERSION: "3.1-dev" permissions: contents: read diff --git a/ChangeLog.md b/ChangeLog.md index 8504fce..0d8823f 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -2,6 +2,12 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](https://keepachangelog.com/) principles. +## [3.1.0] - 2023-MM-DD + +### Added + +* `ComplexityCollection::mergeWith()` + ## [3.0.1] - 2023-08-31 ### Fixed @@ -36,6 +42,7 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](htt * Initial release +[3.1.0]: https://github.com/sebastianbergmann/complexity/compare/3.0.1...main [3.0.1]: https://github.com/sebastianbergmann/complexity/compare/3.0.0...3.0.1 [3.0.0]: https://github.com/sebastianbergmann/complexity/compare/2.0.2...3.0.0 [2.0.2]: https://github.com/sebastianbergmann/complexity/compare/2.0.1...2.0.2 diff --git a/composer.json b/composer.json index f3663cb..78f6ffb 100644 --- a/composer.json +++ b/composer.json @@ -37,7 +37,7 @@ }, "extra": { "branch-alias": { - "dev-main": "3.0-dev" + "dev-main": "3.1-dev" } } } diff --git a/src/Complexity/ComplexityCollection.php b/src/Complexity/ComplexityCollection.php index 6000973..b17616c 100644 --- a/src/Complexity/ComplexityCollection.php +++ b/src/Complexity/ComplexityCollection.php @@ -9,6 +9,7 @@ */ namespace SebastianBergmann\Complexity; +use function array_merge; use function count; use Countable; use IteratorAggregate; @@ -75,4 +76,14 @@ public function cyclomaticComplexity(): int return $cyclomaticComplexity; } + + public function mergeWith(self $other): self + { + return new self( + array_merge( + $this->asArray(), + $other->asArray(), + ), + ); + } } diff --git a/tests/unit/ComplexityCollectionTest.php b/tests/unit/ComplexityCollectionTest.php index 29c2cfd..e209006 100644 --- a/tests/unit/ComplexityCollectionTest.php +++ b/tests/unit/ComplexityCollectionTest.php @@ -73,4 +73,20 @@ public function testHasCyclomaticComplexity(): void $this->assertSame(3, $collection->cyclomaticComplexity()); } + + public function testCanBeMerged(): void + { + $a = ComplexityCollection::fromList($this->array[0]); + $b = ComplexityCollection::fromList($this->array[1]); + + $c = $a->mergeWith($b); + + $this->assertSame( + [ + $this->array[0], + $this->array[1], + ], + $c->asArray(), + ); + } }