3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace App\ServerArbiter; use App\ServerArbiter\Rules\Rule, App\Model\Entity\Server; /** * Class ServerArbiter * * @package App\ServerArbiter */ class ServerArbiter { /** * @var RuleSet */ private $ruleSet; /** * @var Server[] */ private $servers; public function __construct(RuleSet $ruleSet, array $servers) { foreach ($servers as $server) { if (!($server instanceof Server)) { throw new \InvalidArgumentException(sprintf( "Second parameter for: %s must be an array of Server objects. %s given which is an instance of %s.", __METHOD__, $server, is_scalar($server) ? 'a scalar value' : get_class($server) )); } } $this->ruleSet = $ruleSet; $this->servers = $servers; } /** * Run each Server against each Rule in the RuleSet and return the Server that matched the most rules * * @return Server The Server chosen by the ServerArbiter * * @note If two servers match the same number of rules successfully, the first one will be returned */ public function decide() { $decisions = []; /** @var Rule $rule */ foreach ($this->ruleSet as $rule) { foreach ($this->servers as $server) { if (!array_key_exists($server->getId(), $decisions)) { $decisions[$server->getId()]['successes'] = 0; } if ($rule->resolve()) { $decisions[$server->getId()]['successes']++; } } } $decision = array_search(max($decisions), $decisions); return $decision; } }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/IF1gb
function name:  (null)
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   74     0  E > > RETURN                                                   1

Class App\ServerArbiter\ServerArbiter:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 28
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 28
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 27
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 18
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 18
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 28
filename:       /in/IF1gb
function name:  __construct
number of ops:  34
compiled vars:  !0 = $ruleSet, !1 = $servers, !2 = $server
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   27     2      > FE_RESET_R                                       $3      !1, ->28
          3    > > FE_FETCH_R                                               $3, !2, ->28
   29     4    >   INSTANCEOF                                       ~4      !2, 'App%5CModel%5CEntity%5CServer'
          5        BOOL_NOT                                         ~5      ~4
          6      > JMPZ                                                     ~5, ->27
   31     7    >   NEW                                              $6      'InvalidArgumentException'
          8        INIT_NS_FCALL_BY_NAME                                    'App%5CServerArbiter%5Csprintf'
   32     9        SEND_VAL_EX                                              'Second+parameter+for%3A+%25s+must+be+an+array+of+Server+objects.+%25s+given+which+is+an+instance+of+%25s.'
   33    10        SEND_VAL_EX                                              'App%5CServerArbiter%5CServerArbiter%3A%3A__construct'
   32    11        SEND_VAR_EX                                              !2
   33    12        INIT_NS_FCALL_BY_NAME                                    'App%5CServerArbiter%5Cis_scalar'
         13        SEND_VAR_EX                                              !2
         14        DO_FCALL                                      0  $7      
         15      > JMPZ                                                     $7, ->18
         16    >   QM_ASSIGN                                        ~8      'a+scalar+value'
         17      > JMP                                                      ->22
         18    >   INIT_NS_FCALL_BY_NAME                                    'App%5CServerArbiter%5Cget_class'
         19        SEND_VAR_EX                                              !2
         20        DO_FCALL                                      0  $9      
         21        QM_ASSIGN                                        ~8      $9
         22    >   SEND_VAL_EX                                              ~8
         23        DO_FCALL                                      0  $10     
         24        SEND_VAR_NO_REF_EX                                       $10
         25        DO_FCALL                                      0          
         26      > THROW                                         0          $6
   27    27    > > JMP                                                      ->3
         28    >   FE_FREE                                                  $3
   38    29        ASSIGN_OBJ                                               'ruleSet'
         30        OP_DATA                                                  !0
   39    31        ASSIGN_OBJ                                               'servers'
         32        OP_DATA                                                  !1
   40    33      > RETURN                                                   null

End of function __construct

Function decide:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 31
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 31
Branch analysis from position: 4
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 29
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 29
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 20
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 28
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 28
Branch analysis from position: 20
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 29
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 31
filename:       /in/IF1gb
function name:  decide
number of ops:  42
compiled vars:  !0 = $decisions, !1 = $rule, !2 = $server, !3 = $decision
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   51     0  E >   ASSIGN                                                   !0, <array>
   54     1        FETCH_OBJ_R                                      ~5      'ruleSet'
          2      > FE_RESET_R                                       $6      ~5, ->31
          3    > > FE_FETCH_R                                               $6, !1, ->31
   56     4    >   FETCH_OBJ_R                                      ~7      'servers'
          5      > FE_RESET_R                                       $8      ~7, ->29
          6    > > FE_FETCH_R                                               $8, !2, ->29
   58     7    >   INIT_NS_FCALL_BY_NAME                                    'App%5CServerArbiter%5Carray_key_exists'
          8        INIT_METHOD_CALL                                         !2, 'getId'
          9        DO_FCALL                                      0  $9      
         10        SEND_VAR_NO_REF_EX                                       $9
         11        SEND_VAR_EX                                              !0
         12        DO_FCALL                                      0  $10     
         13        BOOL_NOT                                         ~11     $10
         14      > JMPZ                                                     ~11, ->20
   60    15    >   INIT_METHOD_CALL                                         !2, 'getId'
         16        DO_FCALL                                      0  $12     
         17        FETCH_DIM_W                                      $13     !0, $12
         18        ASSIGN_DIM                                               $13, 'successes'
         19        OP_DATA                                                  0
   63    20    >   INIT_METHOD_CALL                                         !1, 'resolve'
         21        DO_FCALL                                      0  $15     
         22      > JMPZ                                                     $15, ->28
   65    23    >   INIT_METHOD_CALL                                         !2, 'getId'
         24        DO_FCALL                                      0  $16     
         25        FETCH_DIM_RW                                     $17     !0, $16
         26        FETCH_DIM_RW                                     $18     $17, 'successes'
         27        PRE_INC                                                  $18
   56    28    > > JMP                                                      ->6
         29    >   FE_FREE                                                  $8
   54    30      > JMP                                                      ->3
         31    >   FE_FREE                                                  $6
   70    32        INIT_NS_FCALL_BY_NAME                                    'App%5CServerArbiter%5Carray_search'
         33        INIT_NS_FCALL_BY_NAME                                    'App%5CServerArbiter%5Cmax'
         34        SEND_VAR_EX                                              !0
         35        DO_FCALL                                      0  $20     
         36        SEND_VAR_NO_REF_EX                                       $20
         37        SEND_VAR_EX                                              !0
         38        DO_FCALL                                      0  $21     
         39        ASSIGN                                                   !3, $21
   72    40      > RETURN                                                   !3
   73    41*     > RETURN                                                   null

End of function decide

End of class App\ServerArbiter\ServerArbiter.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
161.3 ms | 1404 KiB | 25 Q