Problem/Motivation

All method arguments with default values should be declared after the method arguments without default values. Otherwise, it makes it impossible for callers to take advantage of defaults; they must re-specify the defaulted values in order to "get to" the non-default arguments.

File: search_api/tests/src/Unit/Processor/EntityStatusTest.php

83: public function testSupportsIndex(array $datasource_ids = NULL, $expected) {

Proposed resolution

83: public function testSupportsIndex($expected, array $datasource_ids = NULL) {

Comments

fnalb2 created an issue. See original summary.

Pracheth’s picture

Status: Active » Needs review
StatusFileSize
new1.42 KB

Hi fnalb2,
Updated the class file as per the proposed resolution.
Please review the same.

Status: Needs review » Needs work

The last submitted patch, 2: updated_function_arguments-3319384-#2.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

fnalb2’s picture

Status: Needs work » Reviewed & tested by the community

Reviewed

drunken monkey’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new3.73 KB

Thanks for reporting this problem and providing a patch, respectively!

However, obviously, when changing the method signature you will also need to adapt the callers accordingly. The test failures should have been a hint.
Furthermore, you see that the = NULL default was just there to allow NULL to be passed (which was necessary before the ?array syntax for type hinting became available), not as an actual default.
Attached is the correct solution to this problem, along with a few other code style fixes in these two files.

  • drunken monkey committed 504991d6 on 8.x-1.x
    Issue #3319384 by drunken monkey: Fixed code style issues in...
drunken monkey’s picture

Title: Move arguments "$datasource_ids" after arguments without default value in EntityStatusTest.php » Fix code style issues in EntityStatusTest and StemmerTest
Component: General code » Tests
Status: Needs review » Fixed

Committed.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.