Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
9 / 9 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| FundingProfileMerger | |
100.00% |
9 / 9 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
| merge | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
| sortedUnique | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | /** |
| 6 | * Fast Forward Development Tools for PHP projects. |
| 7 | * |
| 8 | * This file is part of fast-forward/dev-tools project. |
| 9 | * |
| 10 | * @author Felipe Sayão Lobato Abreu <github@mentordosnerds.com> |
| 11 | * @license https://opensource.org/licenses/MIT MIT License |
| 12 | * |
| 13 | * @see https://github.com/php-fast-forward/ |
| 14 | * @see https://github.com/php-fast-forward/dev-tools |
| 15 | * @see https://github.com/php-fast-forward/dev-tools/issues |
| 16 | * @see https://php-fast-forward.github.io/dev-tools/ |
| 17 | * @see https://datatracker.ietf.org/doc/html/rfc2119 |
| 18 | */ |
| 19 | |
| 20 | namespace FastForward\DevTools\Funding; |
| 21 | |
| 22 | use function array_unique; |
| 23 | use function sort; |
| 24 | |
| 25 | /** |
| 26 | * Merges normalized funding profiles into a deterministic synchronized view. |
| 27 | */ |
| 28 | class FundingProfileMerger |
| 29 | { |
| 30 | /** |
| 31 | * Merges funding metadata from Composer and GitHub sources. |
| 32 | * |
| 33 | * @param FundingProfile $composerProfile the funding metadata sourced from composer.json |
| 34 | * @param FundingProfile $yamlProfile the funding metadata sourced from .github/FUNDING.yml |
| 35 | * |
| 36 | * @return FundingProfile the merged synchronized funding metadata |
| 37 | */ |
| 38 | public function merge(FundingProfile $composerProfile, FundingProfile $yamlProfile): FundingProfile |
| 39 | { |
| 40 | return new FundingProfile( |
| 41 | $this->sortedUnique([...$composerProfile->getGithubSponsors(), ...$yamlProfile->getGithubSponsors()]), |
| 42 | $this->sortedUnique([...$composerProfile->getCustomUrls(), ...$yamlProfile->getCustomUrls()]), |
| 43 | $yamlProfile->getUnsupportedYamlEntries(), |
| 44 | $composerProfile->getUnsupportedComposerEntries(), |
| 45 | ); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Returns a sorted unique list of scalar values. |
| 50 | * |
| 51 | * @param array<int, string> $values the values to normalize |
| 52 | * |
| 53 | * @return array<int, string> the sorted unique values |
| 54 | */ |
| 55 | private function sortedUnique(array $values): array |
| 56 | { |
| 57 | $values = array_values(array_unique($values)); |
| 58 | sort($values); |
| 59 | |
| 60 | return $values; |
| 61 | } |
| 62 | } |