3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Poll { private array $points; private RatingCost $cost; private array $votes = []; private array $votedUsers = []; public function __construct(array $points, RatingCost $cost, array $votes = [], array $votedUsers = []) { $this->points = $points; $this->cost = $cost; $this->votes = $votes; $this->votedUsers = $votedUsers; } public function vote(Vote $vote) { $this->votes[] = $vote; $votedUser = $vote->getUser(); $this->votedUsers[] = $votedUser; $votedUser->increaseRating($this->cost); } } class Vote { private User $user; private PollingPoint $point; public function __construct(User $user, PollingPoint $point) { $this->user = $user; $this->point = $point; } public function getUser() : User { return $this->user; } } class PollingPoint { private string $id; private string $value; public function __construct(string $id, string $value) { $this->id = $id; $this->value = $value; } } class User { private string $id; private Rating $rating; public function __construct(string $id, Rating $rating) { $this->id = $id; $this->rating = $rating; } public function increaseRating(RatingCost $cost) { $this->rating->increase($cost); } } class Rating { private int $value; public function __construct(int $value) { $this->value = $value; } public function increase(RatingCost $cost) { $this->value += $cost->getValue(); } } class RatingCost { private $value; public function __construct(int $value) { $this->value = $value; } public function getValue() : int { return $this->value; } } class VotePoll { public function __invoke(string $pollId, string $userId, string $pointId) { //$poll = $em->getPoll($pollId); $cost = new RatingCost(30); $firstPoint = new PollingPoint('firstPoint', 'Подписыюсь'); $secondPoint = new PollingPoint('secondPoint', 'За русь ем закусь'); $poll = new Poll([$firstPoint, $secondPoint], $cost); //$user = $em->getUser($userId); $rating = new Rating(1488); $user = new User('firstUser', $rating); $vote = new Vote($user, $firstPoint); $poll->vote($vote); //$em->flush(); return $user; } } print_r((new VotePoll)('pollId', 'userId', 'pointId'));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AREPJ
function name:  (null)
number of ops:  11
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  108     0  E >   INIT_FCALL                                               'print_r'
          1        NEW                                              $0      'VotePoll'
          2        DO_FCALL                                      0          
          3        INIT_DYNAMIC_CALL                                        $0
          4        SEND_VAL_EX                                              'pollId'
          5        SEND_VAL_EX                                              'userId'
          6        SEND_VAL_EX                                              'pointId'
          7        DO_FCALL                                      0  $2      
          8        SEND_VAR                                                 $2
          9        DO_ICALL                                                 
         10      > RETURN                                                   1

Class Poll:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AREPJ
function name:  __construct
number of ops:  13
compiled vars:  !0 = $points, !1 = $cost, !2 = $votes, !3 = $votedUsers
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      <array>
          3        RECV_INIT                                        !3      <array>
   10     4        ASSIGN_OBJ                                               'points'
          5        OP_DATA                                                  !0
   11     6        ASSIGN_OBJ                                               'cost'
          7        OP_DATA                                                  !1
   12     8        ASSIGN_OBJ                                               'votes'
          9        OP_DATA                                                  !2
   13    10        ASSIGN_OBJ                                               'votedUsers'
         11        OP_DATA                                                  !3
   14    12      > RETURN                                                   null

End of function __construct

Function vote:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AREPJ
function name:  vote
number of ops:  16
compiled vars:  !0 = $vote, !1 = $votedUser
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
   17     1        FETCH_OBJ_W                                      $2      'votes'
          2        ASSIGN_DIM                                               $2
          3        OP_DATA                                                  !0
   18     4        INIT_METHOD_CALL                                         !0, 'getUser'
          5        DO_FCALL                                      0  $4      
          6        ASSIGN                                                   !1, $4
   19     7        FETCH_OBJ_W                                      $6      'votedUsers'
          8        ASSIGN_DIM                                               $6
          9        OP_DATA                                                  !1
   21    10        INIT_METHOD_CALL                                         !1, 'increaseRating'
         11        CHECK_FUNC_ARG                                           
         12        FETCH_OBJ_FUNC_ARG                               $8      'cost'
         13        SEND_FUNC_ARG                                            $8
         14        DO_FCALL                                      0          
   22    15      > RETURN                                                   null

End of function vote

End of class Poll.

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

End of function __construct

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

End of function getuser

End of class Vote.

Class PollingPoint:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AREPJ
function name:  __construct
number of ops:  7
compiled vars:  !0 = $id, !1 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   43     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   44     2        ASSIGN_OBJ                                               'id'
          3        OP_DATA                                                  !0
   45     4        ASSIGN_OBJ                                               'value'
          5        OP_DATA                                                  !1
   46     6      > RETURN                                                   null

End of function __construct

End of class PollingPoint.

Class User:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AREPJ
function name:  __construct
number of ops:  7
compiled vars:  !0 = $id, !1 = $rating
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   53     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   54     2        ASSIGN_OBJ                                               'id'
          3        OP_DATA                                                  !0
   55     4        ASSIGN_OBJ                                               'rating'
          5        OP_DATA                                                  !1
   56     6      > RETURN                                                   null

End of function __construct

Function increaserating:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AREPJ
function name:  increaseRating
number of ops:  6
compiled vars:  !0 = $cost
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   58     0  E >   RECV                                             !0      
   59     1        FETCH_OBJ_R                                      ~1      'rating'
          2        INIT_METHOD_CALL                                         ~1, 'increase'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0          
   60     5      > RETURN                                                   null

End of function increaserating

End of class User.

Class Rating:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AREPJ
function name:  __construct
number of ops:  4
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   66     0  E >   RECV                                             !0      
   67     1        ASSIGN_OBJ                                               'value'
          2        OP_DATA                                                  !0
   68     3      > RETURN                                                   null

End of function __construct

Function increase:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AREPJ
function name:  increase
number of ops:  6
compiled vars:  !0 = $cost
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   70     0  E >   RECV                                             !0      
   71     1        INIT_METHOD_CALL                                         !0, 'getValue'
          2        DO_FCALL                                      0  $2      
          3        ASSIGN_OBJ_OP                                 1          'value'
          4        OP_DATA                                                  $2
   72     5      > RETURN                                                   null

End of function increase

End of class Rating.

Class RatingCost:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AREPJ
function name:  __construct
number of ops:  4
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   78     0  E >   RECV                                             !0      
   79     1        ASSIGN_OBJ                                               'value'
          2        OP_DATA                                                  !0
   80     3      > RETURN                                                   null

End of function __construct

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

End of function getvalue

End of class RatingCost.

Class VotePoll:
Function __invoke:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AREPJ
function name:  __invoke
number of ops:  43
compiled vars:  !0 = $pollId, !1 = $userId, !2 = $pointId, !3 = $cost, !4 = $firstPoint, !5 = $secondPoint, !6 = $poll, !7 = $rating, !8 = $user, !9 = $vote
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   88     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   90     3        NEW                                              $10     'RatingCost'
          4        SEND_VAL_EX                                              30
          5        DO_FCALL                                      0          
          6        ASSIGN                                                   !3, $10
   91     7        NEW                                              $13     'PollingPoint'
          8        SEND_VAL_EX                                              'firstPoint'
          9        SEND_VAL_EX                                              '%D0%9F%D0%BE%D0%B4%D0%BF%D0%B8%D1%81%D1%8B%D1%8E%D1%81%D1%8C'
         10        DO_FCALL                                      0          
         11        ASSIGN                                                   !4, $13
   92    12        NEW                                              $16     'PollingPoint'
         13        SEND_VAL_EX                                              'secondPoint'
         14        SEND_VAL_EX                                              '%D0%97%D0%B0+%D1%80%D1%83%D1%81%D1%8C+%D0%B5%D0%BC+%D0%B7%D0%B0%D0%BA%D1%83%D1%81%D1%8C'
         15        DO_FCALL                                      0          
         16        ASSIGN                                                   !5, $16
   93    17        NEW                                              $19     'Poll'
         18        INIT_ARRAY                                       ~20     !4
         19        ADD_ARRAY_ELEMENT                                ~20     !5
         20        SEND_VAL_EX                                              ~20
         21        SEND_VAR_EX                                              !3
         22        DO_FCALL                                      0          
         23        ASSIGN                                                   !6, $19
   96    24        NEW                                              $23     'Rating'
         25        SEND_VAL_EX                                              1488
         26        DO_FCALL                                      0          
         27        ASSIGN                                                   !7, $23
   97    28        NEW                                              $26     'User'
         29        SEND_VAL_EX                                              'firstUser'
         30        SEND_VAR_EX                                              !7
         31        DO_FCALL                                      0          
         32        ASSIGN                                                   !8, $26
   99    33        NEW                                              $29     'Vote'
         34        SEND_VAR_EX                                              !8
         35        SEND_VAR_EX                                              !4
         36        DO_FCALL                                      0          
         37        ASSIGN                                                   !9, $29
  100    38        INIT_METHOD_CALL                                         !6, 'vote'
         39        SEND_VAR_EX                                              !9
         40        DO_FCALL                                      0          
  104    41      > RETURN                                                   !8
  105    42*     > RETURN                                                   null

End of function __invoke

End of class VotePoll.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
136.91 ms | 1015 KiB | 14 Q