doucong8553 2017-05-30 23:47
浏览 74
已采纳

PHP代码嗅探器中的三元运算符出错

I have problem with PHP code sniffer and ternary operator. I added rule for checking spaces after and before operators

<rule ref="Squiz.WhiteSpace.OperatorSpacing"/>

and now I have errors in short if statements:

 37 | ERROR | [x] Expected 1 space before "?"; newline found
 38 | ERROR | [x] Expected 1 space before ":"; newline found

My code looks like:

return ($this->get('router')->getContext()->getHttpPort() == 80)
    ? '//'.$this->get('router')->getContext()->getHost()
    : '//'.$this->get('router')->getContext()->getHost().':'.$this->get('router')->getContext()->getHttpPort();

Anyone know where can be problem? I can paste whole ruleset file but after delete OperatorSpacing rule everything is ok.

Greetings

  • 写回答

2条回答 默认 最新

  • drag2458 2017-05-31 00:07
    关注

    Ok guys, thanks for help but i found solution, @roberto06, thanks for link m8!

    After add

    <rule ref="Squiz.WhiteSpace.OperatorSpacing">
        <properties>
            <property name="ignoreNewlines" value="true"/>
        </properties>
    </rule>
    

    it's working perfect :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部