Skip to content

Commit

Permalink
Sort Composer repository objects per schema
Browse files Browse the repository at this point in the history
  • Loading branch information
fredden authored and localheinz committed May 2, 2023
1 parent 00976bb commit 2839e97
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 19 deletions.
4 changes: 0 additions & 4 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
<code>$itemSchema</code>
<code>$oneOfSchema</code>
<code>$value</code>
<code>$value</code>
</MixedArgument>
<MixedArgumentTypeCoercion>
<code><![CDATA[$json->decoded()]]></code>
Expand All @@ -31,9 +30,6 @@
<code>$value</code>
<code>$value</code>
</MixedAssignment>
<RedundantCast>
<code>(string) $name</code>
</RedundantCast>
</file>
<file src="src/Vendor/Composer/PackageHashNormalizer.php">
<MixedAssignment>
Expand Down
15 changes: 6 additions & 9 deletions src/SchemaNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,7 @@ private function normalizeObject(
* @see https://json-schema.org/understanding-json-schema/reference/object.html#properties
*/
if (
$dataShouldBeSorted
&& \property_exists($schema, 'properties')
\property_exists($schema, 'properties')
&& \is_object($schema->properties)
) {
/** @var array<string, object> $objectPropertiesThatAreDefinedBySchema */
Expand Down Expand Up @@ -228,14 +227,12 @@ private function normalizeObject(
\ksort($additionalProperties);
}

$valueSchema = new \stdClass();

foreach ($additionalProperties as $name => $value) {
$normalized->{$name} = $this->normalizeData(
$value,
$valueSchema,
$pointerToData->append(Pointer\ReferenceToken::fromString((string) $name)),
);
$normalized->{$name} = $this->normalizeArray(
[$value],
$schema,
$pointerToData->append(Pointer\ReferenceToken::fromString($name)),
)[0];
}

return $normalized;
Expand Down
10 changes: 7 additions & 3 deletions src/Vendor/Composer/ComposerJsonNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,17 @@ public function __construct(string $schemaUri)
* @see https://github.com/composer/installers/blob/v2.2.0/src/Composer/Installers/BaseInstaller.php#L52-L58
* @see https://github.com/composer/installers/blob/v2.2.0/src/Composer/Installers/BaseInstaller.php#L116-L126
*/
Pointer\Specification::equals(Pointer\JsonPointer::fromJsonString('/extra/installer-paths')),
Pointer\Specification::closure(static function (Pointer\JsonPointer $jsonPointer): bool {
return 1 === \preg_match('{^\/extra\/installer-paths\/[^/]+$}', $jsonPointer->toJsonString());
}),
/**
* Patches need to be installed in a specific order.
*
* @see https://github.com/cweagans/composer-patches/blob/1.7.2/src/Patches.php#L229-L234
* @see https://github.com/cweagans/composer-patches/blob/1.7.2/src/Patches.php#L315-L329
*/
Pointer\Specification::closure(static function (Pointer\JsonPointer $jsonPointer): bool {
return 1 === \preg_match('{^/extra/patches/([^/])+$}', $jsonPointer->toJsonString());
return 1 === \preg_match('{^\/extra\/patches\/[^/]+\/[^/]+\/[^/]+$}', $jsonPointer->toJsonString());
}),
/**
* Repositories need to be iterated in a specific order, but can be an array or an object.
Expand All @@ -87,7 +89,9 @@ public function __construct(string $schemaUri)
*
* @see https://github.com/symfony/flex/blob/v2.2.3/src/Flex.php#L517-L519
*/
Pointer\Specification::equals(Pointer\JsonPointer::fromJsonString('/scripts/auto-scripts')),
Pointer\Specification::closure(static function (Pointer\JsonPointer $jsonPointer): bool {
return 1 === \preg_match('{^\/scripts\/auto-scripts\/[^/]+$}', $jsonPointer->toJsonString());
}),
),
),
new BinNormalizer(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
"homepage": "https://getcomposer.org/doc/04-schema.md#repositories",
"repositories": {
"foo": {
"type": "composer",
"url": "http://packages.foo.com",
"only": [
"foo/*"
],
"type": "composer",
"url": "http://packages.foo.com"
]
},
"bar": {
"type": "composer",
Expand Down

0 comments on commit 2839e97

Please sign in to comment.