Skip to content

Commit

Permalink
Split long regex over multiple lines
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdijen committed Jan 16, 2025
1 parent 9edf3c6 commit 54a0a2f
Show file tree
Hide file tree
Showing 26 changed files with 349 additions and 61 deletions.
25 changes: 24 additions & 1 deletion src/Assert/ByteTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,30 @@
trait ByteTrait
{
/** @var string */
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';
private static string $byte_regex = '/^
(
(
(
-[0]*
(
[0-9]
|[1-8]\d
|9\d
|1[01]\d
|12[0-8]
)
)|(
[+]?[0]*
(
[0-9]
|[1-8]\d
|9\d
|1[01]\d
|12[0-7]
)
)|0
)
)$/Dx';


/**
Expand Down
37 changes: 28 additions & 9 deletions src/Assert/DateTimeTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,34 @@ trait DateTimeTrait
*
* @var string
*/
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';

/***********************************************************************************
* NOTE: Custom assertions may be added below this line. *
* They SHOULD be marked as `protected` to ensure the call is forced *
* through __callStatic(). *
* Assertions marked `public` are called directly and will *
* not handle any custom exception passed to it. *
***********************************************************************************/
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
)?
$/Dx';


/**
Expand Down
17 changes: 16 additions & 1 deletion src/Assert/DateTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,22 @@ trait DateTrait
*
* @var string
*/
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';
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
)?$/Dx';


/**
Expand Down
6 changes: 5 additions & 1 deletion src/Assert/DayTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ trait DayTrait
*
* @var string
*/
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';
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)
?$/Dx';


/**
Expand Down
2 changes: 1 addition & 1 deletion src/Assert/DecimalTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
trait DecimalTrait
{
/** @var string */
private static string $decimal_regex = '/^[+-]?((\d+(\.\d*)?)|(\.\d+))$/';
private static string $decimal_regex = '/^[+-]?((\d+(\.\d*)?)|(\.\d+))$/D';

/**
* @param string $value
Expand Down
7 changes: 6 additions & 1 deletion src/Assert/DoubleTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@
trait DoubleTrait
{
/** @var string */
private static string $double_regex = '/^(([+-]?([0-9]+[.][0-9]*|[.][0-9]+)([e][+-]?[0-9]+)?)|NaN|[-]?FIN)$/D';
private static string $double_regex = '/^
(
([+-]?([0-9]+[.][0-9]*|[.][0-9]+)([e][+-]?[0-9]+)?)
|NaN
|[-]?FIN
)$/Dx';

/**
* @param string $value
Expand Down
13 changes: 12 additions & 1 deletion src/Assert/DurationTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,18 @@
trait DurationTrait
{
/** @var string */
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';
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)?)?
$/Dx';


/**
Expand Down
2 changes: 1 addition & 1 deletion src/Assert/EntitiesTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
trait EntitiesTrait
{
/** @var string */
private static string $entities_regex = '/^([a-zA-Z_][\w.-]*)([\s][a-zA-Z_][\w.-]*)*$/Du';
private static string $entities_regex = '/^([a-z_][\w.-]*)([\s][a-z_][\w.-]*)*$/Dui';


/**
Expand Down
2 changes: 1 addition & 1 deletion src/Assert/HexBinaryTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
trait HexBinaryTrait
{
/** @var string */
private static string $hexbin_regex = '/^([0-9a-fA-F]{2})+$/D';
private static string $hexbin_regex = '/^([0-9a-f]{2})+$/Di';


/**
Expand Down
2 changes: 1 addition & 1 deletion src/Assert/IDRefsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
trait IDRefsTrait
{
/** @var string */
private static string $idrefs_regex = '/^([a-zA-Z_][\w.-]*)([\s][a-zA-Z_][\w.-]*)*$/Du';
private static string $idrefs_regex = '/^([a-z_][\w.-]*)([\s][a-z_][\w.-]*)*$/Dui';


/**
Expand Down
33 changes: 32 additions & 1 deletion src/Assert/IntTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,38 @@
trait IntTrait
{
/** @var string */
private static string $int_regex = '/^((([-+]?[0]*)(?:[1-9]|214748364[0-7]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]|1[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]|20[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]|21[0-3][0-9][0-9][0-9][0-9][0-9][0-9][0-9]|214[0-6][0-9][0-9][0-9][0-9][0-9][0-9]|2147[0-3][0-9][0-9][0-9][0-9][0-9]|21474[0-7][0-9][0-9][0-9][0-9]|214748[0-2][0-9][0-9][0-9]|2147483[0-5][0-9][0-9]|21474836[0-3][0-9]|[0-9]|214748364[0-7]))|0|((-([0]*)?)2147483648))$/D';
private static string $int_regex = '/^
(
(
([-+]?[0]*)
(?:
[1-9]
|214748364[0-7]
|[1-9][0-9]
|[1-9][0-9][0-9]
|[1-9][0-9][0-9][0-9]
|[1-9][0-9][0-9][0-9][0-9]
|[1-9][0-9][0-9][0-9][0-9][0-9]
|[1-9][0-9][0-9][0-9][0-9][0-9][0-9]
|[1-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]
|[1-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]
|1[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]
|20[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]
|21[0-3][0-9][0-9][0-9][0-9][0-9][0-9][0-9]
|214[0-6][0-9][0-9][0-9][0-9][0-9][0-9]
|2147[0-3][0-9][0-9][0-9][0-9][0-9]
|21474[0-7][0-9][0-9][0-9][0-9]
|214748[0-2][0-9][0-9][0-9]
|2147483[0-5][0-9][0-9]
|21474836[0-3][0-9]
|[0-9]
|214748364[0-7]
)
)|
0|
((-([0]*)?)2147483648)
)
$/Dx';

/**
* @param string $value
Expand Down
32 changes: 31 additions & 1 deletion src/Assert/LongTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,37 @@
trait LongTrait
{
/** @var string */
private static string $long_regex = '/^(([-+]?[0]*)?(?:[1-9]|[1-9]\d{1,14}|1000000000000000|1000000000000000[1-9]|10000000000000000[1-9]|[1-8][1-9]\d{17}|9[01]\d{17}|92[01]\d{16}|922[0-2]\d{15}|9223[0-2]\d{14}|92233[0-6]\d{13}|922337[01]\d{12}|92233720[0-2]\d{10}|922337203[0-5]\d{9}|9223372036[0-7]\d{8}|92233720368[0-4]\d{7}|922337203685[0-3]\d{6}|9223372036854[0-6]\d{5}|92233720368547[0-6]\d{4}|922337203685477[0-4]\d{3}|9223372036854775[0-7]\d{2}|922337203685477580[0-7])|0|(-([0]*)?)9223372036854775808)$/D';
private static string $long_regex = '/^
(
([-+]?[0]*)?
(?:
[1-9]
|[1-9]\d{1,14}
|1000000000000000
|1000000000000000[1-9]
|10000000000000000[1-9]
|[1-8][1-9]\d{17}
|9[01]\d{17}
|92[01]\d{16}
|922[0-2]\d{15}
|9223[0-2]\d{14}
|92233[0-6]\d{13}
|922337[01]\d{12}
|92233720[0-2]\d{10}
|922337203[0-5]\d{9}
|9223372036[0-7]\d{8}
|92233720368[0-4]\d{7}
|922337203685[0-3]\d{6}
|9223372036854[0-6]\d{5}
|92233720368547[0-6]\d{4}
|922337203685477[0-4]\d{3}
|9223372036854775[0-7]\d{2}
|922337203685477580[0-7]
)
|0
|(-([0]*)?)9223372036854775808
)
$/Dx';

/**
* @param string $value
Expand Down
2 changes: 1 addition & 1 deletion src/Assert/MonthTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ trait MonthTrait
*
* @var string
*/
private static string $month_regex = '/^--(0[1-9]|1[012])((\+|-)([0-1][0-9]|2[0-4]):(0[0-9]|[1-5][0-9])|Z)?$/Di';
private static string $month_regex = '/^--(0[1-9]|1[012])((\+|-)([0-1][0-9]|2[0-4]):(0[0-9]|[1-5][0-9])|Z)?$/D';


/**
Expand Down
2 changes: 1 addition & 1 deletion src/Assert/NCNameTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
trait NCNameTrait
{
/** @var string */
private static string $ncname_regex = '/^[a-zA-Z_][\w.-]*$/Du';
private static string $ncname_regex = '/^[a-z_][\w.-]*$/Dui';


/**
Expand Down
2 changes: 1 addition & 1 deletion src/Assert/NameTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
trait NameTrait
{
/** @var string */
private static string $name_regex = '/^[a-zA-Z:-][\w.:-]+$/Du';
private static string $name_regex = '/^[a-z:-][\w.:-]+$/Dui';


/**
Expand Down
10 changes: 1 addition & 9 deletions src/Assert/QNameTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,7 @@
trait QNameTrait
{
/** @var string */
private static string $qname_regex = '/^([a-z_][\w.-]*)(:[a-z_][\w.-]*)?$/Dui';

/***********************************************************************************
* NOTE: Custom assertions may be added below this line. *
* They SHOULD be marked as `protected` to ensure the call is forced *
* through __callStatic(). *
* Assertions marked `public` are called directly and will *
* not handle any custom exception passed to it. *
***********************************************************************************/
private static string $qname_regex = '/^([a-z_][\w.-]*)(:[a-z_][\w.-]*)?$/Di';


/**
Expand Down
23 changes: 22 additions & 1 deletion src/Assert/ShortTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,28 @@
trait ShortTrait
{
/** @var string */
private static string $short_regex = '/^((([+-]?0*)(?:[1-9]|3276[0-7]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[12][0-9][0-9][0-9][0-9]|3[01][0-9][0-9][0-9]|32[0-6][0-9][0-9]|327[0-5][0-9]|[0-9]|3276[0-7]))|0|((-0*)32768))$/D';
private static string $short_regex = '/^
(
(
([+-]?0*)
(?:
[1-9]
|3276[0-7]
|[1-9][0-9]
|[1-9][0-9][0-9]
|[1-9][0-9][0-9][0-9]
|[12][0-9][0-9][0-9][0-9]
|3[01][0-9][0-9][0-9]
|32[0-6][0-9][0-9]
|327[0-5][0-9]
|[0-9]
|3276[0-7]
)
)
|0
|((-0*)32768)
)
$/Dx';


/**
Expand Down
9 changes: 8 additions & 1 deletion src/Assert/TimeTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@
trait TimeTrait
{
/** @var string */
private static string $time_regex = '/^([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';
private static string $time_regex = '/^
([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)?
$/Dx';


/**
Expand Down
21 changes: 20 additions & 1 deletion src/Assert/UnsignedIntTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,26 @@
trait UnsignedIntTrait
{
/** @var string */
private static string $unsignedInt_regex = '/^(([+]?0*)(?:[1-9]|[1-9]\d{1,8}|[1-3]\d{9}|4[01]\d{8}|42[0-8]\d{7}|429[0-3]\d{6}|4294[0-8]\d{5}|42949[0-5]\d{4}|429496[0-6]\d{3}|4294967[01]\d{2}|42949672[0-8]\d|429496729[0-5])|0)$/D';
private static string $unsignedInt_regex = '/^
(
([+]?0*)
(?:
[1-9]
|[1-9]\d{1,8}
|[1-3]\d{9}
|4[01]\d{8}
|42[0-8]\d{7}
|429[0-3]\d{6}
|4294[0-8]\d{5}
|42949[0-5]\d{4}
|429496[0-6]\d{3}
|4294967[01]\d{2}
|42949672[0-8]\d
|429496729[0-5]
)
|0
)
$/Dx';


/**
Expand Down
Loading

0 comments on commit 54a0a2f

Please sign in to comment.