Skip to content

Commit

Permalink
Merge pull request #6 from php-etl/hotfix/jq-failures-on-composer-aut…
Browse files Browse the repository at this point in the history
…oloads

Fixed issues related to jq clearing the composer.json
  • Loading branch information
clemzarch authored Sep 14, 2023
2 parents c8cb914 + beab9fe commit 860d280
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions src/PHP/ComposerAutoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,39 @@ private static function pipe(string ...$commands): string
return implode(' | ', $commands);
}

private static function indirection(string $command, string $destination): string
{
return $command.' > '.self::escapeArgument($destination);
}

private static function and(string ...$commands): string
{
return implode(' \\'.\PHP_EOL.' && ', $commands);
}

public function __toString(): string
{
if (\count($this->autoloads) <= 0) {
return '';
}

$commands = implode(' \\'.\PHP_EOL.' && ', array_map(fn ($type, $autoload) => match ($type) {
'psr4' => self::pipe(
self::command('cat', 'composer.json'),
self::command('jq', '--indent', '4', sprintf('.autoload."psr-4" |= . + %s', json_encode($autoload, \JSON_THROW_ON_ERROR))),
self::command('tee', 'composer.json')
$commands = self::and(
...array_map(
fn ($type, $autoload) => match ($type) {

Check failure on line 68 in src/PHP/ComposerAutoload.php

View workflow job for this annotation

GitHub Actions / phpstan

Match expression does not handle remaining values: (int|string)

Check failure on line 68 in src/PHP/ComposerAutoload.php

View workflow job for this annotation

GitHub Actions / phpstan

Match expression does not handle remaining values: (int|string)

Check failure on line 68 in src/PHP/ComposerAutoload.php

View workflow job for this annotation

GitHub Actions / phpstan

Match expression does not handle remaining values: (int|string)

Check failure on line 68 in src/PHP/ComposerAutoload.php

View workflow job for this annotation

GitHub Actions / phpstan

Match expression does not handle remaining values: (int|string)
'psr4' => self::and(
self::pipe(
self::command('cat', 'composer.json'),
self::command('jq', '--indent', '4', sprintf('.autoload."psr-4" |= . + %s', json_encode($autoload, \JSON_THROW_ON_ERROR))),
self::command('tee', 'composer.temp')
),
self::indirection(self::command('cat', 'composer.temp'), 'composer.json'),
self::command('rm', 'composer.temp'),
)
},
array_keys($this->autoloads),
array_values($this->autoloads)
)
}, array_keys($this->autoloads), array_values($this->autoloads)));
);

return (string) new Dockerfile\Run(
<<<RUN
Expand Down

0 comments on commit 860d280

Please sign in to comment.