Skip to content

Commit

Permalink
- improving line-ending fixer
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfy-j committed Oct 11, 2019
1 parent ca47d9d commit b5af28d
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions bin/spiral-cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,28 @@ class CodeStyleHelper
public function normalizeEndings(array $paths)
{
$finder = new Symfony\Component\Finder\Finder();
$finder->in($paths)->files();

foreach ($finder as $file) {
$lines = file((string)$file);
foreach ($lines as &$line) {
$line = rtrim($line, "\n\r ");
unset($line);
foreach ($paths as $path) {
if (is_file($path)) {
$this->normalizeContent($path);
} else {
$finder->in($path);
}
}

foreach ($finder->files() as $path) {
$this->normalizeContent((string)$path);
}
}

file_put_contents((string)$file, join("\n", $lines));
private function normalizeContent(string $filename)
{
$lines = file($filename);
foreach ($lines as &$line) {
$line = rtrim($line, "\n\r ");
unset($line);
}

file_put_contents($filename, join("\n", $lines));
}
}

Expand Down Expand Up @@ -193,4 +204,5 @@ $codeStyleApp->addCommands([
return $exitCode;
}),
]);

$codeStyleApp->run();

0 comments on commit b5af28d

Please sign in to comment.