Skip to content

Commit

Permalink
[TASK] Reduce indirection in creating TypoScriptPrettyPrinterFormatCo…
Browse files Browse the repository at this point in the history
…nfiguration
  • Loading branch information
andreaswolf committed Aug 29, 2024
1 parent 35b525e commit 892a59b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 60 deletions.
3 changes: 1 addition & 2 deletions packages/fractor-typoscript/config/application.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
declare(strict_types=1);

use a9f\FractorTypoScript\Contract\TypoScriptFractor;
use a9f\FractorTypoScript\Factory\PrettyPrinterFormatFactory;
use a9f\FractorTypoScript\TypoScriptFileProcessor;
use a9f\FractorTypoScript\ValueObject\TypoScriptPrettyPrinterFormatConfiguration;
use Helmich\TypoScriptParser\Parser\Parser;
Expand All @@ -29,7 +28,7 @@
$services->set(PrettyPrinter::class);

$services->set('fractor.typoscript_processor.pretty_printer', TypoScriptPrettyPrinterFormatConfiguration::class)
->factory([service(PrettyPrinterFormatFactory::class), 'create']);
->factory([null, 'createFromParameterBag']);

$services->set(TypoScriptFileProcessor::class)
->arg('$typoScriptPrettyPrinterFormatConfiguration', service('fractor.typoscript_processor.pretty_printer'))
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

namespace a9f\FractorTypoScript\ValueObject;

use a9f\FractorTypoScript\Configuration\TypoScriptProcessorOption;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;

final readonly class TypoScriptPrettyPrinterFormatConfiguration
{
public function __construct(
Expand All @@ -15,16 +18,29 @@ public function __construct(
) {
}

/**
* @phpstan-param \Helmich\TypoScriptParser\Parser\Printer\PrettyPrinterConfiguration::INDENTATION_STYLE_* $style
*/
public static function fromValues(
int $size,
string $style,
bool $addClosingGlobal,
bool $includeEmptyLineBreaks,
bool $indentConditions
): self {
public static function createFromParameterBag(ParameterBagInterface $parameterBag): self
{
$size = $parameterBag->has(TypoScriptProcessorOption::INDENT_SIZE)
? $parameterBag->get(TypoScriptProcessorOption::INDENT_SIZE)
: 4;
$size = is_int($size) ? $size : 4;

$style = $parameterBag->has(TypoScriptProcessorOption::INDENT_CHARACTER)
? $parameterBag->get(TypoScriptProcessorOption::INDENT_CHARACTER)
: 'auto';
$style = is_string($style) ? $style : 'auto';

$addClosingGlobal = $parameterBag->has(TypoScriptProcessorOption::ADD_CLOSING_GLOBAL)
? (bool) $parameterBag->get(TypoScriptProcessorOption::ADD_CLOSING_GLOBAL)
: true;

$includeEmptyLineBreaks = $parameterBag->has(TypoScriptProcessorOption::INCLUDE_EMPTY_LINE_BREAKS)
? (bool) $parameterBag->get(TypoScriptProcessorOption::INCLUDE_EMPTY_LINE_BREAKS)
: true;

$indentConditions = $parameterBag->has(TypoScriptProcessorOption::INDENT_CONDITIONS)
&& (bool) $parameterBag->get(TypoScriptProcessorOption::INDENT_CONDITIONS);

return new self($size, $style, $addClosingGlobal, $includeEmptyLineBreaks, $indentConditions);
}

Expand Down

0 comments on commit 892a59b

Please sign in to comment.