1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
<?php
$excludedFiles = [
'CommandApplication.php',
'UpdateCommand.php',
];
$failedFiles = [];
$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;
}
$iterator = new \RecursiveDirectoryIterator(
$libDir,
\RecursiveDirectoryIterator::SKIP_DOTS
);
/**
* @var string $path
* @var SplFileInfo $fileInfo
*/
foreach ($iterator as $path => $fileInfo) {
$fileName = explode($libDir, $path)[1];
if(array_search($fileName, $excludedFiles) !== false) {
continue;
}
$fileContent = file_get_contents($path);
$fileContent = explode("namespace NC\\Updater;\n", $fileContent, 2)[1];
$fileContent = trim($fileContent);
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);
}
echo "Code is the same" . PHP_EOL;
|