Exemple #1
0
function indent_line($line, $numline, $indent, $indent_tokens, $token, $list_tokens, $function_info, $list_token, $lista_functions, $lista_function_names, $stati)
{
    // insert a space before open braces
    $line = preg_replace('/([^[:space:]]){/', "\\1 {", $line);
    $mc_inc = 0;
    // by default each line doesn't increment the McCabe cyclomatic complexity counter
    $list_inc0 = $indent_tokens['list_inc0'];
    $list_mid0 = $indent_tokens['list_mid0'];
    $list_dec0 = $indent_tokens['list_dec0'];
    $list_inc = $indent_tokens['list_inc'];
    $list_mid = $indent_tokens['list_mid'];
    $list_dec = $indent_tokens['list_dec'];
    $token_next = array();
    $indent_next = 0;
    // if indent counter is zero (top level), and I find a }, it means that the current function closes here
    if ($indent == 0 && $line === '} ') {
        $close_function = true;
    } else {
        $close_function = false;
    }
    // a 'do' structure was just closed --> request the substitution of 'while' with 'while_do'
    if (array_key_exists('subst_line', $stati) && !empty($stati['subst_line'])) {
        $line = preg_replace('/' . $stati['subst_line'][0] . '/', $stati['subst_line'][1], $line);
        $stati['line_modified'] = $line;
        $stati['subst_line'] = array();
    } else {
        // a new complex instruction starts?
        for ($i_inc = 0; $i_inc < count($list_inc0); $i_inc++) {
            if (preg_match('/^' . $list_inc0[$i_inc] . '[^[:alnum:]]?/', $line)) {
                $token_next['inc'] = $list_inc0[$i_inc];
                $token_next['mid'] = $list_mid0[$i_inc];
                $token_next['dec'] = $list_dec0[$i_inc];
                $indent_next = 1;
                break;
            }
            // end if
        }
        // end for
        if (array_key_exists('dec', $token)) {
            // if you're inside a complex instruction, delimited by braces, for which closing tags exist
            // (ex. '}', and other intermediate (ex. 'else', 'elseif')...
            // var_dump($token);echo "<br>"; // !!!
            // stampa("1($indent,$indent_next)"); // !!!
            // search intermediate token (ex. else)
            $temp_result = manage_mid_token($line, $token, $indent, $indent_next);
            $indent = $temp_result[0];
            $indent_next = $temp_result[1];
            // stampa("2($indent,$indent_next)"); // !!!
            // search closing token (ex. })
            $temp_result = manage_dec_token($line, $numline, $token, $list_token, $indent, $indent_next, $function_info, $stati);
            $indent = $temp_result[0];
            $indent_next = $temp_result[1];
            $token = $temp_result[2];
            $list_token = $temp_result[3];
            $function_info = $temp_result[4];
            $stati = $temp_result[5];
            // var_dump($token);echo "<br>"; // !!!
            // stampa("3($indent,$indent_next)"); // !!!
        }
        // end if
    }
    // end if
    // end
    // current function finishes, a new starts (included the root function, for scripts not inside function tags)
    if (preg_match('/^(private |public |protected )*function /', $line) || $close_function) {
        // first verify the tokens found in previous function...
        $function_info = function_checks($function_info, $list_tokens);
        array_push($lista_functions, $function_info);
        // ...then start new function
        $function_info = get_function_info($line);
        $list_tokens = array();
        array_push($lista_function_names, $function_info['function']);
    } else {
        // verify whether any of the tokens is an input or output parameter
        preg_match_all('/[[:alnum:]_$]+/', $line, $temp_ereg_result);
        if (empty($line_tokens)) {
            $line_tokens = $temp_ereg_result[0];
        } else {
            $line_tokens = array_merge($line_tokens, $temp_ereg_result[0]);
        }
        $list_tokens = array_unique(array_merge($list_tokens, $line_tokens));
        $mc_inc = lint_check($line, $line_tokens);
        $function_info['mc_count'] = $function_info['mc_count'] + $mc_inc;
    }
    // end if
    // end
    if (array_key_exists('inc', $token_next)) {
        $token = $token_next;
        array_push($list_token, $token_next);
    }
    return array($token, $token_next, $indent, $indent_next, $list_token, $list_tokens, $function_info, $lista_functions, $lista_function_names, $stati, $mc_inc);
}
Exemple #2
0
require_once $dirname . '/docs_method.php';
require_once $dirname . '/docs_method_param.php';
require_once $dirname . '/docs_roperty.php';
if ($file) {
    if (is_file($file)) {
        require_once $file;
    } else {
        echo "指定的文件" . $file . "不存在\n";
        exit;
    }
}
function get_function_info($class_name, $dir_type)
{
    if ($dir_type == 'orm') {
        $arr = array();
        foreach (array('finder', 'data', 'result') as $type) {
            $orm_class_name = $class_name . '_' . $type;
            if (class_exists($orm_class_name)) {
                $class = new _Docs_Class($orm_class_name);
                $arr[$type] = $class->getArrayCopy();
            }
        }
    } else {
        $class = new _Docs_Class($class_name);
        $arr = $class->getArrayCopy();
    }
    echo "ok\n";
    echo serialize($arr);
}
get_function_info($class_name, $dir_type);
Exemple #3
0
#!/usr/bin/env php
<?php 
$args = $_SERVER['argv'];
array_shift($args);
if (count($args) < 3) {
    echo '参数错误';
    exit;
}
define('DIR_MANUAL', realpath(dirname(__FILE__) . '/../../') . '/');
list($ns, $type, $fun) = $args;
$auto_run = false;
include dirname(__FILE__) . '/../../../index.php';
require_once dirname(__FILE__) . '/docs.php';
require_once dirname(__FILE__) . '/docs_method.php';
require_once dirname(__FILE__) . '/docs_method_param.php';
require_once dirname(__FILE__) . '/markdown.php';
require_once dirname(__FILE__) . '/markdown_extra.php';
function get_function_info()
{
    $class_name = 'Database';
    $method_name = 'query';
    $method = new _Docs_Method($class_name, $method_name);
    include DIR_MANUAL . 'tpl/api_method.html';
    $html = ob_get_clean();
}
get_function_info();