3v4l.org

run code in 300+ PHP versions simultaneously
<?php //my variante final class StateOptions { public function __construct(array $options) { $this->options = $options; } private function validate() { if ($this->options === []) { return false; } return true; } public function getNextState() { return $this->options['nextState'] ?? 'defaultstate'; } } class BusinessLogicServiceOOp { public function changeState(StateOptions $stateOptions) { $this->changeTo($stateOptions->getNextState()); } public function changeTo(string $changeTo) { echo $changeTo; } } //array solution class BusinessLogicServiceLegacy { public function changeState(array $stateOptions) { /** Problem here is, that no validation ran on mandatory or optional flags or on valid flags from business perspective**/ $this->changeTo($stateOptions['nextState'] ?? 'defaultstate'); } public function changeTo(string $changeTo) { echo $changeTo; } } (new BusinessLogicServiceLegacy())->changeState([]); (new BusinessLogicServiceOOp())->changeState(new StateOptions([]));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/s7McT
function name:  (null)
number of ops:  14
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   53     0  E >   NEW                                              $0      'BusinessLogicServiceLegacy'
          1        DO_FCALL                                      0          
          2        INIT_METHOD_CALL                                         $0, 'changeState'
          3        SEND_VAL_EX                                              <array>
          4        DO_FCALL                                      0          
   54     5        NEW                                              $3      'BusinessLogicServiceOOp'
          6        DO_FCALL                                      0          
          7        INIT_METHOD_CALL                                         $3, 'changeState'
          8        NEW                                              $5      'StateOptions'
          9        SEND_VAL_EX                                              <array>
         10        DO_FCALL                                      0          
         11        SEND_VAR_NO_REF_EX                                       $5
         12        DO_FCALL                                      0          
         13      > RETURN                                                   1

Class StateOptions:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/s7McT
function name:  __construct
number of ops:  4
compiled vars:  !0 = $options
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
    8     1        ASSIGN_OBJ                                               'options'
          2        OP_DATA                                                  !0
    9     3      > RETURN                                                   null

End of function __construct

Function validate:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 4
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/s7McT
function name:  validate
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   FETCH_OBJ_R                                      ~0      'options'
          1        IS_IDENTICAL                                             ~0, <array>
          2      > JMPZ                                                     ~1, ->4
   15     3    > > RETURN                                                   <false>
   18     4    > > RETURN                                                   <true>
   19     5*     > RETURN                                                   null

End of function validate

Function getnextstate:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/s7McT
function name:  getNextState
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   FETCH_OBJ_IS                                     ~0      'options'
          1        FETCH_DIM_IS                                     ~1      ~0, 'nextState'
          2        COALESCE                                         ~2      ~1
          3        QM_ASSIGN                                        ~2      'defaultstate'
          4      > RETURN                                                   ~2
   23     5*     > RETURN                                                   null

End of function getnextstate

End of class StateOptions.

Class BusinessLogicServiceOOp:
Function changestate:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/s7McT
function name:  changeState
number of ops:  7
compiled vars:  !0 = $stateOptions
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   RECV                                             !0      
   30     1        INIT_METHOD_CALL                                         'changeTo'
          2        INIT_METHOD_CALL                                         !0, 'getNextState'
          3        DO_FCALL                                      0  $1      
          4        SEND_VAR_NO_REF_EX                                       $1
          5        DO_FCALL                                      0          
   31     6      > RETURN                                                   null

End of function changestate

Function changeto:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/s7McT
function name:  changeTo
number of ops:  3
compiled vars:  !0 = $changeTo
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   RECV                                             !0      
   33     1        ECHO                                                     !0
   34     2      > RETURN                                                   null

End of function changeto

End of class BusinessLogicServiceOOp.

Class BusinessLogicServiceLegacy:
Function changestate:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/s7McT
function name:  changeState
number of ops:  8
compiled vars:  !0 = $stateOptions
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   42     0  E >   RECV                                             !0      
   45     1        INIT_METHOD_CALL                                         'changeTo'
          2        FETCH_DIM_IS                                     ~1      !0, 'nextState'
          3        COALESCE                                         ~2      ~1
          4        QM_ASSIGN                                        ~2      'defaultstate'
          5        SEND_VAL_EX                                              ~2
          6        DO_FCALL                                      0          
   46     7      > RETURN                                                   null

End of function changestate

Function changeto:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/s7McT
function name:  changeTo
number of ops:  3
compiled vars:  !0 = $changeTo
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   48     0  E >   RECV                                             !0      
   49     1        ECHO                                                     !0
   50     2      > RETURN                                                   null

End of function changeto

End of class BusinessLogicServiceLegacy.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
276.73 ms | 1004 KiB | 13 Q