当前位置: 首页 > 后端技术 > PHP

代码规范-Phan静态分析

时间:2023-03-29 14:53:36 PHP

关于PhanPhan是PHP的静态分析器,旨在最大限度地减少误报。它试图证明错误而不是正确。当类型信息可用或可以推断时,它会查找常见问题并验证各种操作的类型兼容性。astwindowsmac的扩展安装:peclinstallastpcntl.somac:源码编译安装windows:不支持入门##安装composerrequire--devphan/phan##初始化配置vendor/bin/phan--init--init-level=3##执行vendor/bin/phan##执行(windows)shvendor\bin\phan核心配置解释。phan/config.phpreturn[//开启的子进程数,需要使用pcntl扩展,windows不支持,mac安装后,可以修改'processes'=>1,//开启进度条'progress_bar'=>true,//解析后的目录(包括依赖,需要排除依赖的exclude)'directory_list'=>['app','vendor'//建议最小化原则,loadlessfiles],//目录不需要解析'exclude_analysis_directory_list'=>['vendor','.phan',],//将需要解析的文件分开'file_list'=>[],//需要解析的文件列表excluded'exclude_file_list'=>[],//自动加载的内部类库,一般用于加载扩展存根。下面介绍laravelstub'autoload_internal_extension_signatures'=>['laravelIdeHelper'=>'_ide_helper.php','laravelMeta'=>'.phpstorm.meta.php'],]忽略部分错误:建议不要使用suppress忽略整个方法类D{/***@suppressPhanUndeclared类方法*/functiong(){C::f();}}@phan-suppress-current-line忽略当前行functiontest_line_suppression(){echo$undef1;//@phan-suppress-current-linePhanUndeclaredVariableecho$undef2+missingFn();}@phan-suppress-next-line忽略下一行functiontest_line_suppression(){//@phan-suppress-next-linePhanUndeclaredVariable,PhanUndeclaredFunctionecho$undefVar2+missing_function();}

猜你喜欢