我无法让这些规则发挥作用:
函数名后没有空格:
// good
public function cities()
// bad
public function cities ()
Run Code Online (Sandbox Code Playgroud)
确保等于之间的空格:
// good
$test = 'test';
// bad
$test ='test';
$test= 'test';
Run Code Online (Sandbox Code Playgroud)
args 中逗号后必须有空格:
// good
function ($arg1, $arg2)
// bad
function ($arg1,$arg2)
function ($arg1 ,$arg2)
Run Code Online (Sandbox Code Playgroud)
我的规则:
<?xml version="1.0"?>
<ruleset name="PSR2">
<description>The PSR-2 coding standard.</description>
<!-- PHP code MUST use the long <?php ?> tags or the short-echo <?= ?> tags; it MUST NOT use the other tag variations. -->
<rule ref="Generic.PHP.DisallowShortOpenTag.EchoFound">
<severity>0</severity>
</rule>
<!-- PHP code …Run Code Online (Sandbox Code Playgroud) 我一直在尝试在Symfony项目中使用PHP_CodeSniffer,但它通常会抛出Symfony社区通常不会遵循的警告(比如评论参数标签或不在功能文档中对参数进行分组和返回)
我想知道Symfony是否有任何官方或非官方但维护良好的规则集
我找到了这个:https: //github.com/djoos/Symfony2-coding-standard 看起来不错,但现在还没有更新
我正在使用 Laravel 4.2。
假设有这样一个类:
class BShopsController extends ShopsController
Run Code Online (Sandbox Code Playgroud)
为了解决这个问题,我尝试使用名称空间让我们这样说:
namespace app\controllers;
Run Code Online (Sandbox Code Playgroud)
然后它找不到 ShopsController
所以我添加
use \ShopsController;
Run Code Online (Sandbox Code Playgroud)
然后我得到错误:
BShopsController 类不存在
我应该首先使用哪个命名空间,这样它就不会破坏任何东西?
编辑:
BShopsController 和 ShopsController 位于 Shops 文件夹中
在我的自定义嗅探中我添加了
<rule ref="Generic.WhiteSpace.ScopeIndent">
<properties>
<property name="indent" value="2" />
<property name="tabIndent" value="false" />
</properties>
</rule>
Run Code Online (Sandbox Code Playgroud)
它适用于内部的功能和控制结构,但例如
function test_plugin_admin_enqueue( $hook ) {
/**
* Load only on ?page=test-ajax-admin.php
* The easiest way to find out the hook name is to go to the
* options page and put print_r( $hook ); before the conditional.
*/
if ( $hook !== 'toplevel_page_test-ajax-admin' ) {
return;
}
wp_enqueue_script( 'test-plugin-admin-script', plugin_dir_url( __FILE__ ) . 'js/admin.js', array( 'jquery' ) );
}
Run Code Online (Sandbox Code Playgroud)
将会return有错误Tabs must be …