- var_dump: documentation ( source)
- get_defined_functions: documentation ( source)
- levenshtein: documentation ( source)
- array_merge: documentation ( source)
- shuffle: documentation ( source)
<?php
final class Approximator
{
public static $wtfThreshold = 7;
public static function __callStatic($name, $arguments)
{
$proximityMap = self::getProximityMap($name);
for ($proximity = 0; $proximity <= (int) self::$wtfThreshold; $proximity++) {
if (isset($proximityMap[$proximity][0])) {
shuffle($proximityMap[$proximity]);
return call_user_func_array($proximityMap[$proximity][0], $arguments);
}
}
throw new Exception('Sorry, I-a don\'t understoond whet yooo meoont. Bork Bork Bork!');
}
private static function getProximityMap($called)
{
$proximityMap = [];
$definedMap = get_defined_functions();
foreach (array_merge($definedMap['internal'], $definedMap['user']) as $defined) {
$proximityMap[levenshtein($called, $defined)][] = $defined;
}
return $proximityMap;
}
}
var_dump(Approximator::strtoupper('noodles'));