Skip to content

Commit

Permalink
[Comments] Handle new line mix betweeen \n and \r\n in the code on Co…
Browse files Browse the repository at this point in the history
…mmentedCodeAnalyzer (#23)
  • Loading branch information
samsonasik committed Apr 4, 2024
1 parent ba8f8d3 commit b2b162e
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Comments/CommentedCodeAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,28 @@
namespace Rector\SwissKnife\Comments;

use Nette\Utils\FileSystem;
use Nette\Utils\Strings;

/**
* @see \Rector\SwissKnife\Tests\Comments\CommentedCodeAnalyzerTest
*/
final class CommentedCodeAnalyzer
{
/**
* @var string
* @see https://regex101.com/r/5OlGjG/1
* @see https://3v4l.org/Y8pSD
*/
private const NEWLINE_REGEX = '#\r?\n#';

/**
* @return int[]
*/
public function process(string $filePath, int $commentedLinesCountLimit): array
{
$commentedLines = [];

$fileLines = explode(PHP_EOL, FileSystem::read($filePath));
$fileLines = Strings::split(FileSystem::read($filePath), self::NEWLINE_REGEX);

$commentLinesCount = 0;

Expand Down

0 comments on commit b2b162e

Please sign in to comment.