1 | <?php |
||
11 | class Promocodes |
||
12 | { |
||
13 | /** |
||
14 | * Generated codes will be saved here |
||
15 | * to be validated later. |
||
16 | * |
||
17 | * @var array |
||
18 | */ |
||
19 | private $codes = []; |
||
20 | |||
21 | /** |
||
22 | * Length of code will be calculated from asterisks you have |
||
23 | * set as mask in your config file. |
||
24 | * |
||
25 | * @var int |
||
26 | */ |
||
27 | private $length; |
||
28 | |||
29 | /** |
||
30 | * Promocodes constructor. |
||
31 | */ |
||
32 | public function __construct() |
||
38 | |||
39 | /** |
||
40 | * Generates promocodes as many as you wish. |
||
41 | * |
||
42 | * @param int $amount |
||
43 | * |
||
44 | * @return array |
||
45 | */ |
||
46 | public function output($amount = 1) |
||
62 | |||
63 | /** |
||
64 | * Save promocodes into database |
||
65 | * Successful insert returns generated promocodes |
||
66 | * Fail will return empty collection. |
||
67 | * |
||
68 | * @param int $amount |
||
69 | * @param null $reward |
||
70 | * @param array $data |
||
71 | * @param int|null $expires_in |
||
72 | * @param bool $is_disposable |
||
73 | * |
||
74 | * @return \Illuminate\Support\Collection |
||
75 | */ |
||
76 | public function create($amount = 1, $reward = null, array $data = [], $expires_in = null, $is_disposable = false) |
||
99 | |||
100 | /** |
||
101 | * Save one-time use promocodes into database |
||
102 | * Successful insert returns generated promocodes |
||
103 | * Fail will return empty collection. |
||
104 | * |
||
105 | * @param int $amount |
||
106 | * @param null $reward |
||
107 | * @param array $data |
||
108 | * @param int|null $expires_in |
||
109 | * |
||
110 | * @return \Illuminate\Support\Collection |
||
111 | */ |
||
112 | public function createDisposable($amount = 1, $reward = null, array $data = [], $expires_in = null) |
||
116 | |||
117 | /** |
||
118 | * Check promocode in database if it is valid. |
||
119 | * |
||
120 | * @param string $code |
||
121 | * |
||
122 | * @return bool|\Gabievi\Promocodes\Model\Promocode |
||
123 | * @throws \Gabievi\Promocodes\Exceptions\InvalidPromocodeExceprion |
||
124 | */ |
||
125 | public function check($code) |
||
139 | |||
140 | /** |
||
141 | * Apply promocode to user that it's used from now. |
||
142 | * |
||
143 | * @param string $code |
||
144 | * |
||
145 | * @return bool|\Gabievi\Promocodes\Model\Promocode |
||
146 | * @throws \Gabievi\Promocodes\Exceptions\UnauthenticatedExceprion|\Gabievi\Promocodes\Exceptions\AlreadyUsedExceprion |
||
147 | */ |
||
148 | public function apply($code) |
||
172 | |||
173 | /** |
||
174 | * Reedem promocode to user that it's used from now. |
||
175 | * |
||
176 | * @param string $code |
||
177 | * |
||
178 | * @return bool|\Gabievi\Promocodes\Model\Promocode |
||
179 | * @throws \Gabievi\Promocodes\Exceptions\UnauthenticatedExceprion|\Gabievi\Promocodes\Exceptions\AlreadyUsedExceprion |
||
180 | */ |
||
181 | public function redeem($code) |
||
185 | |||
186 | /** |
||
187 | * Expire code as it won't usable anymore. |
||
188 | * |
||
189 | * @param string $code |
||
190 | * @return bool |
||
191 | * @throws \Gabievi\Promocodes\Exceptions\InvalidPromocodeExceprion |
||
192 | */ |
||
193 | public function disable($code) |
||
205 | |||
206 | /** |
||
207 | * Clear all expired and used promotion codes |
||
208 | * that can not be used anymore. |
||
209 | * |
||
210 | * @return void |
||
211 | */ |
||
212 | public function clearRedundant() |
||
221 | |||
222 | /** |
||
223 | * Here will be generated single code using your parameters from config. |
||
224 | * |
||
225 | * @return string |
||
226 | */ |
||
227 | private function generate() |
||
259 | |||
260 | /** |
||
261 | * Generate prefix with separator for promocode. |
||
262 | * |
||
263 | * @return string |
||
264 | */ |
||
265 | private function getPrefix() |
||
271 | |||
272 | /** |
||
273 | * Generate suffix with separator for promocode. |
||
274 | * |
||
275 | * @return string |
||
276 | */ |
||
277 | private function getSuffix() |
||
283 | |||
284 | /** |
||
285 | * Your code will be validated to be unique for one request. |
||
286 | * |
||
287 | * @param $collection |
||
288 | * @param $new |
||
289 | * |
||
290 | * @return bool |
||
291 | */ |
||
292 | private function validate($collection, $new) |
||
296 | |||
297 | /** |
||
298 | * Check if user is trying to apply code again. |
||
299 | * |
||
300 | * @param $promocode |
||
301 | * |
||
302 | * @return bool |
||
303 | */ |
||
304 | private function isSecondUsageAttempt($promocode) { |
||
307 | } |
||
308 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: