| Conditions | 14 |
| Paths | 98 |
| Total Lines | 73 |
| Code Lines | 50 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 210 |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 39 | public function output(App $app, Response $response, array $log = []) |
||
| 40 | { |
||
| 41 | $request = $app->request; |
||
| 42 | $contentType = $response->getHeader('Content-Type'); |
||
| 43 | $accept = $request->header('accept'); |
||
| 44 | if (strpos($accept, 'application/json') === 0 || $request->isAjax()) { |
||
| 45 | return false; |
||
| 46 | } elseif (!empty($contentType) && strpos($contentType, 'html') === false) { |
||
| 47 | return false; |
||
| 48 | } |
||
| 49 | // 获取基本信息 |
||
| 50 | $runtime = number_format(microtime(true) - $app->getBeginTime(), 10); |
||
| 51 | $reqs = $runtime > 0 ? number_format(1 / $runtime, 2) : '∞'; |
||
| 52 | $mem = number_format((memory_get_usage() - $app->getBeginMem()) / 1024, 2); |
||
| 53 | |||
| 54 | if ($request->host()) { |
||
| 55 | $uri = $request->protocol() . ' ' . $request->method() . ' : ' . $request->url(true); |
||
| 56 | } else { |
||
| 57 | $uri = 'cmd:' . implode(' ', $_SERVER['argv']); |
||
| 58 | } |
||
| 59 | |||
| 60 | // 页面Trace信息 |
||
| 61 | $base = [ |
||
| 62 | '请求信息' => date('Y-m-d H:i:s', $request->time()) . ' ' . $uri, |
||
| 63 | '运行时间' => number_format((float) $runtime, 6) . 's [ 吞吐率:' . $reqs . 'req/s ] 内存消耗:' . $mem . 'kb 文件加载:' . count(get_included_files()), |
||
| 64 | '查询信息' => $app->db->getQueryTimes() . ' queries', |
||
| 65 | '缓存信息' => $app->cache->getReadTimes() . ' reads,' . $app->cache->getWriteTimes() . ' writes', |
||
| 66 | ]; |
||
| 67 | |||
| 68 | if ($app->session->getId(false)) { |
||
| 69 | $base['会话信息'] = 'SESSION_ID=' . $app->session->getId(); |
||
| 70 | } |
||
| 71 | |||
| 72 | $info = $this->getFileInfo(); |
||
| 73 | |||
| 74 | // 页面Trace信息 |
||
| 75 | $trace = []; |
||
| 76 | foreach ($this->config['tabs'] as $name => $title) { |
||
| 77 | $name = strtolower($name); |
||
| 78 | switch ($name) { |
||
| 79 | case 'base': // 基本信息 |
||
|
1 ignored issue
–
show
|
|||
| 80 | $trace[$title] = $base; |
||
| 81 | break; |
||
| 82 | case 'file': // 文件信息 |
||
|
1 ignored issue
–
show
|
|||
| 83 | $trace[$title] = $info; |
||
| 84 | break; |
||
| 85 | default: // 调试信息 |
||
|
1 ignored issue
–
show
|
|||
| 86 | if (strpos($name, '|')) { |
||
|
1 ignored issue
–
show
|
|||
| 87 | // 多组信息 |
||
| 88 | $names = explode('|', $name); |
||
| 89 | $result = []; |
||
| 90 | foreach ($names as $item) { |
||
|
1 ignored issue
–
show
|
|||
| 91 | $result = array_merge($result, $log[$item] ?? []); |
||
| 92 | } |
||
|
1 ignored issue
–
show
|
|||
| 93 | $trace[$title] = $result; |
||
| 94 | } else { |
||
|
1 ignored issue
–
show
|
|||
| 95 | $trace[$title] = $log[$name] ?? ''; |
||
| 96 | } |
||
|
1 ignored issue
–
show
|
|||
| 97 | } |
||
| 98 | } |
||
| 99 | |||
| 100 | //输出到控制台 |
||
| 101 | $lines = ''; |
||
| 102 | foreach ($trace as $type => $msg) { |
||
| 103 | $lines .= $this->console($type, $msg); |
||
| 104 | } |
||
| 105 | $js = <<<JS |
||
| 106 | |||
| 107 | <script type='text/javascript'> |
||
| 108 | {$lines} |
||
| 109 | </script> |
||
| 110 | JS; |
||
| 111 | return $js; |
||
| 112 | } |
||
| 171 |