Skip to content

Commit

Permalink
refactor: Rename composer files to composer artifacts (#1286)
Browse files Browse the repository at this point in the history
  • Loading branch information
theofidry authored Dec 16, 2023
1 parent 7feeb4e commit 23d6f5b
Show file tree
Hide file tree
Showing 21 changed files with 227 additions and 221 deletions.
12 changes: 6 additions & 6 deletions src/Box.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,29 +159,29 @@ public function endBuffering(?callable $dumpAutoload): void
/**
* @param non-empty-string $normalizedVendorDir Normalized path ("/" path separator and no trailing "/") to the Composer vendor directory
*/
public function removeComposerArtefacts(string $normalizedVendorDir): void
public function removeComposerArtifacts(string $normalizedVendorDir): void
{
Assert::false($this->buffering, 'The buffering must have ended before removing the Composer artefacts');

$composerFiles = [
$composerArtifacts = [
'composer.json',
'composer.lock',
$normalizedVendorDir.'/composer/installed.json',
];

$this->phar->startBuffering();

foreach ($composerFiles as $composerFile) {
$localComposerFile = ($this->mapFile)($composerFile);
foreach ($composerArtifacts as $composerArtifact) {
$localComposerArtifact = ($this->mapFile)($composerArtifact);

$pharFilePath = sprintf(
'phar://%s/%s',
$this->phar->getPath(),
$localComposerFile,
$localComposerArtifact,
);

if (file_exists($pharFilePath)) {
$this->phar->delete($localComposerFile);
$this->phar->delete($localComposerArtifact);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,28 @@

namespace KevinGH\Box\Composer\Artifact;

final readonly class ComposerFile
/**
* @private
*/
final readonly class ComposerArtifact
{
public function __construct(
public string $path,
public array $decodedContents,
) {
}

public function toComposerJson(): DecodedComposerJson
public function toComposerJson(): ComposerJson
{
return new DecodedComposerJson(
return new ComposerJson(
$this->path,
$this->decodedContents,
);
}

public function toComposerLock(): DecodedComposerLock
public function toComposerLock(): ComposerLock
{
return new DecodedComposerLock(
return new ComposerLock(
$this->path,
$this->decodedContents,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,29 @@
use function array_map;
use function array_values;

final readonly class ComposerFiles
/**
* @private
*/
final readonly class ComposerArtifacts
{
public function __construct(
private ?DecodedComposerJson $composerJson = null,
private ?DecodedComposerLock $composerLock = null,
private ?ComposerFile $installedJson = null,
public readonly ?ComposerJson $composerJson = null,
public readonly ?ComposerLock $composerLock = null,
public readonly ?ComposerArtifact $installedJson = null,
) {
}

public function getComposerJson(): ?DecodedComposerJson
public function getComposerJson(): ?ComposerJson
{
return $this->composerJson;
}

public function getComposerLock(): ?DecodedComposerLock
public function getComposerLock(): ?ComposerLock
{
return $this->composerLock;
}

public function getInstalledJson(): ?ComposerFile
public function getInstalledJson(): ?ComposerArtifact
{
return $this->installedJson;
}
Expand All @@ -50,7 +53,7 @@ public function getPaths(): array
return array_values(
array_filter(
array_map(
static fn (null|ComposerFile|DecodedComposerJson|DecodedComposerLock $file): ?string => $file?->path,
static fn (null|ComposerArtifact|ComposerJson|ComposerLock $file): ?string => $file?->path,
[$this->composerJson, $this->composerLock, $this->installedJson],
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
/**
* @private
*/
final readonly class DecodedComposerJson
final readonly class ComposerJson
{
/**
* @param array $decodedContents Decoded JSON contents of the `composer.json` file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
/**
* @private
*/
final readonly class DecodedComposerLock
final readonly class ComposerLock
{
/**
* @param array $decodedContents Decoded JSON contents of the `composer.lock` file
Expand Down
14 changes: 7 additions & 7 deletions src/Composer/ComposerConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

namespace KevinGH\Box\Composer;

use KevinGH\Box\Composer\Artifact\DecodedComposerJson;
use KevinGH\Box\Composer\Artifact\DecodedComposerLock;
use KevinGH\Box\Composer\Artifact\ComposerJson;
use KevinGH\Box\Composer\Artifact\ComposerLock;
use Symfony\Component\Filesystem\Path;
use function array_filter;
use function array_map;
Expand All @@ -37,8 +37,8 @@ final class ComposerConfiguration
*/
public static function retrieveDevPackages(
string $basePath,
?DecodedComposerJson $composerJson,
?DecodedComposerLock $composerLock,
?ComposerJson $composerJson,
?ComposerLock $composerLock,
bool $excludeDevPackages,
): array {
if (null === $composerJson
Expand All @@ -60,8 +60,8 @@ public static function retrieveDevPackages(
*/
private static function getDevPackagePaths(
string $basePath,
DecodedComposerJson $composerJson,
DecodedComposerLock $composerLock,
ComposerJson $composerJson,
ComposerLock $composerLock,
): array {
$vendorDir = Path::makeAbsolute(
self::retrieveVendorDir($composerJson),
Expand All @@ -83,7 +83,7 @@ private static function getDevPackagePaths(
);
}

public static function retrieveVendorDir(?DecodedComposerJson $composerJson): string
public static function retrieveVendorDir(?ComposerJson $composerJson): string
{
return $composerJson?->getVendorDir() ?? self::DEFAULT_VENDOR_DIR;
}
Expand Down
Loading

0 comments on commit 23d6f5b

Please sign in to comment.