3v4l.org

run code in 300+ 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 = 13
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vt7eP
function name:  __toString
number of ops:  25
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, ->13
   41     5    >   INIT_FCALL                                               'sprintf'
          6        SEND_VAL                                                 'Classifica%C3%A7%C3%A3o+%28por+tabela+de+desambigua%C3%A7%C3%A3o%29%3A+%25s'
          7        FETCH_DIM_R                                      ~5      <array>, !0
          8        SEND_VAL                                                 ~5
          9        DO_ICALL                                         $6      
         10        VERIFY_RETURN_TYPE                                       $6
         11      > RETURN                                                   $6
         12*       JMP                                                      ->23
   43    13    >   INIT_METHOD_CALL                                         'getGeneralRatingIndex'
         14        DO_FCALL                                      0  $7      
         15        ASSIGN                                                   !1, $7
   44    16        INIT_FCALL                                               'sprintf'
         17        SEND_VAL                                                 'Classifica%C3%A7%C3%A3o+geral+do+estresse+t%C3%A9rmico+por+aus%C3%AAncia+de+ambiguidade%3A+%25s'
         18        FETCH_DIM_R                                      ~9      <array>, !1
         19        SEND_VAL                                                 ~9
         20        DO_ICALL                                         $10     
         21        VERIFY_RETURN_TYPE                                       $10
         22      > RETURN                                                   $10
   46    23*       VERIFY_RETURN_TYPE                                       
         24*     > RETURN                                                   null

End of function __tostring

Function getambiguousstressratingindex:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 6, Position 2 = 9
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 13
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
filename:       /in/vt7eP
function name:  getAmbiguousStressRatingIndex
number of ops:  15
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        ISSET_ISEMPTY_DIM_OBJ                         0  ~6      <array>, !0
          5      > JMPZ_EX                                          ~6      ~6, ->9
          6    >   FETCH_DIM_IS                                     ~7      <array>, !0
          7        ISSET_ISEMPTY_DIM_OBJ                         0  ~8      ~7, !1
          8        BOOL                                             ~6      ~8
          9    > > JMPZ                                                     ~6, ->13
   54    10    >   FETCH_DIM_R                                      ~9      <array>, !0
         11        FETCH_DIM_R                                      ~10     ~9, !1
         12      > RETURN                                                   ~10
   56    13    > > RETURN                                                   <false>
   57    14*     > 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.0.0


preferences:
182 ms | 1408 KiB | 15 Q