3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types = 1); /** * Value object representing a time interval. * */ namespace TimeParser; use \DateInterval; class IntervalFlags { const INTERVAL_ONLY = 0b00000000; const REQUIRE_TRAILING = 0b00000001; const REQUIRE_LEADING = 0b00000010; const MULTIPLE_INTERVALS = 0b00000100; } class TimeInterval { private $intervalOffset; private $intervalLength; private $interval; private $leadingData; private $trailingData; public function __construct( int $intervalOffset, int $intervalLength, DateInterval $interval, string $leadingData = null, string $trailingData = null ) { $this->interval = $interval; $this->intervalOffset = $intervalOffset; $this->intervalLength = $intervalLength; $this->leadingData = $leadingData; $this->trailingData = $trailingData; } public function getInterval() : DateInterval { return $this->interval; } public function getIntervalOffset() : int { return $this->intervalOffset; } public function getIntervalLength() : int { return $this->intervalLength; } public function getLeadingData() : string { return $this->leadingData; } public function getTrailingData() : string { return $this->trailingData; } } class TimeParser { /** * Set of regular expressions utilized to match/replace/validate parts of a given input * * Thanks a ton to @bwoebi and @pcrov for helping out on all regexes <3 * * If leading text is required, it should separate time and text by in * ie. foo in 9 weeks 5 days * * @var string $separatorExpression */ private static $leadingDataSeparator = "/(.*)\s+(?:in)\s+(.*)/ui"; # Definitions of sub patterns for a valid interval private static $intervalSeparatorDefinitions = <<<'REGEX' /(?(DEFINE) (?<integer> (?:\G|(?!\n)) (\s*\b)? \d{1,5} \s* ) (?<timepart> (?&integer) ( s(ec(ond)?s?)? | m(on(ths?)?|in(ute)?s?)? | h(rs?|ours?)? | d(ays?)? | w(eeks?)? ) ) ) REGEX; # Concatenate with above definitions before its use private static $intervalOnly = "^(?<interval>(?&timepart)++)$/uix"; private static $intervalWithTrailingData = "^(?<interval>(?&timepart)++)(?<trailing>.+)$/uix"; /** * Used to turn a given non-strtotime-compatible time string into a compatible one within preg_replace_callback * Only modifies the non-strtotime-compatible time strings provided leaving the rest intact * This requires interval offset to be 0, meaning no leading data is allowed. * * @var string $normalizerExpression */ private static $normalizerExpression = <<<'REGEX' ~ # grab the integer part of time string \s? (?<int> \d{1,5}) \s? # match only the shortest abbreviations that aren't supported by strtotime (?<time> (?: s (?=(?:ec(?:ond)?s?)?(?:\b|\d)) | m (?=(?:in(?:ute)?s?)?(?:\b|\d)) | h (?=(?:(?:ou)?rs?)?(?:\b|\d)) | d (?=(?:ays?)?(?:\b|\d)) | w (?=(?:eeks?)?(?:\b|\d)) | mon (?=(?:(?:th)?s?)?(?:\b|\d)) ) ) [^\d]*?(?=\b|\d) # do only extract start of string | (?<text> .+) ~uix REGEX; /** * Looks for a valid interval along with leading and/or trailing data IF the respective flags are set. * TimeInterval is essentially DateInterval with extra information such as interval offset & length, leading/trailing data. * TODO: MULTIPLE_INTERVALS is not yet implemented. * * @param string $input * @param int $flags * @return TimeInterval * @throws \Error|\InvalidArgumentException */ public function findInterval(string $input, int $flags = IntervalFlags::INTERVAL_ONLY) : TimeInterval { if($flags & IntervalFlags::INTERVAL_ONLY){ # If interval contains non-strtotime-compatible abbreviations, replace 'em $input = $this->normalizeTimeInterval($input); if(preg_match(self::$intervalOnly, $input)){ $intervalOffset = 0; $intervalLength = strlen($input); # create and return the interval object $interval = DateInterval::createFromDateString($input); return new TimeInterval($intervalOffset, $intervalLength, $interval, null, null); } throw new \InvalidArgumentException("Given input is not a valid interval."); } if($flags == (IntervalFlags::REQUIRE_LEADING | IntervalFlags::REQUIRE_TRAILING)){ # Requires the "in" separator, TODO: allow at|this|next too $leadingSeparation = preg_match(self::$leadingDataSeparator, $input, $matches, PREG_OFFSET_CAPTURE); if(!$leadingSeparation){ throw new \Error("Allowing leading data requires using a separator. Ie. foo in <interval>"); } $leadingData = $matches[1][0] ?? null; $intervalAndTrailingData = $matches[2][0] ?? null; # throw early for missing parts if(!$leadingData){ throw new \InvalidArgumentException("Given input does not contain a valid leading data."); } if(!$intervalAndTrailingData){ throw new \InvalidArgumentException("Given input does not contain a valid interval and/or trailing data."); } $intervalOffset = $matches[2][1] ?? null; # If interval contains non-strtotime-compatible abbreviations, replace 'em $intervalAndTrailingData = $this->normalizeTimeInterval($intervalAndTrailingData); $expression = self::$intervalSeparatorDefinitions . self::$intervalWithTrailingData; if(preg_match($expression, $intervalAndTrailingData, $parts)){ $interval = $parts['interval']; $trailingData = $parts['trailing']; $intervalLength = strlen($interval); # create and return the interval object $interval = DateInterval::createFromDateString($interval); return new TimeInterval($intervalOffset, $intervalLength, $interval, $leadingData, $trailingData); } throw new \InvalidArgumentException("Given input does not contain a valid interval and/or trailing data."); } if($flags & IntervalFlags::REQUIRE_LEADING){ # Requires the "in" separator, TODO: allow at|this|next too $leadingSeparation = preg_match(self::$leadingDataSeparator, $input, $matches, PREG_OFFSET_CAPTURE); if(!$leadingSeparation){ throw new \Error("Allowing leading data requires using a separator. Ie. foo in <interval>"); } $leadingData = $matches[1][0] ?? null; $intervalAndPossibleTrailingData = $matches[2][0] ?? null; if(!$leadingData || !$intervalAndPossibleTrailingData){ throw new \Error("Could not find any valid interval and/or leading data."); } $intervalOffset = $matches[2][1] ?? null; # If interval contains non-strtotime-compatible abbreviations, replace 'em $safeInterval = $this->normalizeTimeInterval($intervalAndPossibleTrailingData); # since above normalization is expected to not return any trailing data, only check for a valid interval $expression = self::$intervalSeparatorDefinitions . self::$intervalOnly; if(preg_match($expression, $safeInterval, $parts)){ $interval = $parts['interval']; $intervalLength = strlen($interval); # create the interval object $interval = DateInterval::createFromDateString($interval); return new TimeInterval($intervalOffset, $intervalLength, $interval, $leadingData, null); } throw new \InvalidArgumentException("Given input does not contain a valid interval. Keep in mind trailing data is not allowed with currently specified flag."); } if($flags & IntervalFlags::REQUIRE_TRAILING){ $expression = self::$intervalSeparatorDefinitions . self::$intervalWithTrailingData; # If interval contains non-strtotime-compatible abbreviations, replace 'em $safeInterval = $this->normalizeTimeInterval($input); # Separate interval from trailing data if(preg_match($expression, $safeInterval, $parts)){ $trailingData = $parts['trailing'] ?? null; $interval = $parts['interval'] ?? null; if(!$trailingData || !$interval){ throw new \Error("Could not find any valid interval and/or trailing data..."); } $intervalLength = strlen($interval); $intervalOffset = 0; # since we don't allow leading data here # create the interval object $interval = DateInterval::createFromDateString($interval); return new TimeInterval($intervalOffset, $intervalLength, $interval, null, $trailingData); } throw new \InvalidArgumentException("Given input does not contain a valid interval. Keep in mind leading data is not allowed with currently specified flag."); } if($flags & IntervalFlags::MULTIPLE_INTERVALS){ throw new \Error("I'm sorry, multiple intervals is not allowed/implemented, yet."); } # This bit is not tested if( $flags & ~IntervalFlags::INTERVAL_ONLY & ~IntervalFlags::REQUIRE_TRAILING & ~IntervalFlags::REQUIRE_LEADING & ~IntervalFlags::MULTIPLE_INTERVALS ){ throw new \InvalidArgumentException("You have tried to use an invalid flag combination."); } } /** * Turns any non-strtotime-compatible time string into a compatible one. * If the passed input has trailing data, it won't be lost since within the callback the input is reassembled. * However no leading data is accepted. * * @param string $input * @return string */ public function normalizeTimeInterval(string $input): string { $output = preg_replace_callback(self::$normalizerExpression, function ($matches) { switch ($matches['time']) { case 's': $t = ' seconds '; break; case 'm': $t = ' minutes '; break; case 'h': $t = ' hours '; break; case 'd': $t = ' days '; break; case 'w': $t = ' weeks '; break; case 'mon': $t = ' months '; break; case 'y': $t = ' years '; break; } $t = $t ?? ''; # rebuild the interval string $time = $matches['int'] . $t; if(isset($matches['text'])){ $time .= $matches['text']; } return $time; }, $input); return trim($output); } /** * Normalizes any non-strtotime-compatible time string, then validates the interval and returns a DateInterval object. * No leading or trailing data is accepted. * * @param string $input * @return DateInterval * @throws \InvalidArgumentException */ public function parseInterval(string $input): \DateInterval { $input = trim($this->normalizeTimeInterval($input)); $expression = self::$intervalSeparatorDefinitions . self::$intervalOnly; if(preg_match($expression, $input, $matches)){ return DateInterval::createFromDateString($input); } throw new \InvalidArgumentException("Given string is not a valid time interval."); } } $trailingString = '7mon6w5d4h3m2s bazinga!'; $leadingString = 'foo in 9w8d7h6m5s'; $both = 'foo in 9d8h5m bar'; $onlyInterval = '9 mon 2 w 3 m 4 d'; $intervalParser = new TimeParser(); #$timeIntervalWithTrailingData = $intervalParser->findInterval($trailingString, IntervalFlags::REQUIRE_TRAILING); #var_dump($timeIntervalWithTrailingData); #$timeIntervalWithLeadingData = $intervalParser->findInterval($leadingString, IntervalFlags::REQUIRE_LEADING); #var_dump($timeIntervalWithLeadingData); #$timeIntervalWithBoth = $intervalParser->findInterval($both, IntervalFlags::REQUIRE_TRAILING | IntervalFlags::REQUIRE_LEADING); #var_dump($timeIntervalWithBoth); $dateInterval = $intervalParser->parseInterval($onlyInterval); var_dump($dateInterval);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AsnGn
function name:  (null)
number of ops:  15
compiled vars:  !0 = $trailingString, !1 = $leadingString, !2 = $both, !3 = $onlyInterval, !4 = $intervalParser, !5 = $dateInterval
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  358     0  E >   ASSIGN                                                   !0, '7mon6w5d4h3m2s+bazinga%21'
  359     1        ASSIGN                                                   !1, 'foo+in+9w8d7h6m5s'
  360     2        ASSIGN                                                   !2, 'foo+in+9d8h5m+bar'
  361     3        ASSIGN                                                   !3, '9+mon+2+w+3+m+4+d'
  363     4        NEW                                              $10     'TimeParser%5CTimeParser'
          5        DO_FCALL                                      0          
          6        ASSIGN                                                   !4, $10
  374     7        INIT_METHOD_CALL                                         !4, 'parseInterval'
          8        SEND_VAR_EX                                              !3
          9        DO_FCALL                                      0  $13     
         10        ASSIGN                                                   !5, $13
  375    11        INIT_NS_FCALL_BY_NAME                                    'TimeParser%5Cvar_dump'
         12        SEND_VAR_EX                                              !5
         13        DO_FCALL                                      0          
         14      > RETURN                                                   1

Function %00timeparser%5C%7Bclosure%7D%2Fin%2FAsnGn%3A295%240:
Finding entry points
Branch analysis from position: 0
9 jumps found. (Code = 188) Position 1 = 18, Position 2 = 20, Position 3 = 22, Position 4 = 24, Position 5 = 26, Position 6 = 28, Position 7 = 30, Position 8 = 32, Position 9 = 3
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 43
Branch analysis from position: 41
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 43
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
Branch analysis from position: 32
Branch analysis from position: 3
2 jumps found. (Code = 44) Position 1 = 5, Position 2 = 18
Branch analysis from position: 5
2 jumps found. (Code = 44) Position 1 = 7, Position 2 = 20
Branch analysis from position: 7
2 jumps found. (Code = 44) Position 1 = 9, Position 2 = 22
Branch analysis from position: 9
2 jumps found. (Code = 44) Position 1 = 11, Position 2 = 24
Branch analysis from position: 11
2 jumps found. (Code = 44) Position 1 = 13, Position 2 = 26
Branch analysis from position: 13
2 jumps found. (Code = 44) Position 1 = 15, Position 2 = 28
Branch analysis from position: 15
2 jumps found. (Code = 44) Position 1 = 17, Position 2 = 30
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
Branch analysis from position: 30
Branch analysis from position: 28
Branch analysis from position: 26
Branch analysis from position: 24
Branch analysis from position: 22
Branch analysis from position: 20
Branch analysis from position: 18
filename:       /in/AsnGn
function name:  TimeParser\{closure}
number of ops:  45
compiled vars:  !0 = $matches, !1 = $t, !2 = $time
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  295     0  E >   RECV                                             !0      
  296     1        FETCH_DIM_R                                      ~3      !0, 'time'
          2      > SWITCH_STRING                                            ~3, [ 's':->18, 'm':->20, 'h':->22, 'd':->24, 'w':->26, 'mon':->28, 'y':->30, ], ->32
  297     3    >   CASE                                                     ~3, 's'
          4      > JMPNZ                                                    ~4, ->18
  300     5    >   CASE                                                     ~3, 'm'
          6      > JMPNZ                                                    ~4, ->20
  303     7    >   CASE                                                     ~3, 'h'
          8      > JMPNZ                                                    ~4, ->22
  306     9    >   CASE                                                     ~3, 'd'
         10      > JMPNZ                                                    ~4, ->24
  309    11    >   CASE                                                     ~3, 'w'
         12      > JMPNZ                                                    ~4, ->26
  312    13    >   CASE                                                     ~3, 'mon'
         14      > JMPNZ                                                    ~4, ->28
  315    15    >   CASE                                                     ~3, 'y'
         16      > JMPNZ                                                    ~4, ->30
         17    > > JMP                                                      ->32
  298    18    >   ASSIGN                                                   !1, '+seconds+'
  299    19      > JMP                                                      ->32
  301    20    >   ASSIGN                                                   !1, '+minutes+'
  302    21      > JMP                                                      ->32
  304    22    >   ASSIGN                                                   !1, '+hours+'
  305    23      > JMP                                                      ->32
  307    24    >   ASSIGN                                                   !1, '+days+'
  308    25      > JMP                                                      ->32
  310    26    >   ASSIGN                                                   !1, '+weeks+'
  311    27      > JMP                                                      ->32
  313    28    >   ASSIGN                                                   !1, '+months+'
  314    29      > JMP                                                      ->32
  316    30    >   ASSIGN                                                   !1, '+years+'
  317    31      > JMP                                                      ->32
         32    >   FREE                                                     ~3
  320    33        COALESCE                                         ~12     !1
         34        QM_ASSIGN                                        ~12     ''
         35        ASSIGN                                                   !1, ~12
  322    36        FETCH_DIM_R                                      ~14     !0, 'int'
         37        CONCAT                                           ~15     ~14, !1
         38        ASSIGN                                                   !2, ~15
  324    39        ISSET_ISEMPTY_DIM_OBJ                         0          !0, 'text'
         40      > JMPZ                                                     ~17, ->43
  325    41    >   FETCH_DIM_R                                      ~18     !0, 'text'
         42        ASSIGN_OP                                     8          !2, ~18
  328    43    > > RETURN                                                   !2
  330    44*     > RETURN                                                   null

End of function %00timeparser%5C%7Bclosure%7D%2Fin%2FAsnGn%3A295%240

Class TimeParser\IntervalFlags: [no user functions]
Class TimeParser\TimeInterval:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AsnGn
function name:  __construct
number of ops:  16
compiled vars:  !0 = $intervalOffset, !1 = $intervalLength, !2 = $interval, !3 = $leadingData, !4 = $trailingData
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV_INIT                                        !3      null
          4        RECV_INIT                                        !4      null
   35     5        ASSIGN_OBJ                                               'interval'
          6        OP_DATA                                                  !2
   36     7        ASSIGN_OBJ                                               'intervalOffset'
          8        OP_DATA                                                  !0
   37     9        ASSIGN_OBJ                                               'intervalLength'
         10        OP_DATA                                                  !1
   38    11        ASSIGN_OBJ                                               'leadingData'
         12        OP_DATA                                                  !3
   39    13        ASSIGN_OBJ                                               'trailingData'
         14        OP_DATA                                                  !4
   40    15      > RETURN                                                   null

End of function __construct

Function getinterval:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AsnGn
function name:  getInterval
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   44     0  E >   FETCH_OBJ_R                                      ~0      'interval'
          1        VERIFY_RETURN_TYPE                                       ~0
          2      > RETURN                                                   ~0
   45     3*       VERIFY_RETURN_TYPE                                       
          4*     > RETURN                                                   null

End of function getinterval

Function getintervaloffset:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AsnGn
function name:  getIntervalOffset
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   49     0  E >   FETCH_OBJ_R                                      ~0      'intervalOffset'
          1        VERIFY_RETURN_TYPE                                       ~0
          2      > RETURN                                                   ~0
   50     3*       VERIFY_RETURN_TYPE                                       
          4*     > RETURN                                                   null

End of function getintervaloffset

Function getintervallength:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AsnGn
function name:  getIntervalLength
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   54     0  E >   FETCH_OBJ_R                                      ~0      'intervalLength'
          1        VERIFY_RETURN_TYPE                                       ~0
          2      > RETURN                                                   ~0
   55     3*       VERIFY_RETURN_TYPE                                       
          4*     > RETURN                                                   null

End of function getintervallength

Function getleadingdata:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AsnGn
function name:  getLeadingData
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   59     0  E >   FETCH_OBJ_R                                      ~0      'leadingData'
          1        VERIFY_RETURN_TYPE                                       ~0
          2      > RETURN                                                   ~0
   60     3*       VERIFY_RETURN_TYPE                                       
          4*     > RETURN                                                   null

End of function getleadingdata

Function gettrailingdata:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AsnGn
function name:  getTrailingData
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   64     0  E >   FETCH_OBJ_R                                      ~0      'trailingData'
          1        VERIFY_RETURN_TYPE                                       ~0
          2      > RETURN                                                   ~0
   65     3*       VERIFY_RETURN_TYPE                                       
          4*     > RETURN                                                   null

End of function gettrailingdata

End of class TimeParser\TimeInterval.

Class TimeParser\TimeParser:
Function findinterval:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 37
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 33
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 33
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 37
2 jumps found. (Code = 43) Position 1 = 39, Position 2 = 121
Branch analysis from position: 39
2 jumps found. (Code = 43) Position 1 = 51, Position 2 = 55
Branch analysis from position: 51
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 55
2 jumps found. (Code = 43) Position 1 = 67, Position 2 = 71
Branch analysis from position: 67
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 71
2 jumps found. (Code = 43) Position 1 = 73, Position 2 = 77
Branch analysis from position: 73
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 77
2 jumps found. (Code = 43) Position 1 = 96, Position 2 = 117
Branch analysis from position: 96
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 117
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 121
2 jumps found. (Code = 43) Position 1 = 123, Position 2 = 200
Branch analysis from position: 123
2 jumps found. (Code = 43) Position 1 = 135, Position 2 = 139
Branch analysis from position: 135
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 139
2 jumps found. (Code = 47) Position 1 = 151, Position 2 = 153
Branch analysis from position: 151
2 jumps found. (Code = 43) Position 1 = 154, Position 2 = 158
Branch analysis from position: 154
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 158
2 jumps found. (Code = 43) Position 1 = 177, Position 2 = 196
Branch analysis from position: 177
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 196
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 153
Branch analysis from position: 200
2 jumps found. (Code = 43) Position 1 = 202, Position 2 = 255
Branch analysis from position: 202
2 jumps found. (Code = 43) Position 1 = 216, Position 2 = 251
Branch analysis from position: 216
2 jumps found. (Code = 47) Position 1 = 226, Position 2 = 228
Branch analysis from position: 226
2 jumps found. (Code = 43) Position 1 = 229, Position 2 = 233
Branch analysis from position: 229
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 233
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 228
Branch analysis from position: 251
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 255
2 jumps found. (Code = 43) Position 1 = 257, Position 2 = 261
Branch analysis from position: 257
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 261
2 jumps found. (Code = 43) Position 1 = 266, Position 2 = 270
Branch analysis from position: 266
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 270
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AsnGn
function name:  findInterval
number of ops:  272
compiled vars:  !0 = $input, !1 = $flags, !2 = $intervalOffset, !3 = $intervalLength, !4 = $interval, !5 = $leadingSeparation, !6 = $matches, !7 = $leadingData, !8 = $intervalAndTrailingData, !9 = $expression, !10 = $parts, !11 = $trailingData, !12 = $intervalAndPossibleTrailingData, !13 = $safeInterval
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  148     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <const ast>
  150     2        BW_AND                                           ~14     !1, 0
          3      > JMPZ                                                     ~14, ->37
  153     4    >   INIT_METHOD_CALL                                         'normalizeTimeInterval'
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0  $15     
          7        ASSIGN                                                   !0, $15
  155     8        INIT_NS_FCALL_BY_NAME                                    'TimeParser%5Cpreg_match'
          9        CHECK_FUNC_ARG                                           
         10        FETCH_STATIC_PROP_FUNC_ARG   unknown             $17     'intervalOnly'
         11        SEND_FUNC_ARG                                            $17
         12        SEND_VAR_EX                                              !0
         13        DO_FCALL                                      0  $18     
         14      > JMPZ                                                     $18, ->33
  156    15    >   ASSIGN                                                   !2, 0
  157    16        INIT_NS_FCALL_BY_NAME                                    'TimeParser%5Cstrlen'
         17        SEND_VAR_EX                                              !0
         18        DO_FCALL                                      0  $20     
         19        ASSIGN                                                   !3, $20
  160    20        INIT_STATIC_METHOD_CALL                                  'DateInterval', 'createFromDateString'
         21        SEND_VAR                                                 !0
         22        DO_FCALL                                      0  $22     
         23        ASSIGN                                                   !4, $22
  162    24        NEW                                              $24     'TimeParser%5CTimeInterval'
         25        SEND_VAR_EX                                              !2
         26        SEND_VAR_EX                                              !3
         27        SEND_VAR_EX                                              !4
         28        SEND_VAL_EX                                              null
         29        SEND_VAL_EX                                              null
         30        DO_FCALL                                      0          
         31        VERIFY_RETURN_TYPE                                       $24
         32      > RETURN                                                   $24
  165    33    >   NEW                                              $26     'InvalidArgumentException'
         34        SEND_VAL_EX                                              'Given+input+is+not+a+valid+interval.'
         35        DO_FCALL                                      0          
         36      > THROW                                         0          $26
  168    37    >   IS_EQUAL                                                 !1, 3
         38      > JMPZ                                                     ~28, ->121
  171    39    >   INIT_NS_FCALL_BY_NAME                                    'TimeParser%5Cpreg_match'
         40        CHECK_FUNC_ARG                                           
         41        FETCH_STATIC_PROP_FUNC_ARG   unknown             $29     'leadingDataSeparator'
         42        SEND_FUNC_ARG                                            $29
         43        SEND_VAR_EX                                              !0
         44        SEND_VAR_EX                                              !6
         45        FETCH_CONSTANT                                   ~30     'TimeParser%5CPREG_OFFSET_CAPTURE'
         46        SEND_VAL_EX                                              ~30
         47        DO_FCALL                                      0  $31     
         48        ASSIGN                                                   !5, $31
  172    49        BOOL_NOT                                         ~33     !5
         50      > JMPZ                                                     ~33, ->55
  173    51    >   NEW                                              $34     'Error'
         52        SEND_VAL_EX                                              'Allowing+leading+data+requires+using+a+separator.+Ie.+foo+in+%3Cinterval%3E'
         53        DO_FCALL                                      0          
         54      > THROW                                         0          $34
  176    55    >   FETCH_DIM_IS                                     ~36     !6, 1
         56        FETCH_DIM_IS                                     ~37     ~36, 0
         57        COALESCE                                         ~38     ~37
         58        QM_ASSIGN                                        ~38     null
         59        ASSIGN                                                   !7, ~38
  177    60        FETCH_DIM_IS                                     ~40     !6, 2
         61        FETCH_DIM_IS                                     ~41     ~40, 0
         62        COALESCE                                         ~42     ~41
         63        QM_ASSIGN                                        ~42     null
         64        ASSIGN                                                   !8, ~42
  180    65        BOOL_NOT                                         ~44     !7
         66      > JMPZ                                                     ~44, ->71
  181    67    >   NEW                                              $45     'InvalidArgumentException'
         68        SEND_VAL_EX                                              'Given+input+does+not+contain+a+valid+leading+data.'
         69        DO_FCALL                                      0          
         70      > THROW                                         0          $45
  183    71    >   BOOL_NOT                                         ~47     !8
         72      > JMPZ                                                     ~47, ->77
  184    73    >   NEW                                              $48     'InvalidArgumentException'
         74        SEND_VAL_EX                                              'Given+input+does+not+contain+a+valid+interval+and%2For+trailing+data.'
         75        DO_FCALL                                      0          
         76      > THROW                                         0          $48
  187    77    >   FETCH_DIM_IS                                     ~50     !6, 2
         78        FETCH_DIM_IS                                     ~51     ~50, 1
         79        COALESCE                                         ~52     ~51
         80        QM_ASSIGN                                        ~52     null
         81        ASSIGN                                                   !2, ~52
  190    82        INIT_METHOD_CALL                                         'normalizeTimeInterval'
         83        SEND_VAR_EX                                              !8
         84        DO_FCALL                                      0  $54     
         85        ASSIGN                                                   !8, $54
  192    86        FETCH_STATIC_PROP_R          unknown             ~56     'intervalSeparatorDefinitions'
         87        FETCH_STATIC_PROP_R          unknown             ~57     'intervalWithTrailingData'
         88        CONCAT                                           ~58     ~56, ~57
         89        ASSIGN                                                   !9, ~58
  194    90        INIT_NS_FCALL_BY_NAME                                    'TimeParser%5Cpreg_match'
         91        SEND_VAR_EX                                              !9
         92        SEND_VAR_EX                                              !8
         93        SEND_VAR_EX                                              !10
         94        DO_FCALL                                      0  $60     
         95      > JMPZ                                                     $60, ->117
  196    96    >   FETCH_DIM_R                                      ~61     !10, 'interval'
         97        ASSIGN                                                   !4, ~61
  197    98        FETCH_DIM_R                                      ~63     !10, 'trailing'
         99        ASSIGN                                                   !11, ~63
  198   100        INIT_NS_FCALL_BY_NAME                                    'TimeParser%5Cstrlen'
        101        SEND_VAR_EX                                              !4
        102        DO_FCALL                                      0  $65     
        103        ASSIGN                                                   !3, $65
  201   104        INIT_STATIC_METHOD_CALL                                  'DateInterval', 'createFromDateString'
        105        SEND_VAR                                                 !4
        106        DO_FCALL                                      0  $67     
        107        ASSIGN                                                   !4, $67
  202   108        NEW                                              $69     'TimeParser%5CTimeInterval'
        109        SEND_VAR_EX                                              !2
        110        SEND_VAR_EX                                              !3
        111        SEND_VAR_EX                                              !4
        112        SEND_VAR_EX                                              !7
        113        SEND_VAR_EX                                              !11
        114        DO_FCALL                                      0          
        115        VERIFY_RETURN_TYPE                                       $69
        116      > RETURN                                                   $69
  205   117    >   NEW                                              $71     'InvalidArgumentException'
        118        SEND_VAL_EX                                              'Given+input+does+not+contain+a+valid+interval+and%2For+trailing+data.'
        119        DO_FCALL                                      0          
        120      > THROW                                         0          $71
  208   121    >   BW_AND                                           ~73     !1, 2
        122      > JMPZ                                                     ~73, ->200
  211   123    >   INIT_NS_FCALL_BY_NAME                                    'TimeParser%5Cpreg_match'
        124        CHECK_FUNC_ARG                                           
        125        FETCH_STATIC_PROP_FUNC_ARG   unknown             $74     'leadingDataSeparator'
        126        SEND_FUNC_ARG                                            $74
        127        SEND_VAR_EX                                              !0
        128        SEND_VAR_EX                                              !6
        129        FETCH_CONSTANT                                   ~75     'TimeParser%5CPREG_OFFSET_CAPTURE'
        130        SEND_VAL_EX                                              ~75
        131        DO_FCALL                                      0  $76     
        132        ASSIGN                                                   !5, $76
  212   133        BOOL_NOT                                         ~78     !5
        134      > JMPZ                                                     ~78, ->139
  213   135    >   NEW                                              $79     'Error'
        136        SEND_VAL_EX                                              'Allowing+leading+data+requires+using+a+separator.+Ie.+foo+in+%3Cinterval%3E'
        137        DO_FCALL                                      0          
        138      > THROW                                         0          $79
  216   139    >   FETCH_DIM_IS                                     ~81     !6, 1
        140        FETCH_DIM_IS                                     ~82     ~81, 0
        141        COALESCE                                         ~83     ~82
        142        QM_ASSIGN                                        ~83     null
        143        ASSIGN                                                   !7, ~83
  217   144        FETCH_DIM_IS                                     ~85     !6, 2
        145        FETCH_DIM_IS                                     ~86     ~85, 0
        146        COALESCE                                         ~87     ~86
        147        QM_ASSIGN                                        ~87     null
        148        ASSIGN                                                   !12, ~87
  219   149        BOOL_NOT                                         ~89     !7
        150      > JMPNZ_EX                                         ~89     ~89, ->153
        151    >   BOOL_NOT                                         ~90     !12
        152        BOOL                                             ~89     ~90
        153    > > JMPZ                                                     ~89, ->158
  220   154    >   NEW                                              $91     'Error'
        155        SEND_VAL_EX                                              'Could+not+find+any+valid+interval+and%2For+leading+data.'
        156        DO_FCALL                                      0          
        157      > THROW                                         0          $91
  223   158    >   FETCH_DIM_IS                                     ~93     !6, 2
        159        FETCH_DIM_IS                                     ~94     ~93, 1
        160        COALESCE                                         ~95     ~94
        161        QM_ASSIGN                                        ~95     null
        162        ASSIGN                                                   !2, ~95
  226   163        INIT_METHOD_CALL                                         'normalizeTimeInterval'
        164        SEND_VAR_EX                                              !12
        165        DO_FCALL                                      0  $97     
        166        ASSIGN                                                   !13, $97
  229   167        FETCH_STATIC_PROP_R          unknown             ~99     'intervalSeparatorDefinitions'
        168        FETCH_STAT

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.95 ms | 1433 KiB | 19 Q