-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
161 lines (146 loc) · 5.04 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<!doctype html>
<html lang="en-us">
<head>
<meta charset="utf-8">
<title>Phan in Browser</title>
<script src="//ajaxorg.github.io/ace-builds/src-min/ace.js" type="text/javascript" charset="utf-8"></script>
<link rel="stylesheet" type="text/css" href="static/demo.css" />
<link rel="shortcut icon" href="favicon.ico" />
</head>
<body>
<div class="playground">
<div class="site-header">
<h1>Phan in Browser</h1>
<em>(Uses <a href="https://github.com/phan/phan">Phan</a> 2.4.1 and PHP 7.4.0RC5. Best viewed in firefox/chrome)</em>
</div>
<div class="playground-header">
<div class="editor-buttons">
<div class="button-wrapper">
<button id="analyze" title="Analyze PHP Code with Phan" class="disabled" disabled="disabled">Loading...</button>
</div>
<div class="button-wrapper">
<button id="run" title="Run PHP Code" class="disabled" disabled="disabled">Loading...</button>
</div>
</div>
</div>
<div class="playground-split-vertical">
<div class="playground-editor">
<div id="editor"></div>
</div>
<pre id="output"></pre>
</div>
</div>
<a href="https://github.com/phan/demo"><img style="z-index: 1;position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_red_aa0000.png" alt="Fork me on GitHub"></a>
<!-- TODO: move this into a generated JS file -->
<textarea style="display:none;" id="phan_runner_source">
use Phan\Config;
use Phan\Issue;
use Phan\IssueInstance;
use Phan\Output\HTML;
use Phan\Output\IssuePrinterInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Phan\CLI;
use Phan\Phan;
error_reporting(E_ALL);
ini_set('display_errors', 'stderr');
try {
$phar_path = 'phan-2.4.1.phar';
if (!file_exists($phar_path)) {
fwrite(STDERR, "Could not load '$phar_path' - this may not have been included when generating this site with emscripten\n");
exit(1);
}
$phar = "phar://$phar_path";
gc_disable();
$data = require($phar . '/src/Phan/Language/Internal/ClassDocumentationMap.php');
require_once($phar . '/src/requirements.php');
$code_base = require_once($phar . '/src/codebase.php');
require_once($phar . '/src/Phan/Bootstrap.php');
file_put_contents('input', $CONTENTS_TO_ANALYZE);
Config::setValue('file_list', ['input']);
// These plugins are what you'd see with --init-level=2
Config::setValue('plugins', [
'AlwaysReturnPlugin',
'DollarDollarPlugin',
'DuplicateArrayKeyPlugin',
'DuplicateExpressionPlugin',
'PregRegexCheckerPlugin',
'PrintfCheckerPlugin',
'SleepCheckerPlugin',
'UnreachableCodePlugin',
'UseReturnValuePlugin',
'EmptyStatementListPlugin',
'StrictComparisonPlugin',
'LoopVariableReusePlugin',
]);
// This is stricter, though.
Config::setValue('plugin_config', [
'infer_pure_methods' => true,
]);
$cli = CLI::fromRawValues([
'output-mode' => 'html',
'allow-polyfill-parser' => false,
'use-fallback-parser' => false,
'redundant-condition-detection' => false,
'dead-code-detection' => false,
'no-progress-bar' => false,
], []);
// Analyze the file list provided via the CLI
$is_issue_found = Phan::analyzeFileList(
$code_base,
function (bool $recompute_file_list = false) use ($cli) : array {
return $cli->getFileList();
}
);
} catch (\Throwable $e) {
echo "Caught $e\n";
}
</textarea>
<textarea style="display:none;" id="eval_wrapper_source">
function demo_error_handler(int $errno, string $errstr, string $errfile, int $errline) : bool {
fwrite(STDERR, "$errfile:$errline [$errno] $errstr\n");
ob_start();
debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
fwrite(STDERR, ob_get_clean());
return false;
}
try {
error_reporting(E_ALL);
ini_set("display_errors", "stderr");
set_error_handler('demo_error_handler');
eval($CONTENTS_TO_ANALYZE);
} catch (Throwable $e) {
fwrite(STDERR, "Caught " . $e);
}
</textarea>
<textarea style="display:none" id="features_example">
function demo($param, $arg) : ?int {
// Phan can infer types, detect missing elements,
// and detect incorrect calls.
global $argc;
var_export(new my_class());
$cond = $param > 5;
if (!($arg instanceof SplObjectStorage)) { return $argc; }
$arg->attach($cond);
$arg->atach(new stdClass());
$arg->attach(
new MyClass($argc),
[],
'extra'
);
// Phan can detect redundant/impossible conditions
// and unused variables.
$always_true = is_bool($cond);
echo "Missing variable is $argv\n";
return $arg;
}
class MyClass {
public function __construct(string $x = null) {
// and detect undeclared properties, etc.
$this->x = $x;
}
}
demo(2, new SplObjectStorage());</textarea>
<script type="text/javascript" src="php.js"></script>
<script type="text/javascript" src="static/demo.js"></script>
</body>
</html>