Skip to content

Commit 0ffb1c0

Browse files
authored
[deprecated] Drop regex rules, as too nitpicking, in times of GPT pointless (#151)
* [deprecated] Drop regex rules, as too nitpicking, in times of GPT pointless * [docs] avoid using sets as too complicated and bloated, use particular rules instead
1 parent 2eacb49 commit 0ffb1c0

29 files changed

+2
-916
lines changed

README.md

Lines changed: 2 additions & 160 deletions
Original file line numberDiff line numberDiff line change
@@ -16,84 +16,9 @@ composer require symplify/phpstan-rules --dev
1616

1717
<br>
1818

19-
## A. Add Prepared Sets
19+
## Register Rules you Need
2020

21-
Sets are bunch of rules grouped by a common area, e.g. improve naming. You can pick from 5 sets:
22-
23-
```yaml
24-
includes:
25-
- vendor/symplify/phpstan-rules/config/code-complexity-rules.neon
26-
- vendor/symplify/phpstan-rules/config/naming-rules.neon
27-
- vendor/symplify/phpstan-rules/config/regex-rules.neon
28-
- vendor/symplify/phpstan-rules/config/static-rules.neon
29-
```
30-
31-
<br>
32-
33-
## B. Cherry-pick Configurable Rules
34-
35-
There is one set with pre-configured configurable rules. Include it and see what is errors are found:
36-
37-
```yaml
38-
# phpstan.neon
39-
includes:
40-
- vendor/symplify/phpstan-rules/config/configurable-rules.neon
41-
```
42-
43-
<br>
44-
45-
Would you like to tailor it to fit your taste? Pick one PHPStan rule and configure it manually ↓
46-
47-
```yaml
48-
services:
49-
-
50-
class: Symplify\PHPStanRules\Rules\ForbiddenNodeRule
51-
tags: [phpstan.rules.rule]
52-
arguments:
53-
forbiddenNodes:
54-
- PhpParser\Node\Expr\Empty_
55-
- PhpParser\Node\Stmt\Switch_
56-
```
57-
58-
<br>
59-
60-
## 3. Register Particular Rules
61-
62-
<br>
63-
64-
# 30 Rules Overview
65-
66-
## AnnotateRegexClassConstWithRegexLinkRule
67-
68-
Add regex101.com link to that shows the regex in practise, so it will be easier to maintain in case of bug/extension in the future
69-
70-
```yaml
71-
rules:
72-
- Symplify\PHPStanRules\Rules\AnnotateRegexClassConstWithRegexLinkRule
73-
```
74-
75-
```php
76-
class SomeClass
77-
{
78-
private const COMPLICATED_REGEX = '#some_complicated_stu|ff#';
79-
}
80-
```
81-
82-
:x:
83-
84-
<br>
85-
86-
```php
87-
class SomeClass
88-
{
89-
/**
90-
* @see https://regex101.com/r/SZr0X5/12
91-
*/
92-
private const COMPLICATED_REGEX = '#some_complicated_stu|ff#';
93-
}
94-
```
95-
96-
:+1:
21+
Pick from 25+ rules:
9722

9823
<br>
9924

@@ -562,48 +487,6 @@ class SomeClass
562487

563488
<br>
564489

565-
## NoInlineStringRegexRule
566-
567-
Use local named constant instead of inline string for regex to explain meaning by constant name
568-
569-
```yaml
570-
rules:
571-
- Symplify\PHPStanRules\Rules\NoInlineStringRegexRule
572-
```
573-
574-
```php
575-
class SomeClass
576-
{
577-
public function run($value)
578-
{
579-
return preg_match('#some_stu|ff#', $value);
580-
}
581-
}
582-
```
583-
584-
:x:
585-
586-
<br>
587-
588-
```php
589-
class SomeClass
590-
{
591-
/**
592-
* @var string
593-
*/
594-
public const SOME_STUFF_REGEX = '#some_stu|ff#';
595-
596-
public function run($value)
597-
{
598-
return preg_match(self::SOME_STUFF_REGEX, $value);
599-
}
600-
}
601-
```
602-
603-
:+1:
604-
605-
<br>
606-
607490
## NoReferenceRule
608491

609492
Use explicit return value over magic &reference
@@ -895,47 +778,6 @@ class SomeClass extends SomeParentClass
895778

896779
<br>
897780

898-
## RegexSuffixInRegexConstantRule
899-
900-
Name your constant with "_REGEX" suffix, instead of "%s"
901-
902-
```yaml
903-
rules:
904-
- Symplify\PHPStanRules\Rules\RegexSuffixInRegexConstantRule
905-
```
906-
907-
```php
908-
class SomeClass
909-
{
910-
public const SOME_NAME = '#some\s+name#';
911-
912-
public function run($value)
913-
{
914-
$somePath = preg_match(self::SOME_NAME, $value);
915-
}
916-
}
917-
```
918-
919-
:x:
920-
921-
<br>
922-
923-
```php
924-
class SomeClass
925-
{
926-
public const SOME_NAME_REGEX = '#some\s+name#';
927-
928-
public function run($value)
929-
{
930-
$somePath = preg_match(self::SOME_NAME_REGEX, $value);
931-
}
932-
}
933-
```
934-
935-
:+1:
936-
937-
<br>
938-
939781
## RequireAttributeNameRule
940782

941783
Attribute must have all names explicitly defined

config/regex-rules.neon

Lines changed: 0 additions & 4 deletions
This file was deleted.

config/services/services.neon

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ services:
99
- Symplify\PHPStanRules\Naming\ClassToSuffixResolver
1010
- Symplify\PHPStanRules\NodeAnalyzer\AttributeFinder
1111
- Symplify\PHPStanRules\NodeAnalyzer\EnumAnalyzer
12-
- Symplify\PHPStanRules\NodeAnalyzer\RegexFuncCallAnalyzer
13-
- Symplify\PHPStanRules\NodeAnalyzer\RegexStaticCallAnalyzer
1412
- Symplify\PHPStanRules\ParentClassMethodNodeResolver
1513
- Symplify\PHPStanRules\PhpDoc\BarePhpDocParser
1614
- Symplify\PHPStanRules\PhpDoc\PhpDocResolver

config/symplify-rules.neon

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@ includes:
22
- code-complexity-rules.neon
33
- configurable-rules.neon
44
- naming-rules.neon
5-
- regex-rules.neon
65
- static-rules.neon

src/Enum/ClassName.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@ final class ClassName
1111
*/
1212
public const ROUTE_ATTRIBUTE = 'Symfony\Component\Routing\Annotation\Route';
1313

14-
/**
15-
* @var string
16-
*/
17-
public const NETTE_STRINGS = 'Nette\Utils\Strings';
18-
1914
/**
2015
* @var string
2116
*/

src/Enum/RuleIdentifier.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@ final class RuleIdentifier
1616
*/
1717
public const SEE_ANNOTATION_TO_TEST = 'symplify.seeAnnotationToTest';
1818

19-
/**
20-
* @var string
21-
*/
22-
public const REGEX_SUFFIX_IN_REGEX_CONSTANT = 'symplify.regexSuffixInRegexConstant';
23-
2419
/**
2520
* @var string
2621
*/
@@ -66,11 +61,6 @@ final class RuleIdentifier
6661
*/
6762
public const PARENT_METHOD_VISIBILITY_OVERRIDE = 'symplify.parentMethodVisibilityOverride';
6863

69-
/**
70-
* @var string
71-
*/
72-
public const CLASS_CONSTANT_REGEX = 'symplify.classConstantRegex';
73-
7464
/**
7565
* @var string
7666
*/
@@ -126,11 +116,6 @@ final class RuleIdentifier
126116
*/
127117
public const FORBIDDEN_ARRAY_METHOD_CALL = 'symplify.forbiddenArrayMethodCall';
128118

129-
/**
130-
* @var string
131-
*/
132-
public const REGEX_ANNOTATE_CLASS_CONST = 'symplify.regexAnnotateClassConst';
133-
134119
/**
135120
* @var string
136121
*/

src/NodeAnalyzer/RegexFuncCallAnalyzer.php

Lines changed: 0 additions & 32 deletions
This file was deleted.

src/NodeAnalyzer/RegexStaticCallAnalyzer.php

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)