Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
6 / 6
CRAP
100.00% covered (success)
100.00%
1 / 1
FundingProfile
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
6 / 6
8
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getGithubSponsors
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getCustomUrls
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getUnsupportedYamlEntries
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getUnsupportedComposerEntries
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 hasYamlContent
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2
3declare(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
20namespace FastForward\DevTools\Funding;
21
22/**
23 * Carries normalized funding metadata across Composer and GitHub formats.
24 */
25  class FundingProfile
26{
27    /**
28     * Creates a new funding profile.
29     *
30     * @param array<int, string> $githubSponsors the normalized GitHub Sponsors handles
31     * @param array<int, string> $customUrls the normalized custom funding URLs
32     * @param array<string, mixed> $unsupportedYamlEntries the YAML entries preserved without synchronization
33     * @param array<int, array<string, mixed>> $unsupportedComposerEntries the Composer entries preserved without synchronization
34     */
35    public function __construct(
36        private array $githubSponsors = [],
37        private array $customUrls = [],
38        private array $unsupportedYamlEntries = [],
39        private array $unsupportedComposerEntries = [],
40    ) {}
41
42    /**
43     * Returns the normalized GitHub Sponsors handles.
44     *
45     * @return array<int, string> the GitHub Sponsors handles
46     */
47    public function getGithubSponsors(): array
48    {
49        return $this->githubSponsors;
50    }
51
52    /**
53     * Returns the normalized custom funding URLs.
54     *
55     * @return array<int, string> the custom funding URLs
56     */
57    public function getCustomUrls(): array
58    {
59        return $this->customUrls;
60    }
61
62    /**
63     * Returns the unsupported YAML entries that MUST be preserved.
64     *
65     * @return array<string, mixed> the YAML entries kept without transformation
66     */
67    public function getUnsupportedYamlEntries(): array
68    {
69        return $this->unsupportedYamlEntries;
70    }
71
72    /**
73     * Returns the unsupported Composer funding entries that MUST be preserved.
74     *
75     * @return array<int, array<string, mixed>> the Composer funding entries kept without transformation
76     */
77    public function getUnsupportedComposerEntries(): array
78    {
79        return $this->unsupportedComposerEntries;
80    }
81
82    /**
83     * Reports whether the profile contains any YAML-serializable content.
84     *
85     * @return bool true when the YAML file SHOULD exist
86     */
87    public function hasYamlContent(): bool
88    {
89        return [] !== $this->githubSponsors
90            || [] !== $this->customUrls
91            || [] !== $this->unsupportedYamlEntries;
92    }
93}