Skip to content

Remove dead code based on evaluated constant expression #2574

@staabm

Description

@staabm

Before

if (time() > strtotime('30 Nov 2018')) {
  // do something1
} else if (time() > strtotime('30 Nov 2019')) {
  // do something2
} else {
  // do something3
}

After running with min php version = 7.3

  // do something3

Inspired by https://github.com/redaxo/redaxo/blob/46d0ace6cd1ca0d40fa233abd637bea53c694daa/redaxo/src/core/pages/setup.php#L147

Phpstan e.g. does similar things with printf() in case the format pattern can be constructed at parse time, some validation runs
I guess its implemented in https://github.com/phpstan/phpstan-src/blob/699c420f8193da66927e54494a0afa0c323c6458/src/Rules/Functions/PrintfParametersRule.php

https://github.com/phpstan/phpstan-src/blob/699c420f8193da66927e54494a0afa0c323c6458/src/Type/Php/SprintfFunctionDynamicReturnTypeExtension.php

https://github.com/phpstan/phpstan-src/blob/699c420f8193da66927e54494a0afa0c323c6458/src/Type/Php/StrtotimeFunctionReturnTypeExtension.php

Related phpstan/phpstan#2812

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions