-
Notifications
You must be signed in to change notification settings - Fork 660
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10828 from jack-worman/MissingClassConstType
- Loading branch information
Showing
9 changed files
with
139 additions
and
14 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,21 @@ | ||
# MissingClassConstType | ||
|
||
Emitted when a class constant doesn't have a declared type. | ||
|
||
```php | ||
<?php | ||
|
||
class A { | ||
public const B = 0; | ||
} | ||
``` | ||
|
||
Correct with: | ||
|
||
```php | ||
<?php | ||
|
||
class A { | ||
public const int B = 0; | ||
} | ||
``` |
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,11 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Psalm\Issue; | ||
|
||
final class MissingClassConstType extends CodeIssue | ||
{ | ||
public const ERROR_LEVEL = 2; | ||
public const SHORTCODE = 359; | ||
} |
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,60 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Psalm\Tests; | ||
|
||
use Psalm\Issue\MissingClassConstType; | ||
use Psalm\Tests\Traits\InvalidCodeAnalysisTestTrait; | ||
use Psalm\Tests\Traits\ValidCodeAnalysisTestTrait; | ||
|
||
class MissingClassConstTypeTest extends TestCase | ||
{ | ||
use ValidCodeAnalysisTestTrait; | ||
use InvalidCodeAnalysisTestTrait; | ||
|
||
public function providerValidCodeParse(): iterable | ||
{ | ||
return [ | ||
'has type; >= PHP 8.3' => [ | ||
'code' => <<<'PHP' | ||
<?php | ||
class A { | ||
public const int B = 0; | ||
} | ||
PHP, | ||
'assertions' => [], | ||
'ignored_issues' => [], | ||
'php_version' => '8.3', | ||
], | ||
'no type; < PHP 8.3' => [ | ||
'code' => <<<'PHP' | ||
<?php | ||
class A { | ||
public const B = 0; | ||
} | ||
PHP, | ||
'assertions' => [], | ||
'ignored_issues' => [], | ||
'php_version' => '8.2', | ||
], | ||
]; | ||
} | ||
|
||
public function providerInvalidCodeParse(): iterable | ||
{ | ||
return [ | ||
'no type; >= PHP 8.3' => [ | ||
'code' => <<<'PHP' | ||
<?php | ||
class A { | ||
public const B = 0; | ||
} | ||
PHP, | ||
'error_message' => MissingClassConstType::getIssueType(), | ||
'error_levels' => [], | ||
'php_version' => '8.3', | ||
], | ||
]; | ||
} | ||
} |