diff --git a/src/Psalm/Type/Atomic/TFalse.php b/src/Psalm/Type/Atomic/TFalse.php index 03d1e27c05f..03ddf5893f9 100644 --- a/src/Psalm/Type/Atomic/TFalse.php +++ b/src/Psalm/Type/Atomic/TFalse.php @@ -9,7 +9,10 @@ */ final class TFalse extends TBool { - /** @var false */ + /** + * @readonly + * @var false + */ public $value = false; public function getKey(bool $include_extra = true): string @@ -17,8 +20,28 @@ public function getKey(bool $include_extra = true): string return 'false'; } + /** + * @param array $aliased_classes + */ + public function toPhpString( + ?string $namespace, + array $aliased_classes, + ?string $this_class, + int $analysis_php_version_id + ): ?string { + if ($analysis_php_version_id >= 8_02_00) { + return $this->getKey(); + } + + if ($analysis_php_version_id >= 7_00_00) { + return 'bool'; + } + + return null; + } + public function canBeFullyExpressedInPhp(int $analysis_php_version_id): bool { - return false; + return $analysis_php_version_id >= 7_00_00; } } diff --git a/src/Psalm/Type/Atomic/TIterable.php b/src/Psalm/Type/Atomic/TIterable.php index 1f67bfb5602..6eb5179699e 100644 --- a/src/Psalm/Type/Atomic/TIterable.php +++ b/src/Psalm/Type/Atomic/TIterable.php @@ -101,7 +101,9 @@ public function toPhpString( public function canBeFullyExpressedInPhp(int $analysis_php_version_id): bool { - return $this->type_params[0]->isMixed() && $this->type_params[1]->isMixed(); + return $analysis_php_version_id >= 7_01_00 + && $this->type_params[0]->isMixed() + && $this->type_params[1]->isMixed(); } public function equals(Atomic $other_type, bool $ensure_source_equality): bool diff --git a/src/Psalm/Type/Atomic/TNull.php b/src/Psalm/Type/Atomic/TNull.php index 7ce4717f701..728e1e5b912 100644 --- a/src/Psalm/Type/Atomic/TNull.php +++ b/src/Psalm/Type/Atomic/TNull.php @@ -25,11 +25,11 @@ public function toPhpString( ?string $this_class, int $analysis_php_version_id ): ?string { - return null; + return $analysis_php_version_id >= 8_02_00 ? $this->getKey() : null; } public function canBeFullyExpressedInPhp(int $analysis_php_version_id): bool { - return false; + return $analysis_php_version_id >= 8_02_00; } } diff --git a/src/Psalm/Type/Atomic/TObject.php b/src/Psalm/Type/Atomic/TObject.php index 31e66c9b5a0..f5797d142d2 100644 --- a/src/Psalm/Type/Atomic/TObject.php +++ b/src/Psalm/Type/Atomic/TObject.php @@ -30,6 +30,6 @@ public function toPhpString( public function canBeFullyExpressedInPhp(int $analysis_php_version_id): bool { - return true; + return $analysis_php_version_id >= 7_02_00; } } diff --git a/src/Psalm/Type/Atomic/TTrue.php b/src/Psalm/Type/Atomic/TTrue.php index 5209cbc4058..38df388d6d7 100644 --- a/src/Psalm/Type/Atomic/TTrue.php +++ b/src/Psalm/Type/Atomic/TTrue.php @@ -9,7 +9,10 @@ */ final class TTrue extends TBool { - /** @var true */ + /** + * @readonly + * @var true + */ public $value = true; public function getKey(bool $include_extra = true): string @@ -17,8 +20,28 @@ public function getKey(bool $include_extra = true): string return 'true'; } + /** + * @param array $aliased_classes + */ + public function toPhpString( + ?string $namespace, + array $aliased_classes, + ?string $this_class, + int $analysis_php_version_id + ): ?string { + if ($analysis_php_version_id >= 8_02_00) { + return $this->getKey(); + } + + if ($analysis_php_version_id >= 7_00_00) { + return 'bool'; + } + + return null; + } + public function canBeFullyExpressedInPhp(int $analysis_php_version_id): bool { - return false; + return $analysis_php_version_id >= 7_00_00; } } diff --git a/src/Psalm/Type/Atomic/TVoid.php b/src/Psalm/Type/Atomic/TVoid.php index e122d9a8e1c..3e1acf7f75a 100644 --- a/src/Psalm/Type/Atomic/TVoid.php +++ b/src/Psalm/Type/Atomic/TVoid.php @@ -30,6 +30,6 @@ public function toPhpString( public function canBeFullyExpressedInPhp(int $analysis_php_version_id): bool { - return true; + return $analysis_php_version_id >= 7_01_00; } } diff --git a/tests/FileManipulation/MissingReturnTypeTest.php b/tests/FileManipulation/MissingReturnTypeTest.php index 4d43cd1a429..6b0b2c7537d 100644 --- a/tests/FileManipulation/MissingReturnTypeTest.php +++ b/tests/FileManipulation/MissingReturnTypeTest.php @@ -897,6 +897,30 @@ function a(): ?bool { 'issues_to_fix' => ['MissingReturnType'], 'safe_types' => false, ], + 'returnNullAndReturnTrueNative' => [ + 'input' => ' ' '8.2', + 'issues_to_fix' => ['MissingReturnType'], + 'safe_types' => false, + ], 'staticReturn5.6' => [ 'input' => '