Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strict rules: Only booleans are allowed in an if condition #444

Open
1 of 5 tasks
lulco opened this issue Sep 27, 2023 · 0 comments
Open
1 of 5 tasks

Strict rules: Only booleans are allowed in an if condition #444

lulco opened this issue Sep 27, 2023 · 0 comments
Assignees

Comments

@lulco
Copy link
Contributor

lulco commented Sep 27, 2023

  • Only booleans are allowed in an if condition, string|null given.
if ($this->getParentName()) { // <- string|null
}

should be transformed to:

if ($this->getParentName() !== null) { // ok
}
  • Only booleans are allowed in an if condition, string|null given.
/** @var string|null $nullOrUrl */
if ($ʟ_if0 = $nullOrUrl) {            
}
if ($ʟ_if0) { // <- string|null
}

should be transformed to:

/** @var string|null $nullOrUrl */
if ($ʟ_if0 = $nullOrUrl) {            
}
if ($ʟ_if0 !== null) { // ok
}
  • Only booleans are allowed in an if condition, Nette\Utils\Html|null given.
if ($ʟ_label = $form["username"]->getLabelPart()) {
    echo $ʟ_label;
}

should be transformed to:

$ʟ_label = $form["username"]->getLabelPart();
if ($ʟ_label !== null) {
    echo $ʟ_label;
}
  • Only booleans are allowed in an if condition, Nette\Utils\Html|string|null given.
if ($ʟ_label = $form["checkbox"]->getLabel()) {
    echo $ʟ_label;
}

should be transformed to:

$ʟ_label = $form["checkbox"]->getLabel();
if ($ʟ_label !== null) {
    echo $ʟ_label;
}
  • Only booleans are allowed in a ternary operator condition, int|false given.
try {
    echo 'Links:create';
} finally {
    $ʟ_tmp = \ob_get_length() ? new \Latte\Runtime\Html(\ob_get_clean()) : \ob_get_clean();
}

should be transformed to:

try {
    echo 'Links:create';
} finally {
    $ʟ_tmp = (bool)\ob_get_length() ? new \Latte\Runtime\Html(\ob_get_clean()) : \ob_get_clean();
}
@lulco lulco self-assigned this Sep 27, 2023
@lulco lulco changed the title If condition can contain only boolean rule fails on some parts of code which are from nette itself Strict rules: Only booleans are allowed in an if condition Oct 11, 2023
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

No branches or pull requests

1 participant