Phan\CodeBase::exportFunctionAndMethodSet PHP Method

exportFunctionAndMethodSet() public method

public exportFunctionAndMethodSet ( ) : array
return array - A human readable encoding of $this->func_and_method_set [string $filename => [int|string $pos => string $spec]] Excludes internal functions and methods.
    public function exportFunctionAndMethodSet() : array
    {
        $result = [];
        foreach ($this->func_and_method_set as $function_or_method) {
            if ($function_or_method->isInternal()) {
                continue;
            }
            $fqsen = $function_or_method->getFQSEN();
            $function_or_method_name = (string) $fqsen;
            $signature = [(string) $function_or_method->getUnionType()];
            foreach ($function_or_method->getParameterList() as $param) {
                $name = $param->getName();
                $paramType = (string) $param->getUnionType();
                if ($param->isVariadic()) {
                    $name = '...' . $name;
                }
                if ($param->isPassByReference()) {
                    $name = '&' . $name;
                }
                if ($param->isOptional()) {
                    $name = $name . '=';
                }
                $signature[$name] = $paramType;
            }
            $result[$function_or_method_name] = $signature;
        }
        ksort($result);
        return $result;
    }

Usage Example

Example #1
0
File: Phan.php Project: etsy/phan
 /**
  * Save json encoded function&method signature to a map.
  * @return int - Exit code for process
  */
 private static function dumpSignaturesToFile(CodeBase $code_base, string $filename) : int
 {
     $encoded_signatures = json_encode($code_base->exportFunctionAndMethodSet(), JSON_PRETTY_PRINT);
     if (!file_put_contents($filename, $encoded_signatures)) {
         error_log(sprintf("Could not save contents to path '%s'\n", $filename));
         return EXIT_FAILURE;
     }
     return EXIT_SUCCESS;
 }