Skip to content

Commit 8f85300

Browse files
committed
add rules
1 parent ab1d4fe commit 8f85300

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

README.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1769,6 +1769,75 @@ rules:
17691769

17701770
<br>
17711771

1772+
### NoBareAndSecurityIsGrantedContentsRule
1773+
1774+
Instead of using one long "and" condition join, split into multiple standalone #[IsGranted] attributes
1775+
1776+
```yaml
1777+
rules:
1778+
- Symplify\PHPStanRules\Rules\Symfony\NoBareAndSecurityIsGrantedContentsRule
1779+
```
1780+
1781+
```php
1782+
use Symfony\Component\Security\Http\Attribute\IsGranted;
1783+
1784+
#[IsGranted('has_role(ROLE_USER) and has_role(ROLE_ADMIN)')]
1785+
class SomeController
1786+
{
1787+
}
1788+
```
1789+
1790+
:x:
1791+
1792+
<br>
1793+
1794+
```php
1795+
use Symfony\Component\Security\Http\Attribute\IsGranted;
1796+
1797+
#[IsGranted('ROLE_USER')]
1798+
#[IsGranted('ROLE_ADMIN')]
1799+
class SomeController
1800+
{
1801+
}
1802+
```
1803+
1804+
:+1:
1805+
1806+
1807+
### RequireIsGrantedEnumRule
1808+
1809+
Instead of string, use enum constant for #[IsGranted]
1810+
1811+
```yaml
1812+
rules:
1813+
- Symplify\PHPStanRules\Rules\Symfony\RequireIsGrantedEnumRule
1814+
```
1815+
1816+
```php
1817+
use Symfony\Component\Security\Http\Attribute\IsGranted;
1818+
1819+
#[IsGranted('ROLE_USER')]
1820+
class SomeController
1821+
{
1822+
}
1823+
```
1824+
1825+
:x:
1826+
1827+
<br>
1828+
1829+
```php
1830+
use Symfony\Component\Security\Http\Attribute\IsGranted;
1831+
1832+
#[IsGranted(SomeEnum::ROLE_USER)]
1833+
class SomeController
1834+
{
1835+
}
1836+
```
1837+
1838+
:+1:
1839+
1840+
17721841
### NoRoutingPrefixRule
17731842

17741843
Avoid global route prefixing. Use single place for paths in @Route/#[Route] and improve static analysis instead.

0 commit comments

Comments
 (0)