Skip to content

Commit

Permalink
refactor: extract initializing the PHAR algorithms for PharInfo (#953)
Browse files Browse the repository at this point in the history
  • Loading branch information
theofidry authored Mar 25, 2023
1 parent 1f1b1ff commit ad0ddc1
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/PharInfo/PharInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ final class PharInfo
private ?string $hash = null;

public function __construct(string $pharFile)
{
self::initAlgorithms();

try {
$this->phar = new Phar($pharFile);
} catch (UnexpectedValueException) {
$this->phar = new PharData($pharFile);
}
}

private static function initAlgorithms(): void
{
if (!isset(self::$ALGORITHMS)) {
self::$ALGORITHMS = [];
Expand All @@ -46,12 +57,6 @@ public function __construct(string $pharFile)
self::$ALGORITHMS[$compressionAlgorithm->value] = $compressionAlgorithm->name;
}
}

try {
$this->phar = new Phar($pharFile);
} catch (UnexpectedValueException) {
$this->phar = new PharData($pharFile);
}
}

public function equals(self $pharInfo): bool
Expand Down

0 comments on commit ad0ddc1

Please sign in to comment.