Skip to content

Commit

Permalink
Classes/DeclarationCompatibility: sync with WP Core
Browse files Browse the repository at this point in the history
While looking at this sniff for something unrelated, I started wondering if the signature definitions were still in line with WP Core.

Turned out they were not.

Refs:
* https://developer.wordpress.org/reference/classes/wp_widget/wp_widget/
* https://developer.wordpress.org/reference/classes/walker/start_el/
* https://developer.wordpress.org/reference/classes/walker/end_el/
* https://developer.wordpress.org/reference/classes/walker/unset_children/

Also see the [additional notes I've added to the review ticket](#507 (comment)).
  • Loading branch information
jrfnl committed Sep 19, 2023
1 parent 9749b01 commit 392bd12
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class DeclarationCompatibilitySniff extends AbstractScopeSniff {
'widget_options' => [
'default' => 'array()',
],
'constol_options' => [
'control_options' => [
'default' => 'array()',
],
],
Expand Down Expand Up @@ -103,7 +103,7 @@ class DeclarationCompatibilitySniff extends AbstractScopeSniff {
'output' => [
'pass_by_reference' => true,
],
'object',
'data_object',
'depth' => [
'default' => '0',
],
Expand All @@ -118,7 +118,7 @@ class DeclarationCompatibilitySniff extends AbstractScopeSniff {
'output' => [
'pass_by_reference' => true,
],
'object',
'data_object',
'depth' => [
'default' => '0',
],
Expand Down Expand Up @@ -158,7 +158,7 @@ class DeclarationCompatibilitySniff extends AbstractScopeSniff {
'elements',
],
'unset_children' => [
'el',
'element',
'children_elements' => [
'pass_by_reference' => true,
],
Expand Down Expand Up @@ -215,7 +215,7 @@ protected function processTokenWithinScope( File $phpcsFile, $stackPtr, $currSco
return;
}

// Meed to define the originalParentClassName since we might override the parentClassName due to signature notations grouping.
// Need to define the originalParentClassName since we might override the parentClassName due to signature notations grouping.
$originalParentClassName = $parentClassName;

if ( array_key_exists( $parentClassName, $this->checkClasses ) === false ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,21 @@ class MyWalker extends Walker {
function display_element( $element, &$children_elements, $max_depth, $depth, $args, &$output ) {
} // Ok.

function unset_children( $el, $children_elements ) {
function unset_children( $element, $children_elements ) {
} // Bad. $children_elements should be passed by reference

function walk( $elements, $max_depth, ...$args ) {
} // Ok.

function paged_walk( $elements, $max_depth, $page_num, $per_page ) {
} // Bad. Missing $args.

function paged_walk( $elements, $max_depth, $page_num, $per_page, $args ) {
} // Bad. $args is not variadic.

function start_el( $output, $data_object, $depth, $args = array(), $current_object_id = 0 ) {
} // Bad. $output should be passed by reference, $depth should have a default value.

function end_el( &$output, $data_object, $depth = 0, $args = array() ) {
} // Ok.
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public function getErrorList() {
128 => 1,
134 => 1,
137 => 1,
140 => 1,
];
}

Expand Down

0 comments on commit 392bd12

Please sign in to comment.