Skip to content

Commit

Permalink
Use Composer for JSON encoding and decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
kubawerlos committed Feb 1, 2025
1 parent 8388593 commit bac60f6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ jobs:
composer_flags: '--prefer-lowest'
- os: ubuntu-latest
php-version: '7.4'
- os: ubuntu-latest
php-version: '8.0'
composer_flags: '--prefer-lowest'
- os: ubuntu-latest
php-version: '8.0'
- os: ubuntu-latest
Expand Down
9 changes: 4 additions & 5 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,20 @@ public static function getSubscribedEvents(): array

public static function clean(Event $event): void
{
$composerLockPath = \substr($event->getComposer()->getConfig()->getConfigSource()->getName(), 0, -4) . 'lock';
$composerLockPath = $event->getComposer()->getConfig()->getConfigSource()->getName();

$composerLockContent = \file_get_contents($composerLockPath);
\assert(\is_string($composerLockContent));
$lock = new JsonFile($composerLockPath);

/** @var array<string, array<string, array<string, array<string, string>>>> $composerLockData */
$composerLockData = \json_decode($composerLockContent, true);
$composerLockData = $lock->read();

foreach (['packages', 'packages-dev'] as $section) {
foreach (\array_keys($composerLockData[$section]) as $package) {
$composerLockData[$section][$package] = self::cleanPackage($composerLockData[$section][$package]);
}
}

\file_put_contents($composerLockPath, JsonFile::encode($composerLockData) . "\n");
$lock->write($composerLockData);
}

/**
Expand Down

0 comments on commit bac60f6

Please sign in to comment.