Skip to content

Feature suggestion: sniff to check for opportunities to use null coalesce #335

@jrfnl

Description

@jrfnl

Is your feature request related to a problem?

Help people find opportunities to modernize their codebase.

Describe the solution you'd like

Some typical code patterns the sniff could look for:

$b = isset($a) ? $a : '';
// Fixed version (PHP 7.0+):
$b = $a ?? '';

$a = isset($a) ? $a : '';
// Fixed version (PHP 7.0+):
$a = $a ?? '';
// Fixed version (PHP 7.4+):
$a ??= '';

$a = '';
if (isset($b)) {
    $a = $b;
}
if (isset($b) === true) {
    $a = $b;
}

// Fixed version (PHP 7.0+):
$a = $b ?? '';

Additional context (optional)

This will need a LOT of tests ;-)

  • I intend to create a pull request to implement this feature.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions