diff options
author | Git'Fellow <carlos@reendex.com> | 2022-08-20 20:36:22 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-20 20:36:22 +0300 |
commit | c21fbf269f519a71528db994476421afa480f378 (patch) | |
tree | 078537f6fc63d774c03ceeaa6da9860393df22f0 /tests/checkSameCodeBase.php | |
parent | 0de81a2395ba6e08abf2a21f7e98eda8f592fcf2 (diff) | |
parent | 922f0792b15cce73797e7213579e00c6ddd47a97 (diff) |
Merge branch 'master' into updateDir
Signed-off-by: Git'Fellow <carlos@reendex.com>
Diffstat (limited to 'tests/checkSameCodeBase.php')
-rw-r--r-- | tests/checkSameCodeBase.php | 95 |
1 files changed, 47 insertions, 48 deletions
diff --git a/tests/checkSameCodeBase.php b/tests/checkSameCodeBase.php index 7fd95cc..0f8f4c4 100644 --- a/tests/checkSameCodeBase.php +++ b/tests/checkSameCodeBase.php @@ -11,69 +11,68 @@ $libDir = __DIR__ . '/../lib/'; $indexPhpContent = file_get_contents(__DIR__ . '/../index.php'); function findDiffPos($original, $copy) { - $lowerLimit = 0; - $upperLimit = strlen($copy) - 1; - - do { - $index = $lowerLimit + round(($upperLimit - $lowerLimit)/2); - - $partOfCopy = substr($copy, 0, $index); - if(strpos($original, $partOfCopy) === false) { - $upperLimit = $index; - } else { - $lowerLimit = $index; - } - } while ($upperLimit - $lowerLimit > 5); - - $matchingSubstring = substr($copy, 0, $lowerLimit); - if(strlen($matchingSubstring) <= 20) { - $originalStart = 0; - $copyStart = 0; - } else { - $originalStart = strpos($original, $matchingSubstring) + strlen($matchingSubstring) - 20; - $copyStart = strlen($matchingSubstring) - 20; - } - $stringOriginal = substr($original, $originalStart, 40); - $stringCopy = substr($copy, $copyStart, 40); - - echo "diff is in here: (between character $lowerLimit and $upperLimit):" . PHP_EOL; - echo '...' . $stringOriginal . '...' . PHP_EOL; - echo '...' . $stringCopy . '...' . PHP_EOL; + $lowerLimit = 0; + $upperLimit = strlen($copy) - 1; + + do { + $index = $lowerLimit + round(($upperLimit - $lowerLimit) / 2); + + $partOfCopy = substr($copy, 0, $index); + if (strpos($original, $partOfCopy) === false) { + $upperLimit = $index; + } else { + $lowerLimit = $index; + } + } while ($upperLimit - $lowerLimit > 5); + + $matchingSubstring = substr($copy, 0, $lowerLimit); + if (strlen($matchingSubstring) <= 20) { + $originalStart = 0; + $copyStart = 0; + } else { + $originalStart = strpos($original, $matchingSubstring) + strlen($matchingSubstring) - 20; + $copyStart = strlen($matchingSubstring) - 20; + } + $stringOriginal = substr($original, $originalStart, 40); + $stringCopy = substr($copy, $copyStart, 40); + + echo "diff is in here: (between character $lowerLimit and $upperLimit):" . PHP_EOL; + echo '...' . $stringOriginal . '...' . PHP_EOL; + echo '...' . $stringCopy . '...' . PHP_EOL; } $iterator = new \RecursiveDirectoryIterator( - $libDir, - \RecursiveDirectoryIterator::SKIP_DOTS + $libDir, + \RecursiveDirectoryIterator::SKIP_DOTS ); /** * @var string $path * @var SplFileInfo $fileInfo */ foreach ($iterator as $path => $fileInfo) { - $fileName = explode($libDir, $path)[1]; + $fileName = explode($libDir, $path)[1]; - if(array_search($fileName, $excludedFiles) !== false) { - continue; - } + if (array_search($fileName, $excludedFiles) !== false) { + continue; + } - $fileContent = file_get_contents($path); + $fileContent = file_get_contents($path); - $fileContent = explode("namespace NC\\Updater;\n", $fileContent, 2)[1]; + $fileContent = explode("namespace NC\\Updater;\n", $fileContent, 2)[1]; - $fileContent = trim($fileContent); + $fileContent = trim($fileContent); - if(strpos($indexPhpContent, $fileContent) === false) { - - $failedFiles[] = $fileName; - echo "$fileName" . PHP_EOL . PHP_EOL; - findDiffPos($indexPhpContent, $fileContent); - echo PHP_EOL; - } + if (strpos($indexPhpContent, $fileContent) === false) { + $failedFiles[] = $fileName; + echo "$fileName" . PHP_EOL . PHP_EOL; + findDiffPos($indexPhpContent, $fileContent); + echo PHP_EOL; + } } -if($failedFiles !== []) { - echo "Code is not the same" . PHP_EOL; - exit(1); +if ($failedFiles !== []) { + echo "Code is not the same" . PHP_EOL; + exit(1); } -echo "Code is the same" . PHP_EOL;
\ No newline at end of file +echo "Code is the same" . PHP_EOL; |