Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
29 | class CreateRegistrationCommand extends Command implements CommandRequiresCapCheckInterface |
||
30 | { |
||
31 | |||
32 | /** |
||
33 | * @var EE_Transaction $transaction |
||
34 | */ |
||
35 | private $transaction; |
||
36 | |||
37 | /** |
||
38 | * @var EE_Ticket $ticket |
||
39 | */ |
||
40 | private $ticket; |
||
41 | |||
42 | /** |
||
43 | * @var EE_Line_Item $ticket_line_item |
||
44 | */ |
||
45 | private $ticket_line_item; |
||
46 | |||
47 | /** |
||
48 | * @var int $reg_count |
||
49 | */ |
||
50 | private $reg_count; |
||
51 | |||
52 | /** |
||
53 | * @var int $reg_group_size |
||
54 | */ |
||
55 | private $reg_group_size; |
||
56 | |||
57 | /** |
||
58 | * @var string $reg_status |
||
59 | */ |
||
60 | private $reg_status; |
||
61 | |||
62 | /** |
||
63 | * @var EE_Registration $registration |
||
64 | */ |
||
65 | protected $registration; |
||
66 | |||
67 | |||
68 | |||
69 | /** |
||
70 | * CreateRegistrationCommand constructor. |
||
71 | * |
||
72 | * @param EE_Transaction $transaction |
||
73 | * @param EE_Line_Item $ticket_line_item |
||
74 | * @param int $reg_count |
||
75 | * @param int $reg_group_size |
||
76 | * @param string $reg_status |
||
77 | * @throws InvalidEntityException |
||
78 | */ |
||
79 | public function __construct( |
||
80 | EE_Transaction $transaction, |
||
81 | EE_Line_Item $ticket_line_item, |
||
82 | $reg_count = 1, |
||
83 | $reg_group_size = 0, |
||
84 | $reg_status = EEM_Registration::status_id_incomplete |
||
85 | ) { |
||
86 | // grab the related ticket object for this line_item |
||
87 | $this->ticket = $ticket_line_item->ticket(); |
||
88 | View Code Duplication | if ( ! $this->ticket instanceof EE_Ticket) { |
|
89 | throw new InvalidEntityException( |
||
90 | is_object($this->ticket) ? get_class($this->ticket) : gettype($this->ticket), |
||
91 | 'EE_Ticket', |
||
92 | sprintf( |
||
93 | __('Line item %s did not contain a valid ticket', 'event_espresso'), |
||
94 | $ticket_line_item->ID() |
||
95 | ) |
||
96 | ); |
||
97 | } |
||
98 | $this->transaction = $transaction; |
||
99 | $this->ticket_line_item = $ticket_line_item; |
||
100 | $this->reg_count = absint($reg_count); |
||
101 | $this->reg_group_size = absint($reg_group_size); |
||
102 | $this->reg_status = $reg_status; |
||
103 | } |
||
104 | |||
105 | |||
106 | |||
107 | /** |
||
108 | * @return \EventEspresso\core\domain\services\capabilities\CapCheckInterface |
||
109 | * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
||
110 | */ |
||
111 | public function getCapCheck() |
||
118 | |||
119 | |||
120 | |||
121 | /** |
||
122 | * @return EE_Transaction |
||
123 | */ |
||
124 | public function transaction() |
||
128 | |||
129 | |||
130 | |||
131 | /** |
||
132 | * @return EE_Ticket |
||
133 | */ |
||
134 | public function ticket() |
||
138 | |||
139 | |||
140 | |||
141 | /** |
||
142 | * @return EE_Line_Item |
||
143 | */ |
||
144 | public function ticketLineItem() |
||
148 | |||
149 | |||
150 | |||
151 | /** |
||
152 | * @return int |
||
153 | */ |
||
154 | public function regCount() |
||
158 | |||
159 | |||
160 | |||
161 | /** |
||
162 | * @return int |
||
163 | */ |
||
164 | public function regGroupSize() |
||
168 | |||
169 | |||
170 | |||
171 | /** |
||
172 | * @return string |
||
173 | */ |
||
174 | public function regStatus() |
||
178 | |||
179 | |||
180 | |||
181 | /** |
||
182 | * @return EE_Registration |
||
183 | */ |
||
184 | public function registration() |
||
188 | |||
189 | |||
190 | |||
191 | } |
||
192 | // End of file CreateRegistrationCommand.php |
||
193 | // Location: /CreateRegistrationCommand.php |