Skip to content

Commit

Permalink
refactor: Introduce a factory for the PHP compactor
Browse files Browse the repository at this point in the history
  • Loading branch information
theofidry committed Nov 22, 2023
1 parent 412d17d commit 7934383
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
16 changes: 16 additions & 0 deletions src/Compactor/Php.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@

namespace KevinGH\Box\Compactor;

use KevinGH\Box\Annotation\CompactedFormatter;
use KevinGH\Box\Annotation\DocblockAnnotationParser;
use phpDocumentor\Reflection\DocBlockFactory;
use PhpToken;
use RuntimeException;
use Webmozart\Assert\Assert;
Expand Down Expand Up @@ -46,6 +48,20 @@
*/
final class Php extends FileExtensionCompactor
{
/**
* @param list<string> $ignoredAnnotations
*/
public static function create(array $ignoredAnnotations): self
{
return new self(
new DocblockAnnotationParser(
DocBlockFactory::createInstance(),
new CompactedFormatter(),
$ignoredAnnotations,
),
);
}

public function __construct(
private ?DocblockAnnotationParser $annotationParser,
array $extensions = ['php'],
Expand Down
11 changes: 1 addition & 10 deletions src/Configuration/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
use Humbug\PhpScoper\Configuration\Configuration as PhpScoperConfiguration;
use Humbug\PhpScoper\Container;
use InvalidArgumentException;
use KevinGH\Box\Annotation\CompactedFormatter;
use KevinGH\Box\Annotation\DocblockAnnotationParser;
use KevinGH\Box\Compactor\Compactor;
use KevinGH\Box\Compactor\Compactors;
use KevinGH\Box\Compactor\Php as PhpCompactor;
Expand All @@ -36,7 +34,6 @@
use KevinGH\Box\Phar\SigningAlgorithm;
use KevinGH\Box\PhpScoper\SerializableScoper;
use Phar;
use phpDocumentor\Reflection\DocBlockFactory;
use RuntimeException;
use Seld\JsonLint\ParsingException;
use SplFileInfo;
Expand Down Expand Up @@ -2686,13 +2683,7 @@ private static function createPhpCompactor(?array $ignoredAnnotations): Compacto
),
);

return new PhpCompactor(
new DocblockAnnotationParser(
DocBlockFactory::createInstance(),
new CompactedFormatter(),
$ignoredAnnotations,
),
);
return PhpCompactor::create($ignoredAnnotations);
}

private static function createPhpScoperCompactor(
Expand Down

0 comments on commit 7934383

Please sign in to comment.