Skip to content

Commit

Permalink
Implement ComplexityCollection::mergeWith()
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Aug 31, 2023
1 parent c70b738 commit bb8ea85
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
name: "CI"

env:
COMPOSER_ROOT_VERSION: "3.0-dev"
COMPOSER_ROOT_VERSION: "3.1-dev"

permissions:
contents: read
Expand Down
7 changes: 7 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
},
"extra": {
"branch-alias": {
"dev-main": "3.0-dev"
"dev-main": "3.1-dev"
}
}
}
11 changes: 11 additions & 0 deletions src/Complexity/ComplexityCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/
namespace SebastianBergmann\Complexity;

use function array_merge;
use function count;
use Countable;
use IteratorAggregate;
Expand Down Expand Up @@ -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(),
),
);
}
}
16 changes: 16 additions & 0 deletions tests/unit/ComplexityCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
);
}
}

0 comments on commit bb8ea85

Please sign in to comment.