forked from coenjacobs/mozart
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add missing built-in PHP interfaces for exclusion
- Loading branch information
1 parent
25db6cd
commit a48ad69
Showing
3 changed files
with
535 additions
and
289 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,3 +17,4 @@ scratch | |
pcov.sh | ||
xdebug.sh | ||
7.4linux.sh | ||
scripts/builtins.php |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
/** | ||
* Get all built-in PHP classes, interfaces, traits. | ||
*/ | ||
|
||
$outputFile = __DIR__ . '/builtins.php'; | ||
|
||
$builtins = file_exists($outputFile) ? require $outputFile : []; | ||
|
||
$currentPhpVersion = implode( | ||
'.', | ||
array_slice( | ||
explode('.', phpversion()), | ||
0, | ||
2 | ||
) | ||
); | ||
|
||
if (!isset($builtins[$currentPhpVersion])) { | ||
$builtins[$currentPhpVersion] = [ | ||
'classes' => [], | ||
'interfaces' => [], | ||
'traits' => [], | ||
]; | ||
} | ||
|
||
$classes = array_filter( | ||
get_declared_classes(), | ||
function (string $className): bool { | ||
$reflector = new \ReflectionClass($className); | ||
return empty($reflector->getFileName()); | ||
} | ||
); | ||
|
||
$interfaces = array_filter( | ||
get_declared_interfaces(), | ||
function (string $interfaceName): bool { | ||
$reflector = new \ReflectionClass($interfaceName); | ||
return empty($reflector->getFileName()); | ||
} | ||
); | ||
|
||
$traits = array_filter( | ||
get_declared_traits(), | ||
function (string $traitName): bool { | ||
$reflector = new \ReflectionClass($traitName); | ||
return empty($reflector->getFileName()); | ||
} | ||
); | ||
|
||
|
||
// Remove classes, interfaces, traits that are built-in in this PHP version from future versions. | ||
foreach ($builtins as $phpVersion => $builtinsArray) { | ||
if (version_compare($phpVersion, $currentPhpVersion, '>')) { | ||
$builtins[$phpVersion]['classes'] = array_diff($builtinsArray['classes'], $classes); | ||
$builtins[$phpVersion]['interfaces'] = array_diff($builtinsArray['interfaces'], $interfaces); | ||
$builtins[$phpVersion]['traits'] = array_diff($builtinsArray['traits'], $traits); | ||
} | ||
} | ||
|
||
// Remove from this PHP version's built-ins list classes, interfaces, traits that exist in older versions. | ||
foreach ($builtins as $phpVersion => $builtinsArray) { | ||
if (version_compare($phpVersion, $currentPhpVersion, '<')) { | ||
$classes = array_diff($classes, $builtinsArray['classes']); | ||
$interfaces = array_diff($interfaces, $builtinsArray['interfaces']); | ||
$traits = array_diff($traits, $builtinsArray['traits']); | ||
} | ||
} | ||
|
||
$builtins[$currentPhpVersion]['classes'] = array_unique(array_merge($builtins[$currentPhpVersion]['classes'], $classes)); | ||
$builtins[$currentPhpVersion]['interfaces'] = array_unique(array_merge($builtins[$currentPhpVersion]['interfaces'], $interfaces)); | ||
$builtins[$currentPhpVersion]['traits'] = array_unique(array_merge($builtins[$currentPhpVersion]['traits'], $traits)); | ||
|
||
foreach ($builtins as $phpVersion => $builtinsArray) { | ||
asort($builtins[$currentPhpVersion]['classes']); | ||
asort($builtins[$currentPhpVersion]['interfaces']); | ||
asort($builtins[$currentPhpVersion]['traits']); | ||
} | ||
|
||
|
||
$outputText = '<?php' . PHP_EOL . 'return ' . var_export($builtins, true) . ';'; | ||
|
||
$outputText = preg_replace('/\d+\s=>\s/', '', $outputText); | ||
|
||
file_put_contents($outputFile, $outputText); |
Oops, something went wrong.