3v4l.org

run code in 300+ PHP versions simultaneously
<?php trait TimeRestriction{ public function excludeTimes($times, $restrictions) { $timeList = $this->mergeTimes($times, $restrictions); var_dump($timeList); $validTimes = []; $result = []; foreach ($timeList as $key => $time) { $restrictionInclusive = false; if ($key == count($timeList) - 1) { $restrictionInclusive = true; } if ($this->isTimeWithinRanges($time, $times) && !$this->isTimeWithinRanges($time, $restrictions, $restrictionInclusive)) { $validTimes[] = $time; } } $validItemsCount = count($validTimes); for ($i = 0; $i < $validItemsCount; $i += 2) { $result[] = [ 'start_time' => $validTimes[$i], 'end_time' => $validTimes[$i + 1] ]; } return $result; } public function isTimeWithinRanges($time, $ranges, $inclusive = true) { foreach ($ranges as $range) { if ($this->isTimeWithinRange($time, $range, $inclusive)) { return true; } } return false; } public function isTimeWithinRange($time, $range, $inclusive = true) { if ($inclusive) { return $time->gte($range['start_time']) && $time->lte($range['end_time']); } else { return $time->gt($range['start_time']) && $time->lt($range['end_time']); } } public function mergeTimes() { $allTimes = collect([]); $params = func_get_args(); foreach ($params as $param) { foreach ($param as $timeRange) { $allTimes->push($timeRange['start_time']); $allTimes->push($timeRange['end_time']); } } var_dump($allTimes->toArray()); return $allTimes->sortBy(function (Carbon $value, $key) { return $value->getTimestamp(); })->values()->unique(function (Carbon $value) { return $value->getTimestamp(); })->all(); } }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2elDs
function name:  (null)
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   91     0  E > > RETURN                                                   1

Class TimeRestriction:
Function excludetimes:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 13, Position 2 = 37
Branch analysis from position: 13
2 jumps found. (Code = 78) Position 1 = 14, Position 2 = 37
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 21
Branch analysis from position: 20
2 jumps found. (Code = 46) Position 1 = 26, Position 2 = 33
Branch analysis from position: 26
2 jumps found. (Code = 43) Position 1 = 34, Position 2 = 36
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 36
Branch analysis from position: 33
Branch analysis from position: 21
Branch analysis from position: 37
1 jumps found. (Code = 42) Position 1 = 50
Branch analysis from position: 50
2 jumps found. (Code = 44) Position 1 = 52, Position 2 = 42
Branch analysis from position: 52
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 42
2 jumps found. (Code = 44) Position 1 = 52, Position 2 = 42
Branch analysis from position: 52
Branch analysis from position: 42
Branch analysis from position: 37
filename:       /in/2elDs
function name:  excludeTimes
number of ops:  54
compiled vars:  !0 = $times, !1 = $restrictions, !2 = $timeList, !3 = $validTimes, !4 = $result, !5 = $time, !6 = $key, !7 = $restrictionInclusive, !8 = $validItemsCount, !9 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    6     2        INIT_METHOD_CALL                                         'mergeTimes'
          3        SEND_VAR_EX                                              !0
          4        SEND_VAR_EX                                              !1
          5        DO_FCALL                                      0  $10     
          6        ASSIGN                                                   !2, $10
    7     7        INIT_FCALL                                               'var_dump'
          8        SEND_VAR                                                 !2
          9        DO_ICALL                                                 
    8    10        ASSIGN                                                   !3, <array>
    9    11        ASSIGN                                                   !4, <array>
   11    12      > FE_RESET_R                                       $15     !2, ->37
         13    > > FE_FETCH_R                                       ~16     $15, !5, ->37
         14    >   ASSIGN                                                   !6, ~16
   13    15        ASSIGN                                                   !7, <false>
   15    16        COUNT                                            ~19     !2
         17        SUB                                              ~20     ~19, 1
         18        IS_EQUAL                                                 !6, ~20
         19      > JMPZ                                                     ~21, ->21
   17    20    >   ASSIGN                                                   !7, <true>
   20    21    >   INIT_METHOD_CALL                                         'isTimeWithinRanges'
         22        SEND_VAR_EX                                              !5
         23        SEND_VAR_EX                                              !0
         24        DO_FCALL                                      0  $23     
         25      > JMPZ_EX                                          ~24     $23, ->33
         26    >   INIT_METHOD_CALL                                         'isTimeWithinRanges'
         27        SEND_VAR_EX                                              !5
         28        SEND_VAR_EX                                              !1
         29        SEND_VAR_EX                                              !7
         30        DO_FCALL                                      0  $25     
         31        BOOL_NOT                                         ~26     $25
         32        BOOL                                             ~24     ~26
         33    > > JMPZ                                                     ~24, ->36
   22    34    >   ASSIGN_DIM                                               !3
         35        OP_DATA                                                  !5
   11    36    > > JMP                                                      ->13
         37    >   FE_FREE                                                  $15
   26    38        COUNT                                            ~28     !3
         39        ASSIGN                                                   !8, ~28
   28    40        ASSIGN                                                   !9, 0
         41      > JMP                                                      ->50
   31    42    >   FETCH_DIM_R                                      ~32     !3, !9
         43        INIT_ARRAY                                       ~33     ~32, 'start_time'
   32    44        ADD                                              ~34     !9, 1
         45        FETCH_DIM_R                                      ~35     !3, ~34
         46        ADD_ARRAY_ELEMENT                                ~33     ~35, 'end_time'
   30    47        ASSIGN_DIM                                               !4
   32    48        OP_DATA                                                  ~33
   28    49        ASSIGN_OP                                     1          !9, 2
         50    >   IS_SMALLER                                               !9, !8
         51      > JMPNZ                                                    ~37, ->42
   36    52    > > RETURN                                                   !4
   37    53*     > RETURN                                                   null

End of function excludetimes

Function istimewithinranges:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 14
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 14
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 13
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
filename:       /in/2elDs
function name:  isTimeWithinRanges
number of ops:  17
compiled vars:  !0 = $time, !1 = $ranges, !2 = $inclusive, !3 = $range
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      <true>
   41     3      > FE_RESET_R                                       $4      !1, ->14
          4    > > FE_FETCH_R                                               $4, !3, ->14
   43     5    >   INIT_METHOD_CALL                                         'isTimeWithinRange'
          6        SEND_VAR_EX                                              !0
          7        SEND_VAR_EX                                              !3
          8        SEND_VAR_EX                                              !2
          9        DO_FCALL                                      0  $5      
         10      > JMPZ                                                     $5, ->13
   45    11    >   FE_FREE                                                  $4
         12      > RETURN                                                   <true>
   41    13    > > JMP                                                      ->4
         14    >   FE_FREE                                                  $4
   49    15      > RETURN                                                   <false>
   50    16*     > RETURN                                                   null

End of function istimewithinranges

Function istimewithinrange:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 18
Branch analysis from position: 4
2 jumps found. (Code = 46) Position 1 = 10, Position 2 = 16
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
Branch analysis from position: 18
2 jumps found. (Code = 46) Position 1 = 24, Position 2 = 30
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
filename:       /in/2elDs
function name:  isTimeWithinRange
number of ops:  32
compiled vars:  !0 = $time, !1 = $range, !2 = $inclusive
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   53     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      <true>
   55     3      > JMPZ                                                     !2, ->18
   57     4    >   INIT_METHOD_CALL                                         !0, 'gte'
          5        CHECK_FUNC_ARG                                           
          6        FETCH_DIM_FUNC_ARG                               $3      !1, 'start_time'
          7        SEND_FUNC_ARG                                            $3
          8        DO_FCALL                                      0  $4      
          9      > JMPZ_EX                                          ~5      $4, ->16
         10    >   INIT_METHOD_CALL                                         !0, 'lte'
         11        CHECK_FUNC_ARG                                           
         12        FETCH_DIM_FUNC_ARG                               $6      !1, 'end_time'
         13        SEND_FUNC_ARG                                            $6
         14        DO_FCALL                                      0  $7      
         15        BOOL                                             ~5      $7
         16    > > RETURN                                                   ~5
   55    17*       JMP                                                      ->31
   61    18    >   INIT_METHOD_CALL                                         !0, 'gt'
         19        CHECK_FUNC_ARG                                           
         20        FETCH_DIM_FUNC_ARG                               $8      !1, 'start_time'
         21        SEND_FUNC_ARG                                            $8
         22        DO_FCALL                                      0  $9      
         23      > JMPZ_EX                                          ~10     $9, ->30
         24    >   INIT_METHOD_CALL                                         !0, 'lt'
         25        CHECK_FUNC_ARG                                           
         26        FETCH_DIM_FUNC_ARG                               $11     !1, 'end_time'
         27        SEND_FUNC_ARG                                            $11
         28        DO_FCALL                                      0  $12     
         29        BOOL                                             ~10     $12
         30    > > RETURN                                                   ~10
   63    31*     > RETURN                                                   null

End of function istimewithinrange

Function mergetimes:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 23
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 23
Branch analysis from position: 8
2 jumps found. (Code = 77) Position 1 = 9, Position 2 = 21
Branch analysis from position: 9
2 jumps found. (Code = 78) Position 1 = 10, Position 2 = 21
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 21
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
filename:       /in/2elDs
function name:  mergeTimes
number of ops:  43
compiled vars:  !0 = $allTimes, !1 = $params, !2 = $param, !3 = $timeRange
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   68     0  E >   INIT_FCALL_BY_NAME                                       'collect'
          1        SEND_VAL_EX                                              <array>
          2        DO_FCALL                                      0  $4      
          3        ASSIGN                                                   !0, $4
   70     4        FUNC_GET_ARGS                                    ~6      
          5        ASSIGN                                                   !1, ~6
   72     6      > FE_RESET_R                                       $8      !1, ->23
          7    > > FE_FETCH_R                                               $8, !2, ->23
   74     8    > > FE_RESET_R                                       $9      !2, ->21
          9    > > FE_FETCH_R                                               $9, !3, ->21
   76    10    >   INIT_METHOD_CALL                                         !0, 'push'
         11        CHECK_FUNC_ARG                                           
         12        FETCH_DIM_FUNC_ARG                               $10     !3, 'start_time'
         13        SEND_FUNC_ARG                                            $10
         14        DO_FCALL                                      0          
   77    15        INIT_METHOD_CALL                                         !0, 'push'
         16        CHECK_FUNC_ARG                                           
         17        FETCH_DIM_FUNC_ARG                               $12     !3, 'end_time'
         18        SEND_FUNC_ARG                                            $12
         19        DO_FCALL                                      0          
   74    20      > JMP                                                      ->9
         21    >   FE_FREE                                                  $9
   72    22      > JMP                                                      ->7
         23    >   FE_FREE                                                  $8
   81    24        INIT_FCALL                                               'var_dump'
         25        INIT_METHOD_CALL                                         !0, 'toArray'
         26        DO_FCALL                                      0  $14     
         27        SEND_VAR                                                 $14
         28        DO_ICALL                                                 
   83    29        INIT_METHOD_CALL                                         !0, 'sortBy'
         30        DECLARE_LAMBDA_FUNCTION                          ~16     [0]
   86    31        SEND_VAL_EX                                              ~16
   83    32        DO_FCALL                                      0  $17     
   86    33        INIT_METHOD_CALL                                         $17, 'values'
         34        DO_FCALL                                      0  $18     
         35        INIT_METHOD_CALL                                         $18, 'unique'
         36        DECLARE_LAMBDA_FUNCTION                          ~19     [1]
   89    37        SEND_VAL_EX                                              ~19
   86    38        DO_FCALL                                      0  $20     
   89    39        INIT_METHOD_CALL                                         $20, 'all'
         40        DO_FCALL                                      0  $21     
         41      > RETURN                                                   $21
   90    42*     > RETURN                                                   null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2elDs
function name:  {closure}
number of ops:  6
compiled vars:  !0 = $value, !1 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   83     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   85     2        INIT_METHOD_CALL                                         !0, 'getTimestamp'
          3        DO_FCALL                                      0  $2      
          4      > RETURN                                                   $2
   86     5*     > RETURN                                                   null

End of Dynamic Function 0

Dynamic Function 1
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2elDs
function name:  {closure}
number of ops:  5
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
          0  E >   RECV                                             !0      
   88     1        INIT_METHOD_CALL                                         !0, 'getTimestamp'
          2        DO_FCALL                                      0  $1      
          3      > RETURN                                                   $1
   89     4*     > RETURN                                                   null

End of Dynamic Function 1

End of function mergetimes

End of class TimeRestriction.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
156.92 ms | 1027 KiB | 14 Q