3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface PolicyRule { public function isSatisfiedBy(string $aValue); } abstract class EnforcedRule implements PolicyRule { const UNENFORCED = 0; const ENFORCED = 1; private $enforcementType; protected function isEnforced() : bool { return ($this->enforcementType == self::ENFORCED); } protected function setEnforcementType(int $aType) { $this->guardEnforcementType($aType); $this->enforcementType = $aType; } protected function guardEnforcementType(int $aType) : void { if (! in_array($aType, [self::UNENFORCED, self::ENFORCED])) { throw new InvalidEnforcementTypeException($aType); } } } abstract class MinimumCharacterCountRule extends EnforcedRule { const DEFAULT_MINIMUM = 1; protected $regexPattern; protected $minimumCount = self::DEFAULT_MINIMUM; public function isSatisfiedBy(string $aValue) : bool { if (! $this->isEnforced()) { return true; } $matches = []; preg_match_all($this->regexPattern, $aValue, $matches); return (count($matches[0]) >= $this->minimumCount); } } class NumericRule extends MinimumCharacterCountRule { protected $regexPattern = '/[0-9]/'; public function __construct(int $aMinimumCount = self::DEFAULT_MINIMUM, int $anEnforcementType = self::ENFORCED) { $this->setEnforcementType($anEnforcementType); $this->minimumCount = $aMinimumCount; } } class SpecialCharacterRule extends MinimumCharacterCountRule { protected $regexPattern = '/[~`#\$%\^&\*\(\)\-_\+\|,\.<>]/'; public function __construct(int $aMinimumCount = self::DEFAULT_MINIMUM, int $anEnforcementType = self::ENFORCED) { $this->setEnforcementType($anEnforcementType); $this->minimumCount = $aMinimumCount; } } $numeric = new NumericRule(); var_dump($numeric->isSatisfiedBy("for5")); $special = new SpecialCharacterRule(); var_dump($special->isSatisfiedBy("for5"));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Z8nJt
function name:  (null)
number of ops:  23
compiled vars:  !0 = $numeric, !1 = $special
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   DECLARE_CLASS                                            'enforcedrule'
   34     1        DECLARE_CLASS                                            'minimumcharactercountrule', 'enforcedrule'
   55     2        DECLARE_CLASS                                            'numericrule', 'minimumcharactercountrule'
   66     3        DECLARE_CLASS                                            'specialcharacterrule', 'minimumcharactercountrule'
   77     4        NEW                                              $2      'NumericRule'
          5        DO_FCALL                                      0          
          6        ASSIGN                                                   !0, $2
   78     7        INIT_FCALL                                               'var_dump'
          8        INIT_METHOD_CALL                                         !0, 'isSatisfiedBy'
          9        SEND_VAL_EX                                              'for5'
         10        DO_FCALL                                      0  $5      
         11        SEND_VAR                                                 $5
         12        DO_ICALL                                                 
   79    13        NEW                                              $7      'SpecialCharacterRule'
         14        DO_FCALL                                      0          
         15        ASSIGN                                                   !1, $7
   80    16        INIT_FCALL                                               'var_dump'
         17        INIT_METHOD_CALL                                         !1, 'isSatisfiedBy'
         18        SEND_VAL_EX                                              'for5'
         19        DO_FCALL                                      0  $10     
         20        SEND_VAR                                                 $10
         21        DO_ICALL                                                 
         22      > RETURN                                                   1

Class PolicyRule:
Function issatisfiedby:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Z8nJt
function name:  isSatisfiedBy
number of ops:  2
compiled vars:  !0 = $aValue
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
          1      > RETURN                                                   null

End of function issatisfiedby

End of class PolicyRule.

Class EnforcedRule:
Function isenforced:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Z8nJt
function name:  isEnforced
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   FETCH_OBJ_R                                      ~0      'enforcementType'
          1        IS_EQUAL                                         ~1      ~0, 1
          2        VERIFY_RETURN_TYPE                                       ~1
          3      > RETURN                                                   ~1
   18     4*       VERIFY_RETURN_TYPE                                       
          5*     > RETURN                                                   null

End of function isenforced

Function setenforcementtype:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Z8nJt
function name:  setEnforcementType
number of ops:  7
compiled vars:  !0 = $aType
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   RECV                                             !0      
   22     1        INIT_METHOD_CALL                                         'guardEnforcementType'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
   23     4        ASSIGN_OBJ                                               'enforcementType'
          5        OP_DATA                                                  !0
   24     6      > RETURN                                                   null

End of function setenforcementtype

Function guardenforcementtype:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 11
Branch analysis from position: 7
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Z8nJt
function name:  guardEnforcementType
number of ops:  12
compiled vars:  !0 = $aType
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   RECV                                             !0      
   28     1        INIT_FCALL                                               'in_array'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 <array>
          4        DO_ICALL                                         $1      
          5        BOOL_NOT                                         ~2      $1
          6      > JMPZ                                                     ~2, ->11
   29     7    >   NEW                                              $3      'InvalidEnforcementTypeException'
          8        SEND_VAR_EX                                              !0
          9        DO_FCALL                                      0          
         10      > THROW                                         0          $3
   31    11    > > RETURN                                                   null

End of function guardenforcementtype

End of class EnforcedRule.

Class MinimumCharacterCountRule:
Function issatisfiedby:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 6
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Z8nJt
function name:  isSatisfiedBy
number of ops:  21
compiled vars:  !0 = $aValue, !1 = $matches
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   42     0  E >   RECV                                             !0      
   44     1        INIT_METHOD_CALL                                         'isEnforced'
          2        DO_FCALL                                      0  $2      
          3        BOOL_NOT                                         ~3      $2
          4      > JMPZ                                                     ~3, ->6
   45     5    > > RETURN                                                   <true>
   48     6    >   ASSIGN                                                   !1, <array>
   49     7        INIT_FCALL                                               'preg_match_all'
          8        FETCH_OBJ_R                                      ~5      'regexPattern'
          9        SEND_VAL                                                 ~5
         10        SEND_VAR                                                 !0
         11        SEND_REF                                                 !1
         12        DO_ICALL                                                 
   51    13        FETCH_DIM_R                                      ~7      !1, 0
         14        COUNT                                            ~8      ~7
         15        FETCH_OBJ_R                                      ~9      'minimumCount'
         16        IS_SMALLER_OR_EQUAL                              ~10     ~9, ~8
         17        VERIFY_RETURN_TYPE                                       ~10
         18      > RETURN                                                   ~10
   52    19*       VERIFY_RETURN_TYPE                                       
         20*     > RETURN                                                   null

End of function issatisfiedby

End of class MinimumCharacterCountRule.

Class NumericRule:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Z8nJt
function name:  __construct
number of ops:  8
compiled vars:  !0 = $aMinimumCount, !1 = $anEnforcementType
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   59     0  E >   RECV_INIT                                        !0      <const ast>
          1        RECV_INIT                                        !1      <const ast>
   61     2        INIT_METHOD_CALL                                         'setEnforcementType'
          3        SEND_VAR_EX                                              !1
          4        DO_FCALL                                      0          
   62     5        ASSIGN_OBJ                                               'minimumCount'
          6        OP_DATA                                                  !0
   63     7      > RETURN                                                   null

End of function __construct

End of class NumericRule.

Class SpecialCharacterRule:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Z8nJt
function name:  __construct
number of ops:  8
compiled vars:  !0 = $aMinimumCount, !1 = $anEnforcementType
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   70     0  E >   RECV_INIT                                        !0      <const ast>
          1        RECV_INIT                                        !1      <const ast>
   72     2        INIT_METHOD_CALL                                         'setEnforcementType'
          3        SEND_VAR_EX                                              !1
          4        DO_FCALL                                      0          
   73     5        ASSIGN_OBJ                                               'minimumCount'
          6        OP_DATA                                                  !0
   74     7      > RETURN                                                   null

End of function __construct

End of class SpecialCharacterRule.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
174.17 ms | 1404 KiB | 19 Q