Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
PEAR/ValidDefaultValue: handle FQN null
This commit fixes the sniff to handle "fully qualified null" as a default value, the same as unqualified null.

Includes tests.
  • Loading branch information
jrfnl committed Aug 30, 2025
commit e4df0d626cbfc4528d0ab1c2b667999c1d7f34f4
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,14 @@ public function process(File $phpcsFile, $stackPtr)
}

if (array_key_exists('default', $param) === true) {
$defaultFound = true;
$defaultFound = true;
$defaultValueLc = strtolower($param['default']);
// Check if the arg is type hinted and using NULL for the default.
// This does not make the argument optional - it just allows NULL
// to be passed in.
if ($param['type_hint'] !== '' && strtolower($param['default']) === 'null') {
if ($param['type_hint'] !== ''
&& ($defaultValueLc === 'null' || $defaultValueLc === '\null')
) {
$defaultFound = false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,7 @@ class ConstructorPropertyPromotionMixedWithNormalParams {
mixed $requiredParam,
) {}
}

// Safeguard correct handling of FQN null as default value.
function foo(Foo $foo = \null, $bar) {}
function foo(Foo $foo = \null, Foz $foz = \NULL, $bar = true, $baz) {}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public function getErrorList($testFile='')
101 => 1,
106 => 1,
114 => 1,
120 => 1,
];

default:
Expand Down