forked from vimeo/psalm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
2,107 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# RiskyTruthyFalsyComparison | ||
|
||
Emitted when comparing a value with multiple types that can both contain truthy and falsy values. | ||
|
||
```php | ||
<?php | ||
|
||
/** | ||
* @param array|null $arg | ||
* @return void | ||
*/ | ||
function foo($arg) { | ||
if ($arg) { | ||
// this is risky, bc the empty array and null case are handled together | ||
} | ||
|
||
if (!$arg) { | ||
// this is risky, bc the empty array and null case are handled together | ||
} | ||
} | ||
``` | ||
|
||
## Why this is bad | ||
|
||
The truthy/falsy type of one variable is often forgotten and not handled explicitly causing hard to track down errors. | ||
|
||
## How to fix | ||
|
||
Explicitly validate the variable with strict comparison. |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
namespace Psalm\Issue; | ||
|
||
use Psalm\CodeLocation; | ||
|
||
final class RiskyTruthyFalsyComparison extends CodeIssue | ||
{ | ||
public const ERROR_LEVEL = 2; | ||
public const SHORTCODE = 356; | ||
|
||
public function __construct(string $message, CodeLocation $code_location, ?string $dupe_key) | ||
{ | ||
parent::__construct($message, $code_location); | ||
$this->dupe_key = $dupe_key; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.