Skip to content

Commit

Permalink
[Printer] Remove has InlineHTML node check after apply changes on Php…
Browse files Browse the repository at this point in the history
…FileProcessor (#4601)

* [Printer] Remove has InlineHTML node check after apply changes on PhpFileProcessor

* [ci-review] Rector Rectify

* move

* reformat

---------

Co-authored-by: GitHub Action <actions@github.com>
  • Loading branch information
samsonasik and actions-user committed Jul 25, 2023
1 parent a04101c commit 2951cc8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 24 deletions.
8 changes: 7 additions & 1 deletion build/target-repository/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,14 @@ dump_node($node, 1);

## Known Drawbacks

Rector uses [nikic/php-parser](https://github.com/nikic/PHP-Parser/), built on technology called an *abstract syntax tree* (AST). An AST doesn't know about spaces and when written to a file it produces poorly formatted code in both PHP and docblock annotations.

### How to Apply Coding Standards?

Rector uses [nikic/php-parser](https://github.com/nikic/PHP-Parser/), built on technology called an *abstract syntax tree* (AST). An AST doesn't know about spaces and when written to a file it produces poorly formatted code in both PHP and docblock annotations. **That's why your project needs to have a coding standard tool** and a set of formatting rules, so it can make Rector's output code nice and shiny again.
**Your project needs to have a coding standard tool** and a set of formatting rules, so it can make Rector's output code nice and shiny again.

We're using [ECS](https://github.com/symplify/easy-coding-standard) with [this setup](https://github.com/rectorphp/rector-src/blob/main/ecs.php).

### May cause unexpected output on File with mixed PHP+HTML content

When you apply changes to File(s) thas has mixed PHP+HTML content, you may need to manually verify the changed file after apply the changes.
12 changes: 1 addition & 11 deletions src/Application/FileProcessor/PhpFileProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
use Rector\Parallel\ValueObject\Bridge;
use Rector\PostRector\Application\PostFileProcessor;
use Rector\Testing\PHPUnit\StaticPHPUnitEnvironment;
use Symfony\Component\Console\Style\SymfonyStyle;
use Throwable;

final class PhpFileProcessor implements FileProcessorInterface
Expand All @@ -41,8 +40,7 @@ public function __construct(
private readonly ChangedFilesDetector $changedFilesDetector,
private readonly PostFileProcessor $postFileProcessor,
private readonly ErrorFactory $errorFactory,
private readonly FilePathHelper $filePathHelper,
private readonly SymfonyStyle $symfonyStyle
private readonly FilePathHelper $filePathHelper
) {
}

Expand Down Expand Up @@ -92,14 +90,6 @@ public function process(File $file, Configuration $configuration): array
}
} while ($fileHasChangedInCurrentPass);

// show warning on has InlineHTML node if file has changed
if ($fileHasChanged && $file->hasInlineHTMLNode()) {
$this->symfonyStyle->warning(sprintf(
'File %s has InlineHTML node, this may cause unexpected output, you may need to manually verify the changed file',
$this->filePathHelper->relativePath($file->getFilePath())
));
}

// 5. add as cacheable if not changed at all
if (! $fileHasChanged) {
$this->changedFilesDetector->addCachableFile($file->getFilePath());
Expand Down
12 changes: 0 additions & 12 deletions src/ValueObject/Application/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
namespace Rector\Core\ValueObject\Application;

use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\InlineHTML;
use PhpParser\NodeFinder;
use Rector\ChangesReporting\ValueObject\RectorWithLineChange;
use Rector\Core\Exception\ShouldNotHappenException;
use Rector\Core\ValueObject\Reporting\FileDiff;
Expand Down Expand Up @@ -154,14 +152,4 @@ public function getRectorWithLineChanges(): array
{
return $this->rectorWithLineChanges;
}

public function hasInlineHTMLNode(): bool
{
if ($this->newStmts === []) {
throw new ShouldNotHappenException();
}

$nodeFinder = new NodeFinder();
return (bool) $nodeFinder->findFirstInstanceOf($this->newStmts, InlineHTML::class);
}
}

0 comments on commit 2951cc8

Please sign in to comment.