max-lines
Ensure that certain structure have line limit
Options
file
File max lines. Default is 400
Type: number
Default: 400
class
Class max lines. Default is 300
Type: number
Default: 300
interface
Interface max lines. If not set, class max lines will be used
Type: number
Default: undefined
trait
Trait max lines. If not set, class max lines will be used
Type: number
Default: undefined
enum
Enum max lines. If not set, class max lines will be used
Type: number
Default: undefined
function
Function max lines. Default is 100
Type: number
Default: 50
method
Method max lines. If not set, function max lines will be used
Type: number
Default: undefined
ignoreComments
Ignore comments. Default is true
Type: boolean
Default: true
ignoreEmptyLines
Ignore empty lines. Default is true
Type: boolean
Default: true
Examples
- Examples of correct code for this rule using default options
File, class and methods are within the limit
<?php
/**
* List Table API: WP_Comments_List_Table class
*
* @package WordPress
* @subpackage Administration
* @since 3.1.0
*/
/**
* Core class used to implement displaying comments in a list table.
*
* @since 3.1.0
*
* @see WP_List_Table
*/
class WP_Comments_List_Table extends WP_List_Table {
public $checkbox = true;
public $pending_count = array();
public $extra_items;
private $user_can;
/**
* Constructor.
*
* @since 3.1.0
*
* @see WP_List_Table::__construct() for more information on default arguments.
*
* @global int $post_id
*
* @param array $args An associative array of arguments.
*/
public function __construct( $args = array() ) {
global $post_id;
$post_id = isset( $_REQUEST['p'] ) ? absint( $_REQUEST['p'] ) : 0;
if ( get_option( 'show_avatars' ) ) {
add_filter( 'comment_author', array( $this, 'floated_admin_avatar' ), 10, 2 );
}
parent::__construct(
array(
'plural' => 'comments',
'singular' => 'comment',
'ajax' => true,
'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
)
);
}
/**
* Adds avatars to comment author names.
*
* @since 3.1.0
*
* @param string $name Comment author name.
* @param int $comment_id Comment ID.
* @return string Avatar with the user name.
*/
public function floated_admin_avatar( $name, $comment_id ) {
$comment = get_comment( $comment_id );
$avatar = get_avatar( $comment, 32, 'mystery' );
return "$avatar $name";
}
/**
* @return bool
*/
public function ajax_user_can() {
return current_user_can( 'edit_posts' );
}
/**
* @param string $comment_status
* @return int
*/
public function get_per_page( $comment_status = 'all' ) {
$comments_per_page = $this->get_items_per_page( 'edit_comments_per_page' );
/**
* Filters the number of comments listed per page in the comments list table.
*
* @since 2.6.0
*
* @param int $comments_per_page The number of comments to list per page.
* @param string $comment_status The comment status name. Default 'All'.
*/
return apply_filters( 'comments_per_page', $comments_per_page, $comment_status );
}
/**
* @global string $comment_status
*/
public function no_items() {
global $comment_status;
if ( 'moderated' === $comment_status ) {
_e( 'No comments awaiting moderation.' );
} elseif ( 'trash' === $comment_status ) {
_e( 'No comments found in Trash.' );
} else {
_e( 'No comments found.' );
}
}
}
?>
Trait, interface and enum are within the limit
<?php
trait ConnectSqlServerDatabaseToTrait {
public function helpMeConnectSqlServerDatabases() {
$SQLServerdatabaseConnectionString = '';
}
}
interface ConnectSqlServerDatabaseToModel {
public function youHaveToConnectSQLServerDatabase();
}
enum DatabasesTypesConnectingToServer {
case SQL;
case NoSQL;
case Graph;
case Key_Value;
}
- Examples of incorrect code for this rule using default options
File, class and method exceed the limit
<?php
/* taqwim "taqwim/max-lines": {"class": 20, "function": 10 } */
/**
* List Table API: WP_Comments_List_Table class
*
* @package WordPress
* @subpackage Administration
* @since 3.1.0
*/
/**
* Core class used to implement displaying comments in a list table.
*
* @since 3.1.0
*
* @see WP_List_Table
*/
class WP_Comments_List_Table extends WP_List_Table {
public $checkbox = true;
public $pending_count = array();
public $extra_items;
private $user_can;
/**
* Constructor.
*
* @since 3.1.0
*
* @see WP_List_Table::__construct() for more information on default arguments.
*
* @global int $post_id
*
* @param array $args An associative array of arguments.
*/
public function __construct( $args = array() ) {
global $post_id;
$post_id = isset( $_REQUEST['p'] ) ? absint( $_REQUEST['p'] ) : 0;
if ( get_option( 'show_avatars' ) ) {
add_filter( 'comment_author', array( $this, 'floated_admin_avatar' ), 10, 2 );
}
parent::__construct(
array(
'plural' => 'comments',
'singular' => 'comment',
'ajax' => true,
'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
)
);
}
/**
* Adds avatars to comment author names.
*
* @since 3.1.0
*
* @param string $name Comment author name.
* @param int $comment_id Comment ID.
* @return string Avatar with the user name.
*/
public function floated_admin_avatar( $name, $comment_id ) {
$comment = get_comment( $comment_id );
$avatar = get_avatar( $comment, 32, 'mystery' );
return "$avatar $name";
}
/**
* @return bool
*/
public function ajax_user_can() {
return current_user_can( 'edit_posts' );
}
/**
* @param string $comment_status
* @return int
*/
public function get_per_page( $comment_status = 'all' ) {
$comments_per_page = $this->get_items_per_page( 'edit_comments_per_page' );
/**
* Filters the number of comments listed per page in the comments list table.
*
* @since 2.6.0
*
* @param int $comments_per_page The number of comments to list per page.
* @param string $comment_status The comment status name. Default 'All'.
*/
return apply_filters( 'comments_per_page', $comments_per_page, $comment_status );
}
/**
* @global string $comment_status
*/
public function no_items() {
global $comment_status;
if ( 'moderated' === $comment_status ) {
_e( 'No comments awaiting moderation.' );
} elseif ( 'trash' === $comment_status ) {
_e( 'No comments found in Trash.' );
} else {
_e( 'No comments found.' );
}
}
}
Trait, interface and enum exceed the limit
<?php
/* taqwim "taqwim/max-lines": {"class": 5} */
trait ConnectSqlServerDatabaseToTrait {
public function helpMeConnectSqlServerDatabases() {
$SQLServerdatabaseConnectionString = '';
}
public function helpMeConnectSqlServerDatabases2() {
$SQLServerdatabaseConnectionString = '';
}
public function helpMeConnectSqlServerDatabases3() {
$SQLServerdatabaseConnectionString = '';
}
}
interface ConnectSqlServerDatabaseToModel {
public function youHaveToConnectSQLServerDatabase();
public function youHaveToConnectSQLServerDatabase2();
public function youHaveToConnectSQLServerDatabase3();
public function youHaveToConnectSQLServerDatabase4();
public function youHaveToConnectSQLServerDatabase5();
}
enum DatabasesTypesConnectingToServer {
case SQL;
case NoSQL;
case Graph;
case Key_Value;
case SQL2;
case NoSQL2;
}
File, class and method exceed the limit that includes comments and blank lines
<?php
/* taqwim "taqwim/max-lines": {"class": 20, "function": 10, "ignoreComments": false, "ignoreEmptyLines": false } */
/**
* List Table API: WP_Comments_List_Table class
*
* @package WordPress
* @subpackage Administration
* @since 3.1.0
*/
/**
* Core class used to implement displaying comments in a list table.
*
* @since 3.1.0
*
* @see WP_List_Table
*/
class WP_Comments_List_Table extends WP_List_Table {
public $checkbox = true;
public $pending_count = array();
public $extra_items;
private $user_can;
/**
* Constructor.
*
* @since 3.1.0
*
* @see WP_List_Table::__construct() for more information on default arguments.
*
* @global int $post_id
*
* @param array $args An associative array of arguments.
*/
public function __construct( $args = array() ) {
global $post_id;
$post_id = isset( $_REQUEST['p'] ) ? absint( $_REQUEST['p'] ) : 0;
if ( get_option( 'show_avatars' ) ) {
add_filter( 'comment_author', array( $this, 'floated_admin_avatar' ), 10, 2 );
}
parent::__construct(
array(
'plural' => 'comments',
'singular' => 'comment',
'ajax' => true,
'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
)
);
}
/**
* Adds avatars to comment author names.
*
* @since 3.1.0
*
* @param string $name Comment author name.
* @param int $comment_id Comment ID.
* @return string Avatar with the user name.
*/
public function floated_admin_avatar( $name, $comment_id ) {
$comment = get_comment( $comment_id );
$avatar = get_avatar( $comment, 32, 'mystery' );
return "$avatar $name";
}
/**
* @return bool
*/
public function ajax_user_can() {
return current_user_can( 'edit_posts' );
}
/**
* @param string $comment_status
* @return int
*/
public function get_per_page( $comment_status = 'all' ) {
$comments_per_page = $this->get_items_per_page( 'edit_comments_per_page' );
/**
* Filters the number of comments listed per page in the comments list table.
*
* @since 2.6.0
*
* @param int $comments_per_page The number of comments to list per page.
* @param string $comment_status The comment status name. Default 'All'.
*/
return apply_filters( 'comments_per_page', $comments_per_page, $comment_status );
}
/**
* @global string $comment_status
*/
public function no_items() {
global $comment_status;
if ( 'moderated' === $comment_status ) {
_e( 'No comments awaiting moderation.' );
} elseif ( 'trash' === $comment_status ) {
_e( 'No comments found in Trash.' );
} else {
_e( 'No comments found.' );
}
}
}