-
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TASK: Add options to configure PrettyPrinter (#4038)
* TASK: Add options to configure PrettyPrinter Resolves: #3643 * [CI] Rector Rectify --------- Co-authored-by: GitHub Action <action@github.com>
- Loading branch information
1 parent
f853b45
commit f9d831f
Showing
5 changed files
with
93 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/FileProcessor/TypoScript/Factory/PrettyPrinterConfigurationFactory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Ssch\TYPO3Rector\FileProcessor\TypoScript\Factory; | ||
|
||
use Helmich\TypoScriptParser\Parser\Printer\PrettyPrinterConfiguration; | ||
use Rector\Core\Configuration\Parameter\ParameterProvider; | ||
use Rector\Core\ValueObject\Application\File; | ||
use Ssch\TYPO3Rector\Configuration\Typo3Option; | ||
use Ssch\TYPO3Rector\ValueObject\Indent; | ||
|
||
final class PrettyPrinterConfigurationFactory | ||
{ | ||
/** | ||
* @readonly | ||
*/ | ||
private ParameterProvider $parameterProvider; | ||
|
||
public function __construct(ParameterProvider $parameterProvider) | ||
{ | ||
$this->parameterProvider = $parameterProvider; | ||
} | ||
|
||
public function createPrettyPrinterConfiguration(File $file): PrettyPrinterConfiguration | ||
{ | ||
// keep original TypoScript format | ||
$indent = Indent::fromFile($file); | ||
|
||
$prettyPrinterConfiguration = PrettyPrinterConfiguration::create(); | ||
|
||
if ($indent->isSpace()) { | ||
// default indent | ||
$indentation = $this->parameterProvider->provideParameter( | ||
Typo3Option::TYPOSCRIPT_INDENT_SIZE | ||
) ?? $indent->length(); | ||
$prettyPrinterConfiguration = $prettyPrinterConfiguration->withSpaceIndentation($indentation); | ||
} else { | ||
$prettyPrinterConfiguration = $prettyPrinterConfiguration->withTabs(); | ||
} | ||
|
||
if ($this->parameterProvider->provideParameter(Typo3Option::TYPOSCRIPT_INDENT_CONDITIONS) ?? false) { | ||
$prettyPrinterConfiguration = $prettyPrinterConfiguration->withIndentConditions(); | ||
} | ||
|
||
if ($this->parameterProvider->provideParameter(Typo3Option::TYPOSCRIPT_WITH_CLOSING_GLOBAL_STATEMENT) ?? true) { | ||
$prettyPrinterConfiguration = $prettyPrinterConfiguration->withClosingGlobalStatement(); | ||
} | ||
|
||
if ($this->parameterProvider->provideParameter(Typo3Option::TYPOSCRIPT_WITH_EMPTY_LINE_BREAKS) ?? true) { | ||
$prettyPrinterConfiguration = $prettyPrinterConfiguration->withEmptyLineBreaks(); | ||
} | ||
|
||
return $prettyPrinterConfiguration; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters