Skip to content

Commit

Permalink
Merge branch 'main' into 3.x
Browse files Browse the repository at this point in the history
  • Loading branch information
eliashaeussler committed Dec 4, 2024
2 parents 251981a + 47b7dae commit e75f2d3
Show file tree
Hide file tree
Showing 10 changed files with 209 additions and 232 deletions.
14 changes: 7 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@
"eliashaeussler/version-bumper": "^1.2",
"ergebnis/composer-normalize": "^2.26",
"phpstan/extension-installer": "^1.2",
"phpstan/phpstan": "^1.9",
"phpstan/phpstan-deprecation-rules": "^1.1",
"phpstan/phpstan-phpunit": "^1.1",
"phpstan/phpstan-strict-rules": "^1.2",
"phpstan/phpstan-symfony": "^1.2",
"phpstan/phpstan-webmozart-assert": "^1.2",
"phpstan/phpstan": "^2.0",
"phpstan/phpstan-deprecation-rules": "^2.0",
"phpstan/phpstan-phpunit": "^2.0",
"phpstan/phpstan-strict-rules": "^2.0",
"phpstan/phpstan-symfony": "^2.0",
"phpstan/phpstan-webmozart-assert": "^2.0",
"phpunit/phpunit": "^10.1 || ^11.0",
"rector/rector": "^1.0.0",
"rector/rector": "^2.0@rc",
"seld/jsonlint": "^1.9"
},
"autoload": {
Expand Down
363 changes: 154 additions & 209 deletions composer.lock

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions src/DependencyInjection/CompilerPass/EventListenerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,16 @@ public function process(DependencyInjection\ContainerBuilder $container): void
continue;
}

if (null === ($className = $service->getClass())) {
/** @var class-string|null $className */
$className = $service->getClass();

if (null === $className) {
throw Exception\ShouldNotHappenException::create();
}

/** @var array{method?: string, event?: class-string} $tag */
foreach ($tags as $tag) {
$method = $tag['method'] ?? '__invoke';
/** @var class-string $className */
$event = $tag['event'] ?? $this->determineEventFromClassMethod($className, $method);

$dispatcher->addMethodCall(
Expand Down
1 change: 1 addition & 0 deletions src/Exception/InvalidConfigurationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public static function forValidationErrors(?JsonSchema\Errors\ValidationError $e

if (null !== $errors) {
$formatter = new JsonSchema\Errors\ErrorFormatter();
/** @var array<string, string> $formattedErrors */
$formattedErrors = $formatter->format($errors, false);

foreach ($formattedErrors as $path => $errorMessage) {
Expand Down
3 changes: 3 additions & 0 deletions src/Helper/ArrayHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ public static function trimExplode(string $subject, string $delimiter = ','): ar
);
}

/**
* @phpstan-assert-if-true array<string, mixed>|ArrayObject<string, mixed> $subject
*/
private static function pathSegmentExists(mixed $subject, string $pathSegment): bool
{
if (!is_array($subject) && !($subject instanceof ArrayObject)) {
Expand Down
3 changes: 2 additions & 1 deletion src/Resource/Http/PhpApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use Psr\Http\Message;
use stdClass;

use function is_string;
use function property_exists;

/**
Expand Down Expand Up @@ -65,7 +66,7 @@ public function getLatestStableVersion(string $branch): string
$json = Utils::jsonDecode((string) $response->getBody());

// Fall back to .0 release if version cannot be determined via API
if (!($json instanceof stdClass) || !property_exists($json, 'version')) {
if (!($json instanceof stdClass) || !property_exists($json, 'version') || !is_string($json->version)) {
return $branch.'.0';
}

Expand Down
9 changes: 6 additions & 3 deletions src/Resource/Local/Git.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

use SebastianFeldmann\Cli;

use function reset;
use function trim;

/**
Expand Down Expand Up @@ -66,13 +67,15 @@ private function readConfig(string $configPath): ?string
private function run(Cli\Command $command): ?string
{
$result = $this->runner->run($command);
/** @var list<string> $output */
$output = $result->getBufferedOutput();

if (!$result->isSuccessful() || [] === $result->getBufferedOutput()) {
if (!$result->isSuccessful() || [] === $output) {
return null;
}

$output = $result->getBufferedOutput()[0];
$output = reset($output);

return '' !== trim((string) $output) ? trim((string) $output) : null;
return '' !== trim($output) ? trim($output) : null;
}
}
4 changes: 3 additions & 1 deletion src/Template/Provider/BaseProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,10 @@ protected function isPackageSupported(Package\BasePackage $package): bool
return false;
}

/** @var array<string, mixed> $extra */
$extra = $package->getExtra();
$excludeFromListing = (bool) Helper\ArrayHelper::getValueByPath(
$package->getExtra(),
$extra,
'cpsit/project-builder.exclude-from-listing',
);

Expand Down
1 change: 1 addition & 0 deletions src/Twig/Renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public function render(
?string $template = null,
array $variables = [],
): string {
/** @var array<string, mixed> $mergedVariables */
$mergedVariables = array_replace_recursive($instructions->getTemplateVariables(), $variables);
$event = new Event\BeforeTemplateRenderedEvent($this->twig, $instructions, $mergedVariables);
$template ??= $this->defaultTemplate;
Expand Down
36 changes: 27 additions & 9 deletions tests/src/Template/Provider/BaseProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
use function array_map;
use function array_reduce;
use function dirname;
use function is_array;
use function json_encode;
use function reset;
use function sprintf;
Expand Down Expand Up @@ -276,24 +277,35 @@ public static function listTemplateSourcesListsAllAvailableTemplateSourcesDataPr
],
[],
];

$package1 = self::createPackage('foo/baz-2');
$package2 = self::createPackage('foo/baz-3');

yield 'unsupported and supported packages' => [
[
self::createPackage('foo/baz-1', 'library'),
$package1 = self::createPackage('foo/baz-2'),
$package2 = self::createPackage('foo/baz-3'),
$package1,
$package2,
],
[
$package1,
$package2,
],
];

$abandonedPackage1 = self::createPackage(name: 'foo/baz-1', abandoned: true);
$abandonedPackage2 = self::createPackage(name: 'foo/baz-3', abandoned: 'foo/bar-3');
$package1 = self::createPackage('foo/baz-2');
$package2 = self::createPackage('foo/baz-4');
$package3 = self::createPackage('foo/baz-5');

yield 'abandoned packages after maintained' => [
[
$abandonedPackage1 = self::createPackage(name: 'foo/baz-1', abandoned: true),
$package1 = self::createPackage('foo/baz-2'),
$abandonedPackage2 = self::createPackage(name: 'foo/baz-3', abandoned: 'foo/bar-3'),
$package2 = self::createPackage('foo/baz-4'),
$package3 = self::createPackage('foo/baz-5'),
$abandonedPackage1,
$package1,
$abandonedPackage2,
$package2,
$package3,
],
[
$package1,
Expand Down Expand Up @@ -385,8 +397,14 @@ private function mockPackagesServerResponse(array $packages): void
[
'packages' => array_reduce(
$packages,
function (array $carry, Package\PackageInterface $package) use ($dumper): array {
$carry[$package->getName()][$package->getPrettyVersion()] = $dumper->dump($package);
static function (array $carry, Package\PackageInterface $package) use ($dumper): array {
$packageName = $package->getName();

if (!is_array($carry[$packageName] ?? null)) {
$carry[$packageName] = [];
}

$carry[$packageName][$package->getPrettyVersion()] = $dumper->dump($package);

return $carry;
},
Expand Down

0 comments on commit e75f2d3

Please sign in to comment.