根据 wpcs 清理代码以进行 yoda 条件检查
Sanitizing the code as per wpcs for yoda condition checks
我正在尝试使用 phpcs --standard=Wordpress ../filename.php
清理文件。但似乎 phpcbf 无法执行该操作。所以,任何人都可以分享一些帮助,因为我如何手动修复这些文档评论和 yoda 错误。附件是相关的代码块和实际 php 文件的片段以及遇到的错误。任何帮助将不胜感激。
<?php
function is_blog() {
return ( is_archive() || is_author() || is_category() || is_home() || is_single() || is_tag() ) && 'post' == get_post_type();
}
?>
<?php do_action( 'generate_before_footer' ); ?>
<div <?php generate_footer_class(); ?>>
<?php
do_action( 'generate_before_footer_content' );
// Get how many widgets to show.
$widgets = generate_get_footer_widgets();
if ( ! empty( $widgets ) && 0 !== $widgets ) :
// Set up the widget width.
$widget_width = '';
if ( $widgets == 1 ) {
$widget_width = '100';
}
if ( $widgets == 2 ) {
$widget_width = '50';
}
if ( $widgets == 3 ) {
$widget_width = '33';
}
if ( $widgets == 4 ) {
$widget_width = '25';
}
if ( $widgets == 5 ) {
$widget_width = '20';
}
?>
在 is_blog()
函数之上,您需要添加一个文档块:
/**
* Function comment here.
*
*/
function is_blog() {
}
Yoda 条件是当您在要比较的变量之前写入要比较的值时。所以而不是:
if ( $widgets == 1 ) {
$widget_width = '100';
}
它要你写:
if ( 1 == $widgets ) {
$widget_width = '100';
}
更改这些内容应该会使文件通过检查。
我正在尝试使用 phpcs --standard=Wordpress ../filename.php
清理文件。但似乎 phpcbf 无法执行该操作。所以,任何人都可以分享一些帮助,因为我如何手动修复这些文档评论和 yoda 错误。附件是相关的代码块和实际 php 文件的片段以及遇到的错误。任何帮助将不胜感激。
<?php
function is_blog() {
return ( is_archive() || is_author() || is_category() || is_home() || is_single() || is_tag() ) && 'post' == get_post_type();
}
?>
<?php do_action( 'generate_before_footer' ); ?>
<div <?php generate_footer_class(); ?>>
<?php
do_action( 'generate_before_footer_content' );
// Get how many widgets to show.
$widgets = generate_get_footer_widgets();
if ( ! empty( $widgets ) && 0 !== $widgets ) :
// Set up the widget width.
$widget_width = '';
if ( $widgets == 1 ) {
$widget_width = '100';
}
if ( $widgets == 2 ) {
$widget_width = '50';
}
if ( $widgets == 3 ) {
$widget_width = '33';
}
if ( $widgets == 4 ) {
$widget_width = '25';
}
if ( $widgets == 5 ) {
$widget_width = '20';
}
?>
在 is_blog()
函数之上,您需要添加一个文档块:
/**
* Function comment here.
*
*/
function is_blog() {
}
Yoda 条件是当您在要比较的变量之前写入要比较的值时。所以而不是:
if ( $widgets == 1 ) {
$widget_width = '100';
}
它要你写:
if ( 1 == $widgets ) {
$widget_width = '100';
}
更改这些内容应该会使文件通过检查。