【问题标题】:Unclear Code Sniffer Errors不清楚的代码嗅探器错误
【发布时间】:2016-01-07 02:36:37
【问题描述】:

我已经使用 php 代码跟踪了 html 标记:

<div class="block">
    <div class="block-title">
        <?php if ($user->isOnline()): ?>
            <a href="<?=Url::create('/user/logout');?>">Logout</a>
        <?php endif; ?>
    </div>
</div>

当我运行代码嗅探器时,我收到以下错误:

<error line="3" column="15" severity="error" message="Line indented incorrectly; expected 8 spaces, found 0" source="Generic.WhiteSpace.ScopeIndent.Incorrect"/>
<error line="5" column="15" severity="error" message="Closing brace must be on a line by itself" source="PEAR.WhiteSpace.ScopeClosingBrace.Line"/>

我试图在 html 视图中找到有关 php 构造的任何标准或描述,但没有任何相关内容。

也许,有人知道 html 中的 ifforeach 指令的外观吗?

谢谢。

【问题讨论】:

  • 尝试删除&lt;a href... 行的一个缩进。
  • @VincentDecaux,不,它不起作用。
  • 如果您不在 2.3.4 上,您可能想尝试升级到最新的 PHPCS 版本,因为已经为此类视图代码添加了修复程序,假设您使用的是内置标准像 PSR2 或 PEAR。
  • @GregSherwood,谢谢,但不幸的是,我无法将当前版本的代码嗅探器升级到最新版本。

标签: php codesniffer phpcodesniffer


【解决方案1】:

我解决了我的问题,但代码看起来不太好:

<div class="block">
<div class="block-title">
    <?php
    if ($user->isOnline()): ?>
        <a href="<?=Url::create('/user/logout');?>">Logout</a>
    <?php
    endif; ?>
</div>

所以我决定将视图文件添加到带有@codingStandardsIgnoreFile 注释的代码嗅探器忽略列表中。现在,需要手动检查代码样式,但代码看起来好多了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-01
    相关资源
    最近更新 更多