public static function toplinks($p = array('min_linkbacks' => 10, 'count' => 5)) { $analysis = new Analysis(); $p = $analysis->addCustomerKey($p); // support for multi params if (isset($p['influencers'])) { $p['influencers'] = is_array($p['influencers']) ? implode(',', $p['influencers']) : $p['influencers']; } if (isset($p['tags'])) { $p['tags'] = is_array($p['tags']) ? implode(',', $p['tags']) : $p['tags']; } return $analysis->get(TraackrApi::$apiBaseUrl . 'analysis/toplinks', $p); }
function importSrc($d, $cov = false) { global $IGNORE; foreach ($IGNORE as $idx => $domain) { if ($domain == $d) { return ""; } } array_push($IGNORE, $d); $ccnt = Analysis::get_src_cnt($d, $cov); return preg_replace("/\\/\\/\\/import\\s+([\\w\\-\$]+(\\.[\\w\\-\$]+)*);?/ies", "importSrc('\\1')", $ccnt['c']); }
/** * Shared implementation for parseFile() & parseContents(). * * @param array $tokens The result of a token_get_all() * @param Context $parseContext * @return Analysis */ protected function fromTokens($tokens, $parseContext) { $analyser = new Analyser(); $analysis = new Analysis(); reset($tokens); $token = ''; $imports = ['swg' => 'Swagger\\Annotations']; // Use @SWG\* for swagger annotations (unless overwritten by a use statement) $parseContext->uses = []; $classContext = $parseContext; // Use the parseContext until a classContext is created. $classDefinition = false; $comment = false; $line = 0; $lineOffset = $parseContext->line ?: 0; while ($token !== false) { $previousToken = $token; $token = $this->nextToken($tokens, $parseContext); if (is_array($token) === false) { // Ignore tokens like "{", "}", etc continue; } if ($token[0] === T_DOC_COMMENT) { if ($comment) { // 2 Doc-comments in succession? $analysis->addAnnotations($analyser->fromComment($comment, new Context(['line' => $line], $classContext))); } $comment = $token[1]; $line = $token[2] + $lineOffset; continue; } if ($token[0] === T_ABSTRACT) { $token = $this->nextToken($tokens, $parseContext); // Skip "abstract" keyword } if ($token[0] === T_CLASS) { // Doc-comment before a class? if (is_array($previousToken) && $previousToken[0] === T_DOUBLE_COLON) { //php 5.5 class name resolution (i.e. ClassName::class) continue; } $token = $this->nextToken($tokens, $parseContext); $classContext = new Context(['class' => $token[1], 'line' => $token[2]], $parseContext); if ($classDefinition) { $analysis->addClassDefinition($classDefinition); } $classDefinition = ['class' => $token[1], 'extends' => null, 'properties' => [], 'methods' => [], 'context' => $classContext]; // @todo detect end-of-class and reset $classContext $token = $this->nextToken($tokens, $parseContext); if ($token[0] === T_EXTENDS) { $classContext->extends = $this->parseNamespace($tokens, $token, $parseContext); $classDefinition['extends'] = $classContext->fullyQualifiedName($classContext->extends); } if ($comment) { $classContext->line = $line; $analysis->addAnnotations($analyser->fromComment($comment, $classContext)); $comment = false; continue; } } if ($token[0] == T_STATIC) { $token = $this->nextToken($tokens, $parseContext); if ($token[0] === T_VARIABLE) { // static property $propertyContext = new Context(['property' => substr($token[1], 1), 'static' => true, 'line' => $line], $classContext); if ($classDefinition) { $classDefinition['properties'][$propertyContext->property] = $propertyContext; } if ($comment) { $analysis->addAnnotations($analyser->fromComment($comment, $propertyContext)); $comment = false; } continue; } } if (in_array($token[0], [T_PRIVATE, T_PROTECTED, T_PUBLIC, T_VAR])) { // Scope $token = $this->nextToken($tokens, $parseContext); if ($token[0] == T_STATIC) { $token = $this->nextToken($tokens, $parseContext); } if ($token[0] === T_VARIABLE) { // instance property $propertyContext = new Context(['property' => substr($token[1], 1), 'line' => $line], $classContext); if ($classDefinition) { $classDefinition['properties'][$propertyContext->property] = $propertyContext; } if ($comment) { $analysis->addAnnotations($analyser->fromComment($comment, $propertyContext)); $comment = false; } } elseif ($token[0] === T_FUNCTION) { $token = $this->nextToken($tokens, $parseContext); if ($token[0] === T_STRING) { $methodContext = new Context(['method' => $token[1], 'line' => $line], $classContext); if ($classDefinition) { $classDefinition['methods'][$token[1]] = $methodContext; } if ($comment) { $analysis->addAnnotations($analyser->fromComment($comment, $methodContext)); $comment = false; } } } continue; } elseif ($token[0] === T_FUNCTION) { $token = $this->nextToken($tokens, $parseContext); if ($token[0] === T_STRING) { $methodContext = new Context(['method' => $token[1], 'line' => $line], $classContext); if ($classDefinition) { $classDefinition['methods'][$token[1]] = $methodContext; } if ($comment) { $analysis->addAnnotations($analyser->fromComment($comment, $methodContext)); $comment = false; } } } if (in_array($token[0], [T_NAMESPACE, T_USE]) === false) { // Skip "use" & "namespace" to prevent "never imported" warnings) // Not a doc-comment for a class, property or method? if ($comment) { $analysis->addAnnotations($analyser->fromComment($comment, new Context(['line' => $line], $classContext))); $comment = false; } } if ($token[0] === T_NAMESPACE) { $parseContext->namespace = $this->parseNamespace($tokens, $token, $parseContext); continue; } if ($token[0] === T_USE) { $statements = $this->parseUseStatement($tokens, $token, $parseContext); foreach ($statements as $alias => $target) { if ($target[0] === '\\') { $target = substr($target, 1); } $parseContext->uses[$alias] = $target; foreach (Analyser::$whitelist as $namespace) { if (strcasecmp(substr($target, 0, strlen($namespace)), $namespace) === 0) { $imports[strtolower($alias)] = $target; break; } } } $analyser->docParser->setImports($imports); continue; } } if ($comment) { // File ends with a T_DOC_COMMENT $analysis->addAnnotations($analyser->fromComment($comment, new Context(['line' => $line], $classContext))); } if ($classDefinition) { $analysis->addClassDefinition($classDefinition); } return $analysis; }
private function analysisDelete() { $identity = \Yii::$app->user->getIdentity(); $currentTs = time(); $deleted = 0; $arrIds = \Yii::$app->request->post('idCheck', NULL); if (empty($arrIds)) { $arrIds = \Yii::$app->request->get('idCheck', NULL); } if (is_array($arrIds) && !empty($arrIds)) { foreach ($arrIds as $lst) { $queryUser = Analysis::find(); $Food = $queryUser->where(['id' => $lst])->one()->delete(); $deleted = $deleted + 1; } if ($deleted > 0) { Ui::setMessage("ลบข้อมูลจำนวน {$deleted} รายการ" + "บันทึกข้อมูลสำเร็จ"); } else { Ui::setMessage('ไม่มีข้อมูลถูกลบ'); } } }
/** * Analyze the given set of files and emit any issues * found to STDOUT. * * @param CodeBase $code_base * A code base needs to be passed in because we require * it to be initialized before any classes or files are * loaded. * * @param string[] $file_path_list * A list of files to scan * * @return null * We emit messages to STDOUT. Nothing is returned. * * @see \Phan\CodeBase */ public static function analyzeFileList(CodeBase $code_base, array $file_path_list) { $file_count = count($file_path_list); // We'll construct a set of files that we'll // want to run an analysis on $analyze_file_path_list = []; // This first pass parses code and populates the // global state we'll need for doing a second // analysis after. foreach ($file_path_list as $i => $file_path) { CLI::progress('parse', ($i + 1) / $file_count); // Check to see if we need to re-parse this file either // because we don't have an up to date parse for this // file or because we were isntructed to reanalyze // everything if (!$code_base->isParseUpToDateForFile($file_path) || Config::get()->reanalyze_file_list) { // Kick out anything we read from the former version // of this file $code_base->flushDependenciesForFile($file_path); // If the file is gone, no need to continue if (!file_exists($file_path)) { continue; } try { // Parse the file Analysis::parseFile($code_base, $file_path); // Update the timestamp on when it was last // parsed $code_base->setParseUpToDateForFile($file_path); // Save this to the set of files to analyze $analyze_file_path_list[] = $file_path; } catch (\Throwable $throwable) { error_log($file_path . ' ' . $throwable->getMessage() . "\n"); } } } // Don't continue on to analysis if the user has // chosen to just dump the AST if (Config::get()->dump_ast) { exit; } // Take a pass over all classes verifying various // states now that we have the whole state in // memory Analysis::analyzeClasses($code_base); // Take a pass over all functions verifying // various states now that we have the whole // state in memory Analysis::analyzeFunctions($code_base); // We can only save classes, methods, properties and // constants after we've merged parent classes in. $code_base->store(); // Once we know what the universe looks like we // can scan for more complicated issues. $file_count = count($analyze_file_path_list); foreach ($analyze_file_path_list as $i => $file_path) { CLI::progress('analyze', ($i + 1) / $file_count); // We skip anything defined as 3rd party code // to save a lil' time if (self::isExcludedAnalysisFile($file_path)) { continue; } // Analyze the file Analysis::analyzeFile($code_base, $file_path); } // Scan through all globally accessible elements // in the code base and emit errors for dead // code. Analysis::analyzeDeadCode($code_base); // Emit all log messages Log::display(); }
/** * * @param Analysis $analysis * @param Analyser $analyser * @param string $comment * @param Context $context */ private function analyseComment($analysis, $analyser, $comment, $context) { $analysis->addAnnotations($analyser->fromComment($comment, $context), $context); }
* path: import.php * author: berg * version: 1.0 * date: 2010/07/18 23:57:52 * * @fileoverview * import.js的php版本 * 接受一个f参数,格式和import.js相同,自动合并js并输出 * 此外,本脚本支持引入一个包所有文件(其实也就是一个目录下的所有js文件,**不递归**) * IE下,get请求不能超过2083字节,请注意。 */ $cov = array_key_exists('cov', $_GET) ? $_GET['cov'] : false; $f = explode(',', $_GET['f']); //explode() 函数把字符串分割为数组,此处$f=baidu.ajax.form $e = array_key_exists('e', $_GET) && $_GET['e'] != '' ? explode(",", $_GET['e']) : array(); require_once dirname(__FILE__) . '/analysis.php'; $analysis = new Analysis(); $IGNORE = array(); foreach ($e as $d) { $d = preg_replace('/\\s*/', '', $d) . '.js'; //jiangshuguang修改 if (ConfigTest::$DEBUG) { var_dump($d); } $IGNORE = array_merge($IGNORE, array_keys($analysis->get_import_srcs($d))); } if (ConfigTest::$DEBUG) { var_dump($IGNORE); } function importSrc($d, $cov = false) { global $IGNORE;