This repository has been archived by the owner on Dec 3, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ECS] Refactor bstractSnippetFormatterCommand to composition
- Loading branch information
1 parent
24c8481
commit d537cb9
Showing
11 changed files
with
249 additions
and
159 deletions.
There are no files selected for viewing
104 changes: 104 additions & 0 deletions
104
...oding-standard/packages/snippet-formatter/src/Application/SnippetFormatterApplication.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,104 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Symplify\EasyCodingStandard\SnippetFormatter\Application; | ||
|
||
use Symfony\Component\Console\Style\SymfonyStyle; | ||
use Symplify\EasyCodingStandard\Configuration\Configuration; | ||
use Symplify\EasyCodingStandard\Reporter\ProcessedFileReporter; | ||
use Symplify\EasyCodingStandard\SnippetFormatter\Formatter\SnippetFormatter; | ||
use Symplify\EasyCodingStandard\SnippetFormatter\Reporter\SnippetReporter; | ||
use Symplify\PackageBuilder\Console\ShellCode; | ||
use Symplify\SmartFileSystem\SmartFileInfo; | ||
use Symplify\SmartFileSystem\SmartFileSystem; | ||
|
||
final class SnippetFormatterApplication | ||
{ | ||
/** | ||
* @var Configuration | ||
*/ | ||
private $configuration; | ||
|
||
/** | ||
* @var SnippetReporter | ||
*/ | ||
private $snippetReporter; | ||
|
||
/** | ||
* @var SnippetFormatter | ||
*/ | ||
private $snippetFormatter; | ||
|
||
/** | ||
* @var SmartFileSystem | ||
*/ | ||
private $smartFileSystem; | ||
|
||
/** | ||
* @var SymfonyStyle | ||
*/ | ||
private $symfonyStyle; | ||
|
||
/** | ||
* @var ProcessedFileReporter | ||
*/ | ||
private $processedFileReporter; | ||
|
||
public function __construct( | ||
Configuration $configuration, | ||
SnippetReporter $snippetReporter, | ||
SnippetFormatter $snippetFormatter, | ||
SmartFileSystem $smartFileSystem, | ||
SymfonyStyle $symfonyStyle, | ||
ProcessedFileReporter $processedFileReporter | ||
) { | ||
$this->configuration = $configuration; | ||
$this->snippetReporter = $snippetReporter; | ||
$this->snippetFormatter = $snippetFormatter; | ||
$this->smartFileSystem = $smartFileSystem; | ||
$this->symfonyStyle = $symfonyStyle; | ||
$this->processedFileReporter = $processedFileReporter; | ||
} | ||
|
||
/** | ||
* @param SmartFileInfo[] $fileInfos | ||
*/ | ||
public function processFileInfosWithSnippetPattern( | ||
Configuration $configuration, | ||
array $fileInfos, | ||
string $snippetPattern, | ||
string $kind | ||
): int { | ||
$sources = $configuration->getSources(); | ||
|
||
$fileCount = count($fileInfos); | ||
if ($fileCount === 0) { | ||
$this->snippetReporter->reportNoFilesFound($sources); | ||
return ShellCode::SUCCESS; | ||
} | ||
|
||
$this->symfonyStyle->progressStart($fileCount); | ||
foreach ($fileInfos as $fileInfo) { | ||
$this->processFileInfoWithPattern($fileInfo, $snippetPattern, $kind); | ||
$this->symfonyStyle->progressAdvance(); | ||
} | ||
|
||
return $this->processedFileReporter->report($fileCount); | ||
} | ||
|
||
private function processFileInfoWithPattern(SmartFileInfo $phpFileInfo, string $snippetPattern, string $kind): void | ||
{ | ||
$fixedContent = $this->snippetFormatter->format($phpFileInfo, $snippetPattern, $kind); | ||
if ($phpFileInfo->getContents() === $fixedContent) { | ||
// nothing has changed | ||
return; | ||
} | ||
|
||
if (! $this->configuration->isFixer()) { | ||
return; | ||
} | ||
|
||
$this->smartFileSystem->dumpFile($phpFileInfo->getPathname(), $fixedContent); | ||
} | ||
} |
84 changes: 0 additions & 84 deletions
84
...oding-standard/packages/snippet-formatter/src/Command/AbstractSnippetFormatterCommand.php
This file was deleted.
Oops, something went wrong.
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
34 changes: 34 additions & 0 deletions
34
packages/easy-coding-standard/packages/snippet-formatter/src/Reporter/SnippetReporter.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,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Symplify\EasyCodingStandard\SnippetFormatter\Reporter; | ||
|
||
use Symfony\Component\Console\Style\SymfonyStyle; | ||
|
||
final class SnippetReporter | ||
{ | ||
/** | ||
* @var SymfonyStyle | ||
*/ | ||
private $symfonyStyle; | ||
|
||
public function __construct(SymfonyStyle $symfonyStyle) | ||
{ | ||
$this->symfonyStyle = $symfonyStyle; | ||
} | ||
|
||
/** | ||
* @param string[] $sources | ||
*/ | ||
public function reportNoFilesFound(array $sources): void | ||
{ | ||
$message = sprintf( | ||
'No files found in "%s" paths.%sCheck CLI arguments or "Option::PATHS" parameter in "ecs.php" config file', | ||
implode('", ', $sources), | ||
PHP_EOL | ||
); | ||
|
||
$this->symfonyStyle->warning($message); | ||
} | ||
} |
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
Oops, something went wrong.