|
1 | | -# 28 Rules Overview |
| 1 | +# 32 Rules Overview |
2 | 2 |
|
3 | 3 | ## AnnotateRegexClassConstWithRegexLinkRule |
4 | 4 |
|
@@ -381,6 +381,40 @@ return strlen('...'); |
381 | 381 |
|
382 | 382 | <br> |
383 | 383 |
|
| 384 | +## ForbiddenStaticClassConstFetchRule |
| 385 | + |
| 386 | +Avoid static access of constants, as they can change value. Use interface and contract method instead |
| 387 | + |
| 388 | +- class: [`Symplify\PHPStanRules\Rules\ForbiddenStaticClassConstFetchRule`](../src/Rules/ForbiddenStaticClassConstFetchRule.php) |
| 389 | + |
| 390 | +```php |
| 391 | +class SomeClass |
| 392 | +{ |
| 393 | + public function run() |
| 394 | + { |
| 395 | + return static::SOME_CONST; |
| 396 | + } |
| 397 | +} |
| 398 | +``` |
| 399 | + |
| 400 | +:x: |
| 401 | + |
| 402 | +<br> |
| 403 | + |
| 404 | +```php |
| 405 | +class SomeClass |
| 406 | +{ |
| 407 | + public function run() |
| 408 | + { |
| 409 | + return self::SOME_CONST; |
| 410 | + } |
| 411 | +} |
| 412 | +``` |
| 413 | + |
| 414 | +:+1: |
| 415 | + |
| 416 | +<br> |
| 417 | + |
384 | 418 | ## NoDuplicatedShortClassNameRule |
385 | 419 |
|
386 | 420 | Class with base "%s" name is already used in "%s". Use unique name to make classes easy to recognize |
@@ -470,6 +504,70 @@ class SomeClass |
470 | 504 |
|
471 | 505 | <br> |
472 | 506 |
|
| 507 | +## NoEntityOutsideEntityNamespaceRule |
| 508 | + |
| 509 | +Class with #[Entity] attribute must be located in "Entity" namespace to be loaded by Doctrine |
| 510 | + |
| 511 | +- class: [`Symplify\PHPStanRules\Rules\NoEntityOutsideEntityNamespaceRule`](../src/Rules/NoEntityOutsideEntityNamespaceRule.php) |
| 512 | + |
| 513 | +```php |
| 514 | +namespace App\ValueObject; |
| 515 | + |
| 516 | +use Doctrine\ORM\Mapping as ORM; |
| 517 | + |
| 518 | +#[ORM\Entity] |
| 519 | +class Product |
| 520 | +{ |
| 521 | +} |
| 522 | +``` |
| 523 | + |
| 524 | +:x: |
| 525 | + |
| 526 | +<br> |
| 527 | + |
| 528 | +```php |
| 529 | +namespace App\Entity; |
| 530 | + |
| 531 | +use Doctrine\ORM\Mapping as ORM; |
| 532 | + |
| 533 | +#[ORM\Entity] |
| 534 | +class Product |
| 535 | +{ |
| 536 | +} |
| 537 | +``` |
| 538 | + |
| 539 | +:+1: |
| 540 | + |
| 541 | +<br> |
| 542 | + |
| 543 | +## NoGlobalConstRule |
| 544 | + |
| 545 | +Global constants are forbidden. Use enum-like class list instead |
| 546 | + |
| 547 | +- class: [`Symplify\PHPStanRules\Rules\NoGlobalConstRule`](../src/Rules/NoGlobalConstRule.php) |
| 548 | + |
| 549 | +```php |
| 550 | +const SOME_GLOBAL_CONST = 'value'; |
| 551 | +``` |
| 552 | + |
| 553 | +:x: |
| 554 | + |
| 555 | +<br> |
| 556 | + |
| 557 | +```php |
| 558 | +class SomeClass |
| 559 | +{ |
| 560 | + public function run() |
| 561 | + { |
| 562 | + return self::SOME_CONST; |
| 563 | + } |
| 564 | +} |
| 565 | +``` |
| 566 | + |
| 567 | +:+1: |
| 568 | + |
| 569 | +<br> |
| 570 | + |
473 | 571 | ## NoInlineStringRegexRule |
474 | 572 |
|
475 | 573 | Use local named constant instead of inline string for regex to explain meaning by constant name |
@@ -642,6 +740,44 @@ final class SomeClass |
642 | 740 |
|
643 | 741 | <br> |
644 | 742 |
|
| 743 | +## NoSingleInterfaceImplementerRule |
| 744 | + |
| 745 | +Interface "%s" has only single implementer. Consider using the class directly as there is no point in using the interface. |
| 746 | + |
| 747 | +- class: [`Symplify\PHPStanRules\Rules\NoSingleInterfaceImplementerRule`](../src/Rules/NoSingleInterfaceImplementerRule.php) |
| 748 | + |
| 749 | +```php |
| 750 | +class SomeClass implements SomeInterface |
| 751 | +{ |
| 752 | +} |
| 753 | + |
| 754 | +interface SomeInterface |
| 755 | +{ |
| 756 | +} |
| 757 | +``` |
| 758 | + |
| 759 | +:x: |
| 760 | + |
| 761 | +<br> |
| 762 | + |
| 763 | +```php |
| 764 | +class SomeClass implements SomeInterface |
| 765 | +{ |
| 766 | +} |
| 767 | + |
| 768 | +class AnotherClass implements SomeInterface |
| 769 | +{ |
| 770 | +} |
| 771 | + |
| 772 | +interface SomeInterface |
| 773 | +{ |
| 774 | +} |
| 775 | +``` |
| 776 | + |
| 777 | +:+1: |
| 778 | + |
| 779 | +<br> |
| 780 | + |
645 | 781 | ## NoTestMocksRule |
646 | 782 |
|
647 | 783 | Mocking "%s" class is forbidden. Use direct/anonymous class instead for better static analysis |
|
0 commit comments