3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Assert { private const UUID_LENGTH = 32; public static function validUuid(string $value) : string { if (strlen($value) !== static::UUID_LENGTH || false === ctype_xdigit($value)) { throw new \InvalidArgumentException('Wrong uuid format.'); } return __CLASS__; } public static function notEmptyString(string $value) : string { if ('' === $value) { throw new InvalidArgumentException('Value must not be empty.'); } return __CLASS__; } public static function notEmptyArray(array $value) : string { if (0 >= count($value)) { throw new InvalidArgumentException('Array must not be empty.'); } return __CLASS__; } } class Id { private string $value; public function __construct(?string $uuid = null) { $uuid = $uuid ?? $this->generateuuidV4(); Assert::validUuid($uuid); $this->value = $uuid; } public function __toString() : string { return $this->value; } public function isEqual(Id $id) : bool { return $this->value === (string)$id; } private function generateUuidV4() : string { return bin2hex(random_bytes(16)); } } interface Entity { public function getId() : Id; } class Comment implements Entity { private Id $id; private Id $userId; private string $text; public function __construct(Id $id, Id $userId, string $text) { Assert::notEmptyString($text); $this->id = $id; $this->userId = $userId; $this->text = $text; } public function getId() : Id { return $this->id; } public function getText() : string { return $this->text; } public function changeText(string $text) : void { $this->text = $text; } } class ModeratedComment extends Comment { private Comment $comment; public function __construct(Comment $comment) { $this->comment = $this->moderate($comment); } public function getId() : Id { return $this->comment->getId(); } public function getText() : string { return $this->comment->getText(); } public function changeText(string $text) : void { $this->comment->changeText($text); $this->comment = $this->moderate($this->comment); } private function moderate(Comment $comment) : Comment { $comment->changeText('Моча - сила'); return $comment; } } class Feed implements Entity { private Id $id; private Id $ownerId; private array $publishers; private array $comments; public function __construct( Id $id, Id $ownerId, array $publishers, array $comments = [] ) { Assert::notEmptyArray($publishers); $this->id = $id; $this->ownerId = $ownerId; $this->publishers = $publishers; $this->comments = $comments; } public function getId() : Id { return $this->id; } public function addComment(ModeratedComment $moderatedComment) { $this->comments[(string)$moderatedComment->getId()] = $moderatedComment; } } $feedId = new Id('3a90426a01e414d00f281ae92436f11d'); $feedOwnerId = new Id('da41d5f6b9ef685ddc3fc58f8f2b33f8'); $firstPublisherId = new Id('da41d5f6b9ef685ddc3fc58f8f2b33f8'); $secondPublisherId = new Id('76319d3a35d3ec306dc299d446ab46e6'); $publishers = [ (string)$firstPublisherId => $firstPublisherId, (string)$secondPublisherId => $secondPublisherId, ]; $feed = new Feed($feedId, $feedOwnerId, $publishers); $userId = new Id('da41d5f6b9ef685ddc3fc58f8f2b33f8'); $moderatedComment = new ModeratedComment(new Comment(new Id, $userId, 'Test comment')); $feed->addComment($moderatedComment); var_dump($feed);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/c81Oi
function name:  (null)
number of ops:  53
compiled vars:  !0 = $feedId, !1 = $feedOwnerId, !2 = $firstPublisherId, !3 = $secondPublisherId, !4 = $publishers, !5 = $feed, !6 = $userId, !7 = $moderatedComment
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   DECLARE_CLASS                                            'id'
   69     1        DECLARE_CLASS                                            'comment'
  100     2        DECLARE_CLASS                                            'moderatedcomment', 'comment'
  133     3        DECLARE_CLASS                                            'feed'
  164     4        NEW                                              $8      'Id'
          5        SEND_VAL_EX                                              '3a90426a01e414d00f281ae92436f11d'
          6        DO_FCALL                                      0          
          7        ASSIGN                                                   !0, $8
  165     8        NEW                                              $11     'Id'
          9        SEND_VAL_EX                                              'da41d5f6b9ef685ddc3fc58f8f2b33f8'
         10        DO_FCALL                                      0          
         11        ASSIGN                                                   !1, $11
  166    12        NEW                                              $14     'Id'
         13        SEND_VAL_EX                                              'da41d5f6b9ef685ddc3fc58f8f2b33f8'
         14        DO_FCALL                                      0          
         15        ASSIGN                                                   !2, $14
  167    16        NEW                                              $17     'Id'
         17        SEND_VAL_EX                                              '76319d3a35d3ec306dc299d446ab46e6'
         18        DO_FCALL                                      0          
         19        ASSIGN                                                   !3, $17
  169    20        CAST                                          6  ~20     !2
         21        INIT_ARRAY                                       ~21     !2, ~20
  170    22        CAST                                          6  ~22     !3
         23        ADD_ARRAY_ELEMENT                                ~21     !3, ~22
  168    24        ASSIGN                                                   !4, ~21
  172    25        NEW                                              $24     'Feed'
         26        SEND_VAR_EX                                              !0
         27        SEND_VAR_EX                                              !1
         28        SEND_VAR_EX                                              !4
         29        DO_FCALL                                      0          
         30        ASSIGN                                                   !5, $24
  174    31        NEW                                              $27     'Id'
         32        SEND_VAL_EX                                              'da41d5f6b9ef685ddc3fc58f8f2b33f8'
         33        DO_FCALL                                      0          
         34        ASSIGN                                                   !6, $27
  175    35        NEW                                              $30     'ModeratedComment'
         36        NEW                                              $31     'Comment'
         37        NEW                                              $32     'Id'
         38        DO_FCALL                                      0          
         39        SEND_VAR_NO_REF_EX                                       $32
         40        SEND_VAR_EX                                              !6
         41        SEND_VAL_EX                                              'Test+comment'
         42        DO_FCALL                                      0          
         43        SEND_VAR_NO_REF_EX                                       $31
         44        DO_FCALL                                      0          
         45        ASSIGN                                                   !7, $30
  176    46        INIT_METHOD_CALL                                         !5, 'addComment'
         47        SEND_VAR_EX                                              !7
         48        DO_FCALL                                      0          
  178    49        INIT_FCALL                                               'var_dump'
         50        SEND_VAR                                                 !5
         51        DO_ICALL                                                 
         52      > RETURN                                                   1

Class Assert:
Function validuuid:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 5, Position 2 = 10
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 15
Branch analysis from position: 11
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
filename:       /in/c81Oi
function name:  validUuid
number of ops:  18
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
    9     1        STRLEN                                           ~1      !0
          2        FETCH_CLASS_CONSTANT                             ~2      'UUID_LENGTH'
          3        IS_NOT_IDENTICAL                                 ~3      ~1, ~2
          4      > JMPNZ_EX                                         ~3      ~3, ->10
          5    >   INIT_FCALL                                               'ctype_xdigit'
          6        SEND_VAR                                                 !0
          7        DO_ICALL                                         $4      
          8        TYPE_CHECK                                    4  ~5      $4
          9        BOOL                                             ~3      ~5
         10    > > JMPZ                                                     ~3, ->15
   10    11    >   NEW                                              $6      'InvalidArgumentException'
         12        SEND_VAL_EX                                              'Wrong+uuid+format.'
         13        DO_FCALL                                      0          
         14      > THROW                                         0          $6
   13    15    > > RETURN                                                   'Assert'
   14    16*       VERIFY_RETURN_TYPE                                       
         17*     > RETURN                                                   null

End of function validuuid

Function notemptystring:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 7
Branch analysis from position: 3
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/c81Oi
function name:  notEmptyString
number of ops:  10
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
   18     1        IS_IDENTICAL                                             !0, ''
          2      > JMPZ                                                     ~1, ->7
   19     3    >   NEW                                              $2      'InvalidArgumentException'
          4        SEND_VAL_EX                                              'Value+must+not+be+empty.'
          5        DO_FCALL                                      0          
          6      > THROW                                         0          $2
   22     7    > > RETURN                                                   'Assert'
   23     8*       VERIFY_RETURN_TYPE                                       
          9*     > RETURN                                                   null

End of function notemptystring

Function notemptyarray:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 8
Branch analysis from position: 4
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/c81Oi
function name:  notEmptyArray
number of ops:  11
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   RECV                                             !0      
   27     1        COUNT                                            ~1      !0
          2        IS_SMALLER_OR_EQUAL                                      ~1, 0
          3      > JMPZ                                                     ~2, ->8
   28     4    >   NEW                                              $3      'InvalidArgumentException'
          5        SEND_VAL_EX                                              'Array+must+not+be+empty.'
          6        DO_FCALL                                      0          
          7      > THROW                                         0          $3
   31     8    > > RETURN                                                   'Assert'
   32     9*       VERIFY_RETURN_TYPE                                       
         10*     > RETURN                                                   null

End of function notemptyarray

End of class Assert.

Class Id:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/c81Oi
function name:  __construct
number of ops:  12
compiled vars:  !0 = $uuid
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   RECV_INIT                                        !0      null
   41     1        COALESCE                                         ~1      !0
          2        INIT_METHOD_CALL                                         'generateuuidV4'
          3        DO_FCALL                                      0  $2      
          4        QM_ASSIGN                                        ~1      $2
          5        ASSIGN                                                   !0, ~1
   43     6        INIT_STATIC_METHOD_CALL                                  'Assert', 'validUuid'
          7        SEND_VAR                                                 !0
          8        DO_FCALL                                      0          
   45     9        ASSIGN_OBJ                                               'value'
         10        OP_DATA                                                  !0
   46    11      > RETURN                                                   null

End of function __construct

Function __tostring:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/c81Oi
function name:  __toString
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   50     0  E >   FETCH_OBJ_R                                      ~0      'value'
          1        VERIFY_RETURN_TYPE                                       ~0
          2      > RETURN                                                   ~0
   51     3*       VERIFY_RETURN_TYPE                                       
          4*     > RETURN                                                   null

End of function __tostring

Function isequal:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/c81Oi
function name:  isEqual
number of ops:  8
compiled vars:  !0 = $id
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   53     0  E >   RECV                                             !0      
   55     1        FETCH_OBJ_R                                      ~1      'value'
          2        CAST                                          6  ~2      !0
          3        IS_IDENTICAL                                     ~3      ~1, ~2
          4        VERIFY_RETURN_TYPE                                       ~3
          5      > RETURN                                                   ~3
   56     6*       VERIFY_RETURN_TYPE                                       
          7*     > RETURN                                                   null

End of function isequal

Function generateuuidv4:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/c81Oi
function name:  generateUuidV4
number of ops:  10
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   60     0  E >   INIT_FCALL                                               'bin2hex'
          1        INIT_FCALL                                               'random_bytes'
          2        SEND_VAL                                                 16
          3        DO_ICALL                                         $0      
          4        SEND_VAR                                                 $0
          5        DO_ICALL                                         $1      
          6        VERIFY_RETURN_TYPE                                       $1
          7      > RETURN                                                   $1
   61     8*       VERIFY_RETURN_TYPE                                       
          9*     > RETURN                                                   null

End of function generateuuidv4

End of class Id.

Class Entity:
Function getid:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/c81Oi
function name:  getId
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   66     0  E >   VERIFY_RETURN_TYPE                                       
          1      > RETURN                                                   null

End of function getid

End of class Entity.

Class Comment:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/c81Oi
function name:  __construct
number of ops:  13
compiled vars:  !0 = $id, !1 = $userId, !2 = $text
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   75     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   77     3        INIT_STATIC_METHOD_CALL                                  'Assert', 'notEmptyString'
          4        SEND_VAR                                                 !2
          5        DO_FCALL                                      0          
   79     6        ASSIGN_OBJ                                               'id'
          7        OP_DATA                                                  !0
   80     8        ASSIGN_OBJ                                               'userId'
          9        OP_DATA                                                  !1
   81    10        ASSIGN_OBJ                                               'text'
         11        OP_DATA                                                  !2
   82    12      > RETURN                                                   null

End of function __construct

Function getid:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/c81Oi
function name:  getId
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   86     0  E >   FETCH_OBJ_R                                      ~0      'id'
          1        VERIFY_RETURN_TYPE                                       ~0
          2      > RETURN                                                   ~0
   87     3*       VERIFY_RETURN_TYPE                                       
          4*     > RETURN                                                   null

End of function getid

Function gettext:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/c81Oi
function name:  getText
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   91     0  E >   FETCH_OBJ_R                                      ~0      'text'
          1        VERIFY_RETURN_TYPE                                       ~0
          2      > RETURN                                                   ~0
   92     3*       VERIFY_RETURN_TYPE                                       
          4*     > RETURN                                                   null

End of function gettext

Function changetext:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/c81Oi
function name:  changeText
number of ops:  4
compiled vars:  !0 = $text
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   94     0  E >   RECV                                             !0      
   96     1        ASSIGN_OBJ                                               'text'
          2        OP_DATA                                                  !0
   97     3      > RETURN                                                   null

End of function changetext

End of class Comment.

Class ModeratedComment:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/c81Oi
function name:  __construct
number of ops:  7
compiled vars:  !0 = $comment
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  104     0  E >   RECV                                             !0      
  106     1        INIT_METHOD_CALL                                         'moderate'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0  $2      
          4        ASSIGN_OBJ                                               'comment'
          5        OP_DATA                                                  $2
  107     6      > RETURN                                                   null

End of function __construct

Function getid:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/c81Oi
function name:  getId
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  111     0  E >   FETCH_OBJ_R                                      ~0      'comment'
          1        INIT_METHOD_CALL                                         ~0, 'getId'
          2        DO_FCALL                                      0  $1      
          3        VERIFY_RETURN_TYPE                                       $1
          4      > RETURN                                                   $1
  112     5*       VERIFY_RETURN_TYPE                                       
          6*     > RETURN                                                   null

End of function getid

Function gettext:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/c81Oi
function name:  getText
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  116     0  E >   FETCH_OBJ_R                                      ~0      'comment'
          1        INIT_METHOD_CALL                                         ~0, 'getText'
          2        DO_FCALL                                      0  $1      
          3        VERIFY_RETURN_TYPE                                       $1
          4      > RETURN                                                   $1
  117     5*       VERIFY_RETURN_TYPE                                       
          6*     > RETURN                                                   null

End of function gettext

Function changetext:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/c81Oi
function name:  changeText
number of ops:  13
compiled vars:  !0 = $text
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  119     0  E >   RECV                                             !0      
  121     1        FETCH_OBJ_R                                      ~1      'comment'
          2        INIT_METHOD_CALL                                         ~1, 'changeText'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0          
  122     5        INIT_METHOD_CALL                                         'moderate'
          6        CHECK_FUNC_ARG                                           
          7        FETCH_OBJ_FUNC_ARG                               $4      'comment'
          8        SEND_FUNC_ARG                                            $4
          9        DO_FCALL                                      0  $5      
         10        ASSIGN_OBJ                                               'comment'
         11        OP_DATA                                                  $5
  123    12      > RETURN                                                   null

End of function changetext

Function moderate:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/c81Oi
function name:  moderate
number of ops:  8
compiled vars:  !0 = $comment
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  125     0  E >   RECV                                             !0      
  127     1        INIT_METHOD_CALL                                         !0, 'changeText'
          2        SEND_VAL_EX                                              '%D0%9C%D0%BE%D1%87%D0%B0+-+%D1%81%D0%B8%D0%BB%D0%B0'
          3        DO_FCALL                                      0          
  129     4        VERIFY_RETURN_TYPE                                       !0
          5      > RETURN                                                   !0
  130     6*       VERIFY_RETURN_TYPE                                       
          7*     > RETURN                                                   null

End of function moderate

End of class ModeratedComment.

Class Feed:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/c81Oi
function name:  __construct
number of ops:  16
compiled vars:  !0 = $id, !1 = $ownerId, !2 = $publishers, !3 = $comments
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  140     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV_INIT                                        !3      <array>
  146     4        INIT_STATIC_METHOD_CALL                                  'Assert', 'notEmptyArray'
          5        SEND_VAR                                                 !2
          6        DO_FCALL                                      0          
  148     7        ASSIGN_OBJ                                               'id'
          8        OP_DATA                                                  !0
  149     9        ASSIGN_OBJ                                               'ownerId'
         10        OP_DATA                                                  !1
  150    11        ASSIGN_OBJ                                               'publishers'
         12        OP_DATA                                                  !2
  151    13        ASSIGN_OBJ                                               'comments'
         14        OP_DATA                                                  !3
  152    15      > RETURN                                                   null

End of function __construct

Function getid:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/c81Oi
function name:  getId
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  156     0  E >   FETCH_OBJ_R                                      ~0      'id'
          1        VERIFY_RETURN_TYPE                                       ~0
          2      > RETURN                                                   ~0
  157     3*       VERIFY_RETURN_TYPE                                       
          4*     > RETURN                                                   null

End of function getid

Function addcomment:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/c81Oi
function name:  addComment
number of ops:  8
compiled vars:  !0 = $moderatedComment
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  159     0  E >   RECV                                             !0      
  160     1        INIT_METHOD_CALL                                         !0, 'getId'
          2        DO_FCALL                                      0  $2      
          3        CAST                                          6  ~3      $2
          4        FETCH_OBJ_W                                      $1      'comments'
          5        ASSIGN_DIM                                               $1, ~3
          6        OP_DATA                                                  !0
  161     7      > RETURN                                                   null

End of function addcomment

End of class Feed.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.55 ms | 1420 KiB | 21 Q