Skip to content

Commit 54a0a2f

Browse files
committed
Split long regex over multiple lines
1 parent 9edf3c6 commit 54a0a2f

26 files changed

+349
-61
lines changed

src/Assert/ByteTrait.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,30 @@
1212
trait ByteTrait
1313
{
1414
/** @var string */
15-
private static string $byte_regex = '/^(((-[0]*([0-9]|[1-8][0-9]|9[0-9]|1[01][0-9]|12[0-8]))|([+]?[0]*([0-9]|[1-8][0-9]|9[0-9]|1[01][0-9]|12[0-7]))|0))$/D';
15+
private static string $byte_regex = '/^
16+
(
17+
(
18+
(
19+
-[0]*
20+
(
21+
[0-9]
22+
|[1-8]\d
23+
|9\d
24+
|1[01]\d
25+
|12[0-8]
26+
)
27+
)|(
28+
[+]?[0]*
29+
(
30+
[0-9]
31+
|[1-8]\d
32+
|9\d
33+
|1[01]\d
34+
|12[0-7]
35+
)
36+
)|0
37+
)
38+
)$/Dx';
1639

1740

1841
/**

src/Assert/DateTimeTrait.php

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,34 @@ trait DateTimeTrait
3333
*
3434
* @var string
3535
*/
36-
private static string $datetime_regex = '/^-?([1-9][0-9]*|[0-9]{4})-(((0(1|3|5|7|8)|1(0|2))-(0[1-9]|(1|2)[0-9]|3[0-1]))|((0(4|6|9)|11)-(0[1-9]|(1|2)[0-9]|30))|(02-(0[1-9]|(1|2)[0-9])))T([0-1][0-9]|2[0-4]):(0[0-9]|[1-5][0-9]):(0[0-9]|[1-5][0-9])(\.[0-9]{0,6})?((\+|-)([0-1][0-9]|2[0-4]):(0[0-9]|[1-5][0-9])|Z)?$/Di';
37-
38-
/***********************************************************************************
39-
* NOTE: Custom assertions may be added below this line. *
40-
* They SHOULD be marked as `protected` to ensure the call is forced *
41-
* through __callStatic(). *
42-
* Assertions marked `public` are called directly and will *
43-
* not handle any custom exception passed to it. *
44-
***********************************************************************************/
36+
private static string $datetime_regex = '/^
37+
-?
38+
([1-9][0-9]*|[0-9]{4})
39+
-
40+
(
41+
(
42+
(0(1|3|5|7|8)|1(0|2))
43+
-
44+
(0[1-9]|(1|2)[0-9]|3[0-1])
45+
)|
46+
(
47+
(0(4|6|9)|11)
48+
-
49+
(0[1-9]|(1|2)[0-9]|30)
50+
)|
51+
(02-(0[1-9]|(1|2)[0-9]))
52+
)
53+
T
54+
([0-1][0-9]|2[0-4])
55+
:(0[0-9]|[1-5][0-9])
56+
:(0[0-9]|[1-5][0-9])
57+
(\.[0-9]{0,6})?
58+
(
59+
[+-]([0-1][0-9]|2[0-4])
60+
:(0[0-9]|[1-5][0-9])
61+
|Z
62+
)?
63+
$/Dx';
4564

4665

4766
/**

src/Assert/DateTrait.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,22 @@ trait DateTrait
2424
*
2525
* @var string
2626
*/
27-
private static string $date_regex = '/^-?([1-9][0-9]*|[0-9]{4})-(((0(1|3|5|7|8)|1(0|2))-(0[1-9]|(1|2)[0-9]|3[0-1]))|((0(4|6|9)|11)-(0[1-9]|(1|2)[0-9]|30))|(02-(0[1-9]|(1|2)[0-9])))((\+|-)([0-1][0-9]|2[0-4]):(0[0-9]|[1-5][0-9])|Z)?$/Di';
27+
private static string $date_regex = '/^
28+
-?
29+
([1-9][0-9]*|[0-9]{4})
30+
-
31+
(
32+
((0(1|3|5|7|8)|1(0|2))-(0[1-9]|(1|2)[0-9]|3[0-1]))
33+
|((0(4|6|9)|11)-(0[1-9]|(1|2)[0-9]|30))
34+
|(02-(0[1-9]|(1|2)[0-9]))
35+
)
36+
(
37+
([+-]
38+
([0-1][0-9]|2[0-4])
39+
:
40+
(0[0-9]|[1-5][0-9])
41+
)|Z
42+
)?$/Dx';
2843

2944

3045
/**

src/Assert/DayTrait.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ trait DayTrait
1616
*
1717
* @var string
1818
*/
19-
private static string $day_regex = '/^---(0[1-9]|1[1-9]|2[1-9]|3[01])((\+|-)([0-1][0-9]|2[0-4]):(0[0-9]|[1-5][0-9])|Z)?$/Di';
19+
private static string $day_regex = '/^
20+
---
21+
(0[1-9]|1[1-9]|2[1-9]|3[01])
22+
([+-]([0-1][0-9]|2[0-4]):(0[0-9]|[1-5][0-9])|Z)
23+
?$/Dx';
2024

2125

2226
/**

src/Assert/DecimalTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
trait DecimalTrait
1313
{
1414
/** @var string */
15-
private static string $decimal_regex = '/^[+-]?((\d+(\.\d*)?)|(\.\d+))$/';
15+
private static string $decimal_regex = '/^[+-]?((\d+(\.\d*)?)|(\.\d+))$/D';
1616

1717
/**
1818
* @param string $value

src/Assert/DoubleTrait.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@
1212
trait DoubleTrait
1313
{
1414
/** @var string */
15-
private static string $double_regex = '/^(([+-]?([0-9]+[.][0-9]*|[.][0-9]+)([e][+-]?[0-9]+)?)|NaN|[-]?FIN)$/D';
15+
private static string $double_regex = '/^
16+
(
17+
([+-]?([0-9]+[.][0-9]*|[.][0-9]+)([e][+-]?[0-9]+)?)
18+
|NaN
19+
|[-]?FIN
20+
)$/Dx';
1621

1722
/**
1823
* @param string $value

src/Assert/DurationTrait.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,18 @@
1212
trait DurationTrait
1313
{
1414
/** @var string */
15-
private static string $duration_regex = '/^([-+]?)P(?!$)(?:(?<years>\d+(?:[\.\,]\d+)?)Y)?(?:(?<months>\d+(?:[\.\,]\d+)?)M)?(?:(?<weeks>\d+(?:[\.\,]\d+)?)W)?(?:(?<days>\d+(?:[\.\,]\d+)?)D)?(T(?=\d)(?:(?<hours>\d+(?:[\.\,]\d+)?)H)?(?:(?<minutes>\d+(?:[\.\,]\d+)?)M)?(?:(?<seconds>\d+(?:[\.\,]\d+)?)S)?)?$/D';
15+
private static string $duration_regex = '/^
16+
([-+]?)
17+
P
18+
(?!$)
19+
(?:(?<years>\d+(?:[\.\,]\d+)?)Y)?
20+
(?:(?<months>\d+(?:[\.\,]\d+)?)M)?
21+
(?:(?<weeks>\d+(?:[\.\,]\d+)?)W)?
22+
(?:(?<days>\d+(?:[\.\,]\d+)?)D)?
23+
(T(?=\d)(?:(?<hours>\d+(?:[\.\,]\d+)?)H)?
24+
(?:(?<minutes>\d+(?:[\.\,]\d+)?)M)?
25+
(?:(?<seconds>\d+(?:[\.\,]\d+)?)S)?)?
26+
$/Dx';
1627

1728

1829
/**

src/Assert/EntitiesTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
trait EntitiesTrait
1313
{
1414
/** @var string */
15-
private static string $entities_regex = '/^([a-zA-Z_][\w.-]*)([\s][a-zA-Z_][\w.-]*)*$/Du';
15+
private static string $entities_regex = '/^([a-z_][\w.-]*)([\s][a-z_][\w.-]*)*$/Dui';
1616

1717

1818
/**

src/Assert/HexBinaryTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
trait HexBinaryTrait
1313
{
1414
/** @var string */
15-
private static string $hexbin_regex = '/^([0-9a-fA-F]{2})+$/D';
15+
private static string $hexbin_regex = '/^([0-9a-f]{2})+$/Di';
1616

1717

1818
/**

src/Assert/IDRefsTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
trait IDRefsTrait
1313
{
1414
/** @var string */
15-
private static string $idrefs_regex = '/^([a-zA-Z_][\w.-]*)([\s][a-zA-Z_][\w.-]*)*$/Du';
15+
private static string $idrefs_regex = '/^([a-z_][\w.-]*)([\s][a-z_][\w.-]*)*$/Dui';
1616

1717

1818
/**

0 commit comments

Comments
 (0)