Skip to content

Conversation

@john-shaffer
Copy link
Contributor

A negated constant boolean can be trivially changed to the other constant boolean.

class IfCondition
{
    public function run()
    {
-        if (!true) {
+        if (false) {
            return true;
        }
        return false;
    }
}

I am using this in tandem with bootstrapped constants. It allows dead code elimination rectors to remove blocks of code when the appropriate constants are defined.

@john-shaffer john-shaffer force-pushed the add-replace-constant-boolean-not-rector branch from 8b16ecf to 15ed1fb Compare October 21, 2025 14:24
@john-shaffer john-shaffer force-pushed the add-replace-constant-boolean-not-rector branch from 15ed1fb to 8c97f9f Compare October 21, 2025 14:25
@TomasVotruba
Copy link
Member

TomasVotruba commented Oct 21, 2025

Looks good, thank you for new rule 👍

@TomasVotruba TomasVotruba merged commit 6602925 into rectorphp:main Oct 21, 2025
52 checks passed
@john-shaffer john-shaffer deleted the add-replace-constant-boolean-not-rector branch October 21, 2025 16:27
john-shaffer added a commit to staticweb-io/static-deploy that referenced this pull request Oct 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants