3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface MushroomCalculatorInterface { public function calculateDosage($dose, $wetOrFresh, $MAOi); } class MushroomCalculatorFactory { private $strains = []; private $calculator; public function __construct($strains, $calculator) { $this->strains = $strains; $this->calculator = $calculator; } public function createMushroomCalculator($name): MushroomCalculatorInterface { $potency = $this->strains[$name]; return new $this->calculator($name, $potency); } } class MushroomCalculator implements MushroomCalculatorInterface { private $name; private $potency; public function __construct($name, $potency) { $this->name = $name; $this->potency = $potency; } public function calculateDosage($dose, $wetOrFresh, $MAOi) { $dosages = [ 'microdose' => 0.25, 'regular' => 2.5, 'heroic' => 5, ]; # Pick a dose $dosage = $dosages[$dose]; if ($wetOrFresh) { $dosage *= 9.3; } if ($MAOi) { $dosage /= 2; } return round(($dosage / $this->factor($this->potency)), 2); } private function factor($potency) { $cubensis = 0.63; return $potency / $cubensis; } } $strains = [ 'azurenscens' => 1.78, 'baeocystis' => .85, 'bohemica' => 1.34, 'cubensis' => .63, 'cyanescens' => .85, 'cyanofibrillosa' => .21, 'hoogshagenii' => .60, 'liniformans' => .16, 'penis envy' => 1.35, 'semilanceata' => .98, 'stuntzii' => .36, 'tampanensis' => .68, 'weilii' => .61, ]; #$factory= new MushroomCalculatorFactory($strains, MushroomCalculator::class); $name = 'azurenscens'; $potency = $strains['azurenscens']; # foreach (mushroom) { #$calculator = $factory->createMushroomCalculator('azurenscens'); $calculator = new MushroomCalculator($name, $potency); echo $calculator->calculateDosage('heroic', true, true); # }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JLTJj
function name:  (null)
number of ops:  17
compiled vars:  !0 = $strains, !1 = $name, !2 = $potency, !3 = $calculator
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   DECLARE_CLASS                                            'mushroomcalculator'
   60     1        ASSIGN                                                   !0, <array>
   77     2        ASSIGN                                                   !1, 'azurenscens'
   78     3        FETCH_DIM_R                                      ~6      !0, 'azurenscens'
          4        ASSIGN                                                   !2, ~6
   82     5        NEW                                              $8      'MushroomCalculator'
          6        SEND_VAR_EX                                              !1
          7        SEND_VAR_EX                                              !2
          8        DO_FCALL                                      0          
          9        ASSIGN                                                   !3, $8
   83    10        INIT_METHOD_CALL                                         !3, 'calculateDosage'
         11        SEND_VAL_EX                                              'heroic'
         12        SEND_VAL_EX                                              <true>
         13        SEND_VAL_EX                                              <true>
         14        DO_FCALL                                      0  $11     
         15        ECHO                                                     $11
   84    16      > RETURN                                                   1

Class MushroomCalculatorInterface:
Function calculatedosage:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JLTJj
function name:  calculateDosage
number of ops:  4
compiled vars:  !0 = $dose, !1 = $wetOrFresh, !2 = $MAOi
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3      > RETURN                                                   null

End of function calculatedosage

End of class MushroomCalculatorInterface.

Class MushroomCalculatorFactory:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JLTJj
function name:  __construct
number of ops:  7
compiled vars:  !0 = $strains, !1 = $calculator
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   12     2        ASSIGN_OBJ                                               'strains'
          3        OP_DATA                                                  !0
   13     4        ASSIGN_OBJ                                               'calculator'
          5        OP_DATA                                                  !1
   14     6      > RETURN                                                   null

End of function __construct

Function createmushroomcalculator:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JLTJj
function name:  createMushroomCalculator
number of ops:  14
compiled vars:  !0 = $name, !1 = $potency
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
   17     1        FETCH_OBJ_R                                      ~2      'strains'
          2        FETCH_DIM_R                                      ~3      ~2, !0
          3        ASSIGN                                                   !1, ~3
   19     4        FETCH_OBJ_R                                      ~5      'calculator'
          5        FETCH_CLASS                                   0  $6      ~5
          6        NEW                                              $7      $6
          7        SEND_VAR_EX                                              !0
          8        SEND_VAR_EX                                              !1
          9        DO_FCALL                                      0          
         10        VERIFY_RETURN_TYPE                                       $7
         11      > RETURN                                                   $7
   20    12*       VERIFY_RETURN_TYPE                                       
         13*     > RETURN                                                   null

End of function createmushroomcalculator

End of class MushroomCalculatorFactory.

Class MushroomCalculator:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JLTJj
function name:  __construct
number of ops:  7
compiled vars:  !0 = $name, !1 = $potency
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   28     2        ASSIGN_OBJ                                               'name'
          3        OP_DATA                                                  !0
   29     4        ASSIGN_OBJ                                               'potency'
          5        OP_DATA                                                  !1
   30     6      > RETURN                                                   null

End of function __construct

Function calculatedosage:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 8
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 10
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
Branch analysis from position: 8
filename:       /in/JLTJj
function name:  calculateDosage
number of ops:  22
compiled vars:  !0 = $dose, !1 = $wetOrFresh, !2 = $MAOi, !3 = $dosages, !4 = $dosage
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   33     3        ASSIGN                                                   !3, <array>
   40     4        FETCH_DIM_R                                      ~6      !3, !0
          5        ASSIGN                                                   !4, ~6
   42     6      > JMPZ                                                     !1, ->8
   43     7    >   ASSIGN_OP                                     3          !4, 9.3
   46     8    > > JMPZ                                                     !2, ->10
   47     9    >   ASSIGN_OP                                     4          !4, 2
   50    10    >   INIT_FCALL                                               'round'
         11        INIT_METHOD_CALL                                         'factor'
         12        CHECK_FUNC_ARG                                           
         13        FETCH_OBJ_FUNC_ARG                               $10     'potency'
         14        SEND_FUNC_ARG                                            $10
         15        DO_FCALL                                      0  $11     
         16        DIV                                              ~12     !4, $11
         17        SEND_VAL                                                 ~12
         18        SEND_VAL                                                 2
         19        DO_ICALL                                         $13     
         20      > RETURN                                                   $13
   51    21*     > RETURN                                                   null

End of function calculatedosage

Function factor:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JLTJj
function name:  factor
number of ops:  5
compiled vars:  !0 = $potency, !1 = $cubensis
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   53     0  E >   RECV                                             !0      
   54     1        ASSIGN                                                   !1, 0.63
   56     2        DIV                                              ~3      !0, !1
          3      > RETURN                                                   ~3
   57     4*     > RETURN                                                   null

End of function factor

End of class MushroomCalculator.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
215.37 ms | 1404 KiB | 15 Q