3v4l.org

run code in 300+ PHP versions simultaneously
<?php const AMENITY_ICONS_TO_ADDON_CATEGORY = [ 'wellness' => ['fieldName' => 'wellness-use', 'type' => 'category'], 'wine-tasting' => ['fieldName' => 'Welcome Drink', 'type' => 'description'], 'full-board' => [ 'fieldName' => "3 Course Menu, 4 Course Menu", 'type' => 'description', 'terms' => true ], 'half-board' => ['fieldName' => 'halfboard', 'type' => 'category'], 'parking' => ['fieldName' => 'parking', 'type' => 'category'], ]; function getQueryDefinitionForInclusiveServices(string $term): array { $mapping = AMENITY_ICONS_TO_ADDON_CATEGORY[$term] ?? $term; $queryDefinition = []; $fieldName = 'included_amenities.descriptions.icon'; $term = $mapping['term'] ?? $term; if (is_array($mapping)) { $fieldName = $mapping['type'] == 'category' ? 'hotel.included_addons.category.keyword' : 'hotel.included_addons.en_GB.description.keyword'; if (!empty($mapping['terms'])) { $queryDefinition['type'] = 'terms'; } } $queryDefinition['field'] = $fieldName; $queryDefinition['term'] = $term; return [ $queryDefinition ]; } var_dump(getQueryDefinitionForInclusiveServices('full-board'));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RUc3B
function name:  (null)
number of ops:  8
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   DECLARE_CONST                                            'AMENITY_ICONS_TO_ADDON_CATEGORY', <array>
   38     1        INIT_FCALL                                               'var_dump'
          2        INIT_FCALL                                               'getquerydefinitionforinclusiveservices'
          3        SEND_VAL                                                 'full-board'
          4        DO_FCALL                                      0  $0      
          5        SEND_VAR                                                 $0
          6        DO_ICALL                                                 
          7      > RETURN                                                   1

Function getquerydefinitionforinclusiveservices:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 26
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 19
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 26
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 26
Branch analysis from position: 24
Branch analysis from position: 26
Branch analysis from position: 26
filename:       /in/RUc3B
function name:  getQueryDefinitionForInclusiveServices
number of ops:  35
compiled vars:  !0 = $term, !1 = $mapping, !2 = $queryDefinition, !3 = $fieldName
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
   16     1        FETCH_CONSTANT                                   ~4      'AMENITY_ICONS_TO_ADDON_CATEGORY'
          2        FETCH_DIM_IS                                     ~5      ~4, !0
          3        COALESCE                                         ~6      ~5
          4        QM_ASSIGN                                        ~6      !0
          5        ASSIGN                                                   !1, ~6
   17     6        ASSIGN                                                   !2, <array>
   18     7        ASSIGN                                                   !3, 'included_amenities.descriptions.icon'
   19     8        FETCH_DIM_IS                                     ~10     !1, 'term'
          9        COALESCE                                         ~11     ~10
         10        QM_ASSIGN                                        ~11     !0
         11        ASSIGN                                                   !0, ~11
   21    12        TYPE_CHECK                                  128          !1
         13      > JMPZ                                                     ~13, ->26
   22    14    >   FETCH_DIM_R                                      ~14     !1, 'type'
         15        IS_EQUAL                                                 ~14, 'category'
         16      > JMPZ                                                     ~15, ->19
   23    17    >   QM_ASSIGN                                        ~16     'hotel.included_addons.category.keyword'
         18      > JMP                                                      ->20
   24    19    >   QM_ASSIGN                                        ~16     'hotel.included_addons.en_GB.description.keyword'
   22    20    >   ASSIGN                                                   !3, ~16
   26    21        ISSET_ISEMPTY_DIM_OBJ                         1  ~18     !1, 'terms'
         22        BOOL_NOT                                         ~19     ~18
         23      > JMPZ                                                     ~19, ->26
   27    24    >   ASSIGN_DIM                                               !2, 'type'
         25        OP_DATA                                                  'terms'
   31    26    >   ASSIGN_DIM                                               !2, 'field'
         27        OP_DATA                                                  !3
   32    28        ASSIGN_DIM                                               !2, 'term'
         29        OP_DATA                                                  !0
   34    30        INIT_ARRAY                                       ~23     !2
         31        VERIFY_RETURN_TYPE                                       ~23
         32      > RETURN                                                   ~23
   36    33*       VERIFY_RETURN_TYPE                                       
         34*     > RETURN                                                   null

End of function getquerydefinitionforinclusiveservices

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.45 ms | 1023 KiB | 15 Q