3v4l.org

run code in 500+ PHP versions simultaneously
<?php class Stress { const ABSENT = 0; // Ausente const SOFT = 1; // Ameno const MODERATE = 2; // Moderado const SEVERE = 3; // Severo const CRITICAL = 4; // Morte/Crítico const RATING = [ self::ABSENT => 'Ausência de estresse térmico', self::SOFT => 'Estresse térmico ameno', self::MODERATE => 'Estresse térmico moderado', self::SEVERE => 'Estresse térmico severo', self::CRITICAL => 'Estresse térmico crítico. Ocorrência de morte.', ]; const AMBIGUOUS = [ // Em 25 graus a 100% de UR temos um moderado: 250 => [ 100 => Stress::MODERATE ], // Já na linha dos 26,1 graus temos 3 ambíguos: 261 => [ 80 => Stress::SOFT, 90 => Stress::MODERATE, 100 => Stress::MODERATE ], // ... 433 => [ 30 => Stress::SEVERE ], 461 => [ 20 => Stress::MODERATE ], ]; public $temp;// int public $ur;// int public function __construct( $temp, $ur ) { $this->temp = $temp; $this->ur = $ur; } public function __toString() { $ambiguousRatingIndex = $this->getAmbiguousStressRatingIndex(); if ( $ambiguousRatingIndex !== false ) return sprintf( 'Classificação (por tabela de desambiguação): %s', self::RATING[ $ambiguousRatingIndex ] ); else { $rating = $this->getGeneralRatingIndex(); return sprintf( 'Classificação geral do estresse térmico por ausência de ambiguidade: %s', self::RATING[ $rating ] ); } } // Primeiro passo da lógica. Busca por ambiguidade: private function getAmbiguousStressRatingIndex() { $temp = $this->temp; $ur = $this->ur; if ( isset( self::AMBIGUOUS[ $temp ] ) && isset( self::AMBIGUOUS[ $temp ][ $ur ] ) ) return self::AMBIGUOUS[ $temp ][ $ur ];// int = índice do rótulo encontrado return false;// boolean false = não encontrou. Podia ser Exception, mas vamos facilitar o código } // Utilizado apenas após confirmada a ausência de ambiguidade // ITU = (0,8 x TA + (UR/100) x (TA-14,4) + 46,4) private function getGeneralRatingIndex() { $temp = $this->temp / 10;// Estávamos trabalhando com valores inteiros para a temperatura. 244 => 24.4 $ur = $this->ur / 100; $ITU = .8 * $temp + $ur * ( $temp - 14.4 ) + 46.4; if ( $ITU < 72 ) return Stress::ABSENT; if ( $ITU < 79 ) return Stress::SOFT; if ( $ITU < 90 ) return Stress::MODERATE; if ( $ITU < 98 ) return Stress::SEVERE; return Stress::CRITICAL; } } echo (string)( new Stress( 250, 100 ) ) . "\n";// 25,0 graus / 100% UR echo (string)( new Stress( 261, 80 ) ) . "\n";// 26,1 graus / 80% UR echo (string)( new Stress( 261, 90 ) ) . "\n";// 26,1 graus / 90% UR echo (string)( new Stress( 461, 20 ) ) . "\n";// 46,1 graus / 20% UR (seu exemplo) echo (string)( new Stress( 433, 30 ) ) . "\n";// 43,3 graus / 30% UR (seu exemplo) echo (string)( new Stress( 239, 40 ) ) . "\n"; echo (string)( new Stress( 317, 20 ) ) . "\n"; echo (string)( new Stress( 444, 80 ) ) . "\n";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vt7eP
function name:  (null)
number of ops:  58
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    2     0  E >   DECLARE_CLASS                                                'stress'
   76     1        NEW                                                  $0      'Stress'
          2        SEND_VAL_EX                                                  250
          3        SEND_VAL_EX                                                  100
          4        DO_FCALL                                          0          
          5        CAST                                              6  ~2      $0
          6        CONCAT                                               ~3      ~2, '%0A'
          7        ECHO                                                         ~3
   77     8        NEW                                                  $4      'Stress'
          9        SEND_VAL_EX                                                  261
         10        SEND_VAL_EX                                                  80
         11        DO_FCALL                                          0          
         12        CAST                                              6  ~6      $4
         13        CONCAT                                               ~7      ~6, '%0A'
         14        ECHO                                                         ~7
   78    15        NEW                                                  $8      'Stress'
         16        SEND_VAL_EX                                                  261
         17        SEND_VAL_EX                                                  90
         18        DO_FCALL                                          0          
         19        CAST                                              6  ~10     $8
         20        CONCAT                                               ~11     ~10, '%0A'
         21        ECHO                                                         ~11
   79    22        NEW                                                  $12     'Stress'
         23        SEND_VAL_EX                                                  461
         24        SEND_VAL_EX                                                  20
         25        DO_FCALL                                          0          
         26        CAST                                              6  ~14     $12
         27        CONCAT                                               ~15     ~14, '%0A'
         28        ECHO                                                         ~15
   80    29        NEW                                                  $16     'Stress'
         30        SEND_VAL_EX                                                  433
         31        SEND_VAL_EX                                                  30
         32        DO_FCALL                                          0          
         33        CAST                                              6  ~18     $16
         34        CONCAT                                               ~19     ~18, '%0A'
         35        ECHO                                                         ~19
   82    36        NEW                                                  $20     'Stress'
         37        SEND_VAL_EX                                                  239
         38        SEND_VAL_EX                                                  40
         39        DO_FCALL                                          0          
         40        CAST                                              6  ~22     $20
         41        CONCAT                                               ~23     ~22, '%0A'
         42        ECHO                                                         ~23
   83    43        NEW                                                  $24     'Stress'
         44        SEND_VAL_EX                                                  317
         45        SEND_VAL_EX                                                  20
         46        DO_FCALL                                          0          
         47        CAST                                              6  ~26     $24
         48        CONCAT                                               ~27     ~26, '%0A'
         49        ECHO                                                         ~27
   84    50        NEW                                                  $28     'Stress'
         51        SEND_VAL_EX                                                  444
         52        SEND_VAL_EX                                                  80
         53        DO_FCALL                                          0          
         54        CAST                                              6  ~30     $28
         55        CONCAT                                               ~31     ~30, '%0A'
         56        ECHO                                                         ~31
         57      > RETURN                                                       1

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

End of function __construct

Function __tostring:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 11
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vt7eP
function name:  __toString
number of ops:  21
compiled vars:  !0 = $ambiguousRatingIndex, !1 = $rating
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   38     0  E >   INIT_METHOD_CALL                                             'getAmbiguousStressRatingIndex'
          1        DO_FCALL                                          0  $2      
          2        ASSIGN                                                       !0, $2
   40     3        TYPE_CHECK                                      1018          !0
          4      > JMPZ                                                         ~4, ->11
   41     5    >   FETCH_DIM_R                                          ~5      <array>, !0
          6        NOP                                                          
          7        FAST_CONCAT                                          ~6      'Classifica%C3%A7%C3%A3o+%28por+tabela+de+desambigua%C3%A7%C3%A3o%29%3A+', ~5
          8        VERIFY_RETURN_TYPE                                           ~6
          9      > RETURN                                                       ~6
   40    10*       JMP                                                          ->19
   43    11    >   INIT_METHOD_CALL                                             'getGeneralRatingIndex'
         12        DO_FCALL                                          0  $7      
         13        ASSIGN                                                       !1, $7
   44    14        FETCH_DIM_R                                          ~9      <array>, !1
         15        NOP                                                          
         16        FAST_CONCAT                                          ~10     'Classifica%C3%A7%C3%A3o+geral+do+estresse+t%C3%A9rmico+por+aus%C3%AAncia+de+ambiguidade%3A+', ~9
         17        VERIFY_RETURN_TYPE                                           ~10
         18      > RETURN                                                       ~10
   46    19*       VERIFY_RETURN_TYPE                                           
         20*     > RETURN                                                       null

End of function __tostring

Function getambiguousstressratingindex:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 7, Position 2 = 11
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 16
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
filename:       /in/vt7eP
function name:  getAmbiguousStressRatingIndex
number of ops:  18
compiled vars:  !0 = $temp, !1 = $ur
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   50     0  E >   FETCH_OBJ_R                                          ~2      'temp'
          1        ASSIGN                                                       !0, ~2
   51     2        FETCH_OBJ_R                                          ~4      'ur'
          3        ASSIGN                                                       !1, ~4
   53     4        FETCH_CLASS_CONSTANT                                 ~6      'AMBIGUOUS'
          5        ISSET_ISEMPTY_DIM_OBJ                             0  ~7      ~6, !0
          6      > JMPZ_EX                                              ~7      ~7, ->11
          7    >   FETCH_CLASS_CONSTANT                                 ~8      'AMBIGUOUS'
          8        FETCH_DIM_IS                                         ~9      ~8, !0
          9        ISSET_ISEMPTY_DIM_OBJ                             0  ~10     ~9, !1
         10        BOOL                                                 ~7      ~10
         11    > > JMPZ                                                         ~7, ->16
   54    12    >   FETCH_CLASS_CONSTANT                                 ~11     'AMBIGUOUS'
         13        FETCH_DIM_R                                          ~12     ~11, !0
         14        FETCH_DIM_R                                          ~13     ~12, !1
         15      > RETURN                                                       ~13
   56    16    > > RETURN                                                       <false>
   57    17*     > RETURN                                                       null

End of function getambiguousstressratingindex

Function getgeneralratingindex:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 15
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 18
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 21
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 24
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vt7eP
function name:  getGeneralRatingIndex
number of ops:  26
compiled vars:  !0 = $temp, !1 = $ur, !2 = $ITU
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   62     0  E >   FETCH_OBJ_R                                          ~3      'temp'
          1        DIV                                                  ~4      ~3, 10
          2        ASSIGN                                                       !0, ~4
   63     3        FETCH_OBJ_R                                          ~6      'ur'
          4        DIV                                                  ~7      ~6, 100
          5        ASSIGN                                                       !1, ~7
   64     6        MUL                                                  ~9      !0, 0.8
          7        SUB                                                  ~10     !0, 14.4
          8        MUL                                                  ~11     !1, ~10
          9        ADD                                                  ~12     ~9, ~11
         10        ADD                                                  ~13     ~12, 46.4
         11        ASSIGN                                                       !2, ~13
   66    12        IS_SMALLER                                                   !2, 72
         13      > JMPZ                                                         ~15, ->15
         14    > > RETURN                                                       0
   67    15    >   IS_SMALLER                                                   !2, 79
         16      > JMPZ                                                         ~16, ->18
         17    > > RETURN                                                       1
   68    18    >   IS_SMALLER                                                   !2, 90
         19      > JMPZ                                                         ~17, ->21
         20    > > RETURN                                                       2
   69    21    >   IS_SMALLER                                                   !2, 98
         22      > JMPZ                                                         ~18, ->24
         23    > > RETURN                                                       3
   71    24    > > RETURN                                                       4
   72    25*     > RETURN                                                       null

End of function getgeneralratingindex

End of class Stress.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
222.13 ms | 2177 KiB | 13 Q