Skip to content

Commit 7c27cdd

Browse files
authored
Merge pull request #869 from phpDocumentor/task/document-regex
[TASK] Enforce REGEX Documentation
2 parents 31e9248 + ad33dd8 commit 7c27cdd

File tree

6 files changed

+69
-7
lines changed

6 files changed

+69
-7
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
"rector/rector": "^1.0.1",
6767
"squizlabs/php_codesniffer": "^3.9",
6868
"symfony/finder": "^6.4.0 || ^7.0",
69+
"symplify/phpstan-rules": "^12.4",
6970
"vimeo/psalm": "^5.22"
7071
},
7172
"suggest": {

composer.lock

Lines changed: 56 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/guides-restructured-text/src/RestructuredText/Directives/SectionauthorDirective.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
final class SectionauthorDirective extends BaseDirective
2525
{
26+
/** @see https://regex101.com/r/vGy4Uu/1 */
2627
public const NAME_EMAIL_REGEX = '/^(?P<name>[\w\s]+)(?: <(?P<email>[^>]+)>)?$/';
2728

2829
public function __construct(

packages/guides-restructured-text/src/RestructuredText/Parser/Productions/ListRule.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,11 @@ final class ListRule implements Rule
4444
/**
4545
* A regex matching all bullet list markers and a subset of the enumerated list markers.
4646
*
47+
* @see https://regex101.com/r/LBXWFV/1
4748
* @see https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html#bullet-lists
4849
* @see https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html#enumerated-lists
4950
*/
50-
private const LIST_MARKER = '/
51+
private const LIST_MARKER_REGEX = '/
5152
^(
5253
[-+*\x{2022}\x{2023}\x{2043}] # match bullet list markers: "*", "+", "-", "•", "‣", or "⁃"
5354
)
@@ -120,13 +121,13 @@ private function isListLine(string|null $line): bool
120121
return false;
121122
}
122123

123-
return preg_match(self::LIST_MARKER, $line) > 0;
124+
return preg_match(self::LIST_MARKER_REGEX, $line) > 0;
124125
}
125126

126127
/** @return array{marker: string, indenting: int} */
127128
public function getItemConfig(string $line): array
128129
{
129-
$isList = preg_match(self::LIST_MARKER, $line, $m) > 0;
130+
$isList = preg_match(self::LIST_MARKER_REGEX, $line, $m) > 0;
130131
if (!$isList) {
131132
throw new InvalidArgumentException('Line is not a valid item line');
132133
}
@@ -143,7 +144,7 @@ private function isListItemStart(string|null $line, string|null $listMarker = nu
143144
return false;
144145
}
145146

146-
$isList = preg_match(self::LIST_MARKER, $line, $m) > 0;
147+
$isList = preg_match(self::LIST_MARKER_REGEX, $line, $m) > 0;
147148
if (!$isList) {
148149
return false;
149150
}

packages/guides/src/UriFactory.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
//TODO remove this, as it is copied form phpDocumentor to make things work.
3131
final class UriFactory
3232
{
33-
public const WINDOWS_URI_FORMAT = '~^(file:\/\/\/)?(?<root>[a-zA-Z][:|\|])~';
33+
/** @see https://regex101.com/r/4UN6ZR/1 */
34+
public const WINDOWS_URI_FORMAT_REGEX = '~^(file:\/\/\/)?(?<root>[a-zA-Z][:|\|])~';
3435

3536
public static function createUri(string $uriString): UriInterface
3637
{
@@ -40,7 +41,7 @@ public static function createUri(string $uriString): UriInterface
4041
return self::createPharUri($uriString);
4142
}
4243

43-
if (preg_match(self::WINDOWS_URI_FORMAT, $uriString)) {
44+
if (preg_match(self::WINDOWS_URI_FORMAT_REGEX, $uriString)) {
4445
if (str_starts_with($uriString, 'file:///')) {
4546
$uriString = substr($uriString, strlen('file:///'));
4647
}

phpstan.neon

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
includes:
22
- phpstan-baseline.neon
3+
rules:
4+
- Symplify\PHPStanRules\Rules\AnnotateRegexClassConstWithRegexLinkRule
5+
- Symplify\PHPStanRules\Rules\RegexSuffixInRegexConstantRule
36
parameters:
47
level: max
58

0 commit comments

Comments
 (0)