使用 Checkstyle 报告可视化 PHP 代码(来自 CodeSniffer)

发布于 2024-10-19 09:10:14 字数 343 浏览 6 评论 0原文

PHP CodeSniffer是一个非常好的工具,可以帮助我们检查我们的PHP源代码。但 CodeSniffer 的报告并不容易阅读。

我发现 CodeSniffer 可以输出“Checkstyle”xml 报告。有没有办法用 Checkstyle xml 报告可视化 PHP 代码,以便每个开发人员都可以在一页中阅读代码和报告?

事实上,我发现了一个名为 phpUnderControl 的工具,它看起来是一个非常好的持续集成工具,里面的东西可以满足我的要求。但我没有计划更改我的持续集成工具(我正在使用 Apache Continuum)。

所以如果有人能告诉我一个简单的工具或插件,那就最好了。

谢谢。

PHP CodeSniffer is a very good tool to help us check our PHP source code. But the report from CodeSniffer is not easy to read.

I found that CodeSniffer can output 'Checkstyle' xml report. Is that any way to Visualize PHP code with Checkstyle xml report, so that every developer can read code and report in one page?

In fact, I found a tool named phpUnderControl, which looks like a very good Continuous Integration tool and something inside it could cover my requirement. But I have no plan to change my Continuous Integration tool (I'm using Apache Continuum).

So if anyone can tell me a simple tool or plug-in, that would be the best.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

衣神在巴黎 2024-10-26 09:10:14

这实际上更像是一个评论/问题,但SO认为它太长了,所以我将其表述为答案:

假设您想要像这样输出:

$ phpcs --report=checkstyle /path/to/code

<?xml version="1.0" encoding="UTF-8"?>
<checkstyle version="1.0.0">
 <file name="/path/to/code/myfile.php">
  <error line="2" column="1" severity="error" message="Missing file doc comment" source="PEAR.Commenting.FileComment"/>
  <error line="20" column="43" severity="error" message="PHP keywords must be lowercase; expected "false" but found "FALSE"" source="Generic.PHP.LowerCaseConstant"/>
  <error line="47" column="1" severity="error" message="Line not indented correctly; expected 4 spaces but found 1" source="PEAR.WhiteSpace.ScopeIndent"/>
  <error line="47" column="20" severity="warning" message="Equals sign not aligned with surrounding assignments" source="Generic.Formatting.MultipleStatementAlignment"/>
  <error line="51" column="4" severity="error" message="Missing function doc comment" source="PEAR.Commenting.FunctionComment"/>
 </file>
</checkstyle>

并渲染原始源代码的版本,并突出显示指示的部分不知何故,那么我认为你将不得不“自己动手”。

您必须编写一个脚本,将代码存储库中源文件的路径作为输入参数(例如 path/to/code),并将一大块“checkstyle”XML 作为输入(通过 STDIN),并呈现文件内容(到 STDOUT)作为 HTML 标记。

内部文件的主体应该位于 PRE 元素中(以保留格式),并且带有指向错误/警告“列表元素”的 HREF 链接的每个指定行 + 列将位于 HTML 页面的底部(我不是确定什么样的附加颜色/突出显示可以在 PRE 元素内工作)。

这是一个好主意 - 我想自己拥有这样一个脚本/工具/实用程序!如果我有时间写一篇文章,我承诺将其发布到 Github 上并在此处添加链接。

如果您找到/写了一个,请回答您自己的问题,好吗?

This is really more of a comment/question, but SO thinks it is too long so I'll phrase it as an answer:

Assuming you want to take output like this:

$ phpcs --report=checkstyle /path/to/code

<?xml version="1.0" encoding="UTF-8"?>
<checkstyle version="1.0.0">
 <file name="/path/to/code/myfile.php">
  <error line="2" column="1" severity="error" message="Missing file doc comment" source="PEAR.Commenting.FileComment"/>
  <error line="20" column="43" severity="error" message="PHP keywords must be lowercase; expected "false" but found "FALSE"" source="Generic.PHP.LowerCaseConstant"/>
  <error line="47" column="1" severity="error" message="Line not indented correctly; expected 4 spaces but found 1" source="PEAR.WhiteSpace.ScopeIndent"/>
  <error line="47" column="20" severity="warning" message="Equals sign not aligned with surrounding assignments" source="Generic.Formatting.MultipleStatementAlignment"/>
  <error line="51" column="4" severity="error" message="Missing function doc comment" source="PEAR.Commenting.FunctionComment"/>
 </file>
</checkstyle>

and render a version of the original source code with the indicated sections highlighted somehow, then I think you're going to have "to roll your own".

You'd have to write a script which takes the path to a source file in your code repository as an input parameter (e.g. path/to/code) and a chunk of "checkstyle" XML as input (via STDIN), and renders the contents of the file (to STDOUT) as HTML markup.

The body of the file inside should be in a PRE element (to preserve formatting) and each specified line + column with an HREF link to an error/warning "list element" would be at the bottom of the HTML page (I'm not sure what kind of addition color/highlighting can work inside a PRE element).

This is a good idea - I would like to have such a script/tool/utility myself! If I ever get around to writing one I promise to publish it on Github and add a link to it here.

And if you ever find/write one, PLEASE answer your own question, OK?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文