Skip to content

DisallowedEmptyRuleFixerRector misbehaves, it converts !empty(string|null $foo) to $foo !== null #6724

Closed
rectorphp/rector-src
#956
@janedbal

Description

@janedbal

Bug Report

Subject Details
Rector version dev-main

DisallowedEmptyRuleFixerRector is making dangerous non-equivalent changes. See snippet below.

Minimal PHP Code Causing Issue

class Bug {
	public function get(): ?string {
		return null;
	}

	public function example(): void {
		if (!empty($this->get())) {
			
		}
	}
}
// gets converted to
class Bug {
	public function get(): ?string {
		return null;
	}

	public function example(): void {
		if ($this->get() !== null) {
			
		}
	}
}

Expected Behaviour

// should be converted to
class Bug {
	public function get(): ?string {
		return null;
	}

	public function example(): void {
		if ($this->get() !== null && $this->get() !== '') {
			
		}
	}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions