Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support/funding sections #67

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
ComposerJsonSection::HOMEPAGE,
ComposerJsonSection::LICENSE,
ComposerJsonSection::AUTHORS,
ComposerJsonSection::SUPPORT,
ComposerJsonSection::FUNDING,
ComposerJsonSection::BIN,
ComposerJsonSection::REQUIRE,
ComposerJsonSection::REQUIRE_DEV,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@
"require": {
"php": ">=7.3"
},
"support": {
"email": "support@example.org",
"irc": "irc://irc.freenode.org/example"
},
"funding": [
{
"type": "example",
"url": "https://www.patreon.com/example"
}
],
"require-dev": {
"phpunit/phpunit": "^8.5|^9.4"
},
Expand Down
8 changes: 8 additions & 0 deletions packages/ComposerJsonManipulator/ComposerJsonFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,14 @@ public function createFromArray(array $jsonArray): ComposerJson
$composerJson->setProvide($jsonArray[ComposerJsonSection::PROVIDE]);
}

if (isset($jsonArray[ComposerJsonSection::FUNDING])) {
$composerJson->setFunding($jsonArray[ComposerJsonSection::FUNDING]);
}

if (isset($jsonArray[ComposerJsonSection::SUPPORT])) {
$composerJson->setSupport($jsonArray[ComposerJsonSection::SUPPORT]);
}

$orderedKeys = array_keys($jsonArray);
$composerJson->setOrderedKeys($orderedKeys);

Expand Down
44 changes: 44 additions & 0 deletions packages/ComposerJsonManipulator/ValueObject/ComposerJson.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ final class ComposerJson
*/
private array $extra = [];

/**
* @var mixed[]
*/
private array $funding = [];

/**
* @var mixed[]
*/
private array $support = [];

/**
* @var array<string, string>
*/
Expand Down Expand Up @@ -336,6 +346,38 @@ public function setExtra(array $extra): void
$this->extra = $extra;
}

/**
* @return mixed[]
*/
public function getFunding(): array
{
return $this->funding;
}

/**
* @param mixed[] $funding
*/
public function setFunding(array $funding): void
{
$this->funding = $funding;
}

/**
* @return mixed[]
*/
public function getSupport(): array
{
return $this->support;
}

/**
* @param mixed[] $support
*/
public function setSupport(array $support): void
{
$this->support = $support;
}

public function getName(): ?string
{
return $this->name;
Expand Down Expand Up @@ -416,6 +458,8 @@ public function getJsonArray(): array
ComposerJsonSection::CONFLICT => $this->conflicts,
ComposerJsonSection::PROVIDE => $this->provide,
ComposerJsonSection::VERSION => $this->version,
ComposerJsonSection::FUNDING => $this->funding,
ComposerJsonSection::SUPPORT => $this->support,
]);

if ($this->minimumStability !== null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,14 @@ final class ComposerJsonSection
* @var string
*/
public const VERSION = 'version';

/**
* @var string
*/
public const FUNDING = 'funding';

/**
* @var string
*/
public const SUPPORT = 'support';
}
2 changes: 1 addition & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd" cacheDirectory=".phpunit.cache">
<testsuite name="all">
<directory>tests</directory>
<directory>packages/*/tests</directory>
<directory>packages-tests</directory>
</testsuite>
</phpunit>
Loading