Skip to content

Commit 8f998aa

Browse files
authored
[FEATURE] Improve Json output format (#366)
- Include full class name in json output - Add configuration option to show the changelog Resolves: #349
1 parent 1f4be64 commit 8f998aa

File tree

17 files changed

+90
-24
lines changed

17 files changed

+90
-24
lines changed

e2e/only-option/expected-output.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
----------- end diff -----------
1313

1414
Applied rules:
15-
* RenameConfigXhtmlDoctypeToDoctypeFractor (https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/12.4/Deprecation-100461-TypoScriptOptionConfigxhtmlDoctype.html)
15+
* RenameConfigXhtmlDoctypeToDoctypeFractor
1616

1717

1818
[OK] 1 file has been changed by Fractor

e2e/typo3-extension/expected-output.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
----------- end diff -----------
1212

1313
Applied rules:
14-
* MigrateIncludeTypoScriptSyntaxFractor (https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/13.4/Deprecation-105171-INCLUDE_TYPOSCRIPTTypoScriptSyntax.html)
14+
* MigrateIncludeTypoScriptSyntaxFractor
1515

1616

1717
[OK] 1 file has been changed by Fractor

e2e/typo3-typoscript/expected-output.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
----------- end diff -----------
2020

2121
Applied rules:
22-
* RemoveUseCacheHashFromTypolinkTypoScriptFractor (https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/10.0/Deprecation-88406-SetCacheHashnoCacheHashOptionsInViewHelpersAndUriBuilder.html)
22+
* RemoveUseCacheHashFromTypolinkTypoScriptFractor
2323

2424

2525
[OK] 1 file has been changed by Fractor

e2e/typo3-xml/expected-output.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
----------- end diff -----------
1919

2020
Applied rules:
21-
* MigrateNullFlagFlexFormFractor (https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/12.0/Deprecation-97384-TCAOptionNullable.html)
21+
* MigrateNullFlagFlexFormFractor
2222

2323

2424
[OK] 1 file has been changed by Fractor

e2e/typo3-yaml/expected-output.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
----------- end diff -----------
7171

7272
Applied rules:
73-
* EmailFinisherYamlFractor (https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/10.0/Feature-80420-AllowMultipleRecipientsInEmailFinisher.html)
73+
* EmailFinisherYamlFractor
7474

7575

7676
[OK] 1 file has been changed by Fractor

packages/fractor-xml/tests/AbstractXmlFractorTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function canHandle(\DOMNode $node): bool
2323
return $node->nodeName === 'Child';
2424
}
2525

26-
public function refactor(\DOMNode $node): \DOMNode
26+
public function refactor(\DOMNode $node): \DOMElement
2727
{
2828
if ($node->ownerDocument === null) {
2929
throw new \RuntimeException('Node does not have an ownerDocument, cannot create element');
@@ -51,7 +51,7 @@ public function getRuleDefinition(): RuleDefinition
5151
self::assertStringStartsWith(
5252
'a9f\\FractorXml\\AbstractXmlFractor@anonymous',
5353
$file->getAppliedRules()[0]
54-
->getFractorRule()
54+
->getFractorClass()
5555
);
5656
}
5757
}

packages/fractor/src/Application/ValueObject/AppliedRule.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
final readonly class AppliedRule
1010
{
1111
/**
12-
* @param class-string<FractorRule> $fractorRule
12+
* @param class-string<FractorRule> $fractorClass
1313
*/
1414
private function __construct(
15-
private string $fractorRule,
15+
private string $fractorClass,
1616
) {
1717
}
1818

@@ -32,8 +32,8 @@ public static function fromClassString(string $fractorRule): self
3232
/**
3333
* @return class-string<FractorRule>
3434
*/
35-
public function getFractorRule(): string
35+
public function getFractorClass(): string
3636
{
37-
return $this->fractorRule;
37+
return $this->fractorClass;
3838
}
3939
}

packages/fractor/src/ChangesReporting/Output/ConsoleOutputFormatter.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function getName(): string
2929

3030
public function report(ProcessResult $processResult, Configuration $configuration): void
3131
{
32-
$this->reportFileDiffs($processResult->getFileDiffs(), false);
32+
$this->reportFileDiffs($processResult->getFileDiffs(), false, $configuration->shouldShowChangelog());
3333

3434
// to keep space between progress bar and success message
3535
if ($configuration->shouldShowProgressBar() && $processResult->getFileDiffs() === []) {
@@ -43,7 +43,7 @@ public function report(ProcessResult $processResult, Configuration $configuratio
4343
/**
4444
* @param FileDiff[] $fileDiffs
4545
*/
46-
private function reportFileDiffs(array $fileDiffs, bool $absoluteFilePath): void
46+
private function reportFileDiffs(array $fileDiffs, bool $absoluteFilePath, bool $showChangelog): void
4747
{
4848
if (\count($fileDiffs) <= 0) {
4949
return;
@@ -68,7 +68,9 @@ private function reportFileDiffs(array $fileDiffs, bool $absoluteFilePath): void
6868

6969
if ($fileDiff->getAppliedRules() !== []) {
7070
$this->symfonyStyle->writeln('<options=underscore>Applied rules:</>');
71-
$this->symfonyStyle->listing($fileDiff->getAppliedRules());
71+
$this->symfonyStyle->listing(
72+
$showChangelog ? $fileDiff->getChangelogsLines() : $fileDiff->getFractorShortClasses()
73+
);
7274
$this->symfonyStyle->newLine();
7375
}
7476
}

packages/fractor/src/ChangesReporting/Output/JsonOutputFormatter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function report(ProcessResult $processResult, Configuration $configuratio
3737
$errorsJson['file_diffs'][] = [
3838
'file' => $filePath,
3939
'diff' => $fileDiff->getDiff(),
40-
'applied_rules' => $fileDiff->getAppliedRules(),
40+
'applied_rules' => $configuration->shouldShowChangelog() ? $fileDiff->getChangelogsLines() : $fileDiff->getFractorClasses(),
4141
];
4242

4343
// for CI

packages/fractor/src/Configuration/ConfigurationFactory.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public function createFromInput(InputInterface $input): Configuration
2828

2929
$outputFormat = (string) $input->getOption(Option::OUTPUT_FORMAT);
3030
$showProgressBar = $this->shouldShowProgressBar($input, $outputFormat);
31+
$showChangelog = $this->shouldShowChangelog($input);
3132

3233
/** @var list<non-empty-string> $paths */
3334
$paths = $this->resolvePaths($input);
@@ -48,7 +49,8 @@ public function createFromInput(InputInterface $input): Configuration
4849
$fileExtensions,
4950
$paths,
5051
(array) $this->parameterBag->get(Option::SKIP),
51-
$onlyRule
52+
$onlyRule,
53+
$showChangelog
5254
);
5355
}
5456

@@ -79,6 +81,11 @@ private function shouldShowProgressBar(InputInterface $input, string $outputForm
7981
return $outputFormat === ConsoleOutputFormatter::NAME;
8082
}
8183

84+
private function shouldShowChangelog(InputInterface $input): bool
85+
{
86+
return (bool) $input->getOption(Option::SHOW_CHANGELOG);
87+
}
88+
8289
/**
8390
* @return string[]|mixed[]
8491
*/

0 commit comments

Comments
 (0)