Skip to content

Commit

Permalink
Add gen copyright code tool
Browse files Browse the repository at this point in the history
  • Loading branch information
sy-records committed Nov 27, 2023
1 parent 17f838a commit 47d5ad7
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions bin/copyright-code
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env php
<?php

include 'vendor/autoload.php';

use Symfony\Component\Finder\Finder;

$files = Finder::create()
->in(dirname(__DIR__))
->exclude(['bin', 'docs', 'tests', 'examples'])
->ignoreDotFiles(true)
->ignoreVCSIgnored(true)
->notName(['test.php', 'code.txt'])
->name('*.php')
->sortByName()
->files();

file_put_contents('code.txt', '');

foreach ($files as $file) {
file_put_contents('code.txt', removeCommentsAndEmptyLines($file), FILE_APPEND);
}

function removeCommentsAndEmptyLines($filePath)
{
$cleanCode = '';
$fileLines = file($filePath);

foreach ($fileLines as $line) {
$trimmedLine = trim($line);

// Skip comment lines
if (strpos($trimmedLine, '//') === 0 || strpos($trimmedLine, '/*') === 0 || strpos(
$trimmedLine,
'*'
) === 0 || strpos($trimmedLine, '*/') === 0) {
continue;
}

// Skip empty lines
if ($trimmedLine !== '') {
$cleanCode .= $line;
}
}

return $cleanCode;
}

0 comments on commit 47d5ad7

Please sign in to comment.