@@ -91,9 +91,7 @@ public function __construct()
9191 $ this ->billing = SimpleBilling::fromSale ($ this ->sale );
9292 }
9393
94- /**
95- * @Given /(\S+) (\S+) price is ([0-9.]+) (\w+) per (\w+)(?: includes ([\d.]+))?/
96- */
94+ #[\Behat \Step \Given('/(\S+) (\S+) price is ([0-9.]+) (\w+) per (\w+)(?: includes ([\d.]+))?/ ' )]
9795 public function priceIs ($ target , $ type , $ sum , $ currency , $ unit , $ quantity = 0 )
9896 {
9997 $ type = Type::anyId ($ type );
@@ -104,9 +102,7 @@ public function priceIs($target, $type, $sum, $currency, $unit, $quantity = 0)
104102 }
105103
106104 protected array $ progressivePrice = [];
107- /**
108- * @Given /(\S+) progressive price for (\S+) is +(\S+) (\S+) per (\S+) (\S+) (\S+) (\S+)$/
109- */
105+ #[\Behat \Step \Given('/(\S+) progressive price for (\S+) is +(\S+) (\S+) per (\S+) (\S+) (\S+) (\S+)$/ ' )]
110106 public function progressivePrice ($ target , $ type , $ price , $ currency , $ unit , $ sign , $ quantity , $ perUnit ): void
111107 {
112108 if (empty ($ this ->progressivePrice [$ type ])) {
@@ -128,9 +124,7 @@ public function progressivePrice($target, $type, $price, $currency, $unit, $sign
128124 }
129125 }
130126
131- /**
132- * @Given /^build progressive price/
133- */
127+ #[\Behat \Step \Given('/^build progressive price/ ' )]
134128 public function buildProgressivePrices ()
135129 {
136130 $ i = 0 ;
@@ -148,9 +142,7 @@ public function buildProgressivePrices()
148142 }
149143 }
150144
151- /**
152- * @Given /sale close time is ([0-9.-]+)?/
153- */
145+ #[\Behat \Step \Given('/sale close time is ([0-9.-]+)?/ ' )]
154146 public function setActionCloseTime ($ closeTime ): void
155147 {
156148 if ($ closeTime === null ) {
@@ -160,30 +152,23 @@ public function setActionCloseTime($closeTime): void
160152 $ this ->sale ->close (new DateTimeImmutable ($ closeTime ));
161153 }
162154
163- /**
164- * @Given /sale time is (.+)$/
165- */
155+ #[\Behat \Step \Given('/sale time is (.+)$/ ' )]
166156 public function setSaleTime ($ time ): void
167157 {
168158 $ ref = new ReflectionClass ($ this ->sale );
169159 $ prop = $ ref ->getProperty ('time ' );
170- $ prop ->setAccessible (true );
171160 $ prop ->setValue ($ this ->sale , new DateTimeImmutable ($ time ));
172- $ prop ->setAccessible (false );
173161 }
174162
175163 private function setPrice ($ price )
176164 {
177165 $ this ->price = $ price ;
178166 $ ref = new ReflectionClass ($ this ->plan );
179167 $ prop = $ ref ->getProperty ('prices ' );
180- $ prop ->setAccessible (true );
181168 $ prop ->setValue ($ this ->plan , [$ price ]);
182169 }
183170
184- /**
185- * @Given /action is (\S+) ([\w_,]+)(?: ([0-9.]+) (\S+))?(?: in (.+))?/
186- */
171+ #[\Behat \Step \Given('/action is (\S+) ([\w_,]+)(?: ([0-9.]+) (\S+))?(?: in (.+))?/ ' )]
187172 public function actionIs (string $ target , string $ type , float $ amount , string $ unit , ?string $ date = null ): void
188173 {
189174 $ type = Type::anyId ($ type );
@@ -196,7 +181,7 @@ public function actionIs(string $target, string $type, float $amount, string $un
196181 );
197182 if ($ type ->getName () !== 'overuse ' ) {
198183 // Overuses should be prepared in the test case
199- $ amount = $ amount * $ fractionOfMonth ;
184+ $ amount *= $ fractionOfMonth ;
200185 }
201186 }
202187 $ quantity = Quantity::create ($ unit , $ amount );
@@ -219,22 +204,18 @@ private function getFractionOfMonth(DateTimeImmutable $month, DateTimeImmutable
219204 {
220205 try {
221206 return UsageInterval::withinMonth ($ month , $ startTime , $ endTime )->ratioOfMonth ();
222- } catch (\InvalidArgumentException $ e ) {
207+ } catch (\InvalidArgumentException ) {
223208 return 1 ;
224209 }
225210 }
226211
227- /**
228- * @Given /formula is (.+)/
229- */
212+ #[\Behat \Step \Given('/formula is (.+)/ ' )]
230213 public function formulaIs (string $ formula ): void
231214 {
232215 $ this ->formula = $ formula ;
233216 }
234217
235- /**
236- * @Given /formula continues (.+)/
237- */
218+ #[\Behat \Step \Given('/formula continues (.+)/ ' )]
238219 public function formulaContinues (string $ formula ): void
239220 {
240221 $ this ->formula .= "\n" . $ formula ;
@@ -250,64 +231,53 @@ protected function getFormulaEngine()
250231 }
251232
252233 /**
253- * @When /action date is (.+)/
254234 * @throws Exception
255235 */
236+ #[\Behat \Step \When('/action date is (.+)/ ' )]
256237 public function actionDateIs (string $ date ): void
257238 {
258239 $ this ->action ->setTime (new DateTimeImmutable ($ date ));
259240 }
260241
261- /**
262- * @Given /^client rejected service at ?(.+?)$/
263- */
242+ #[\Behat \Step \Given('/^client rejected service at ?(.+?)$/ ' )]
264243 public function actionCloseDateIs (?string $ close_date ): void
265244 {
266- $ close_date = trim ($ close_date );
245+ $ close_date = trim (( string ) $ close_date );
267246 if (empty ($ close_date )) {
268247 return ;
269248 }
270249
271250 $ this ->sale ->close (new DateTimeImmutable ($ close_date ));
272251 }
273252
274- /**
275- * @Then /^error is$/m
276- */
253+ #[\Behat \Step \Then('/^error is$/m ' )]
277254 public function multilineErrorIs (\Behat \Gherkin \Node \PyStringNode $ value )
278255 {
279256 $ this ->expectedError = $ value ->getRaw ();
280257 }
281258
282259 /**
283- * @Then /^error is (.+)$/
284- *
285260 * @param string $error
286261 */
262+ #[\Behat \Step \Then('/^error is (.+)$/ ' )]
287263 public function errorIs ($ error ): void
288264 {
289265 $ this ->expectedError = $ error ;
290266 }
291267
292- /**
293- * @Then /^(\w+) charge is ?(?: with ?)?$/
294- */
268+ #[\Behat \Step \Then('/^(\w+) charge is ?(?: with ?)?$/ ' )]
295269 public function emptyCharge (string $ numeral ): void
296270 {
297271 $ this ->chargeIs ($ numeral );
298272 }
299273
300- /**
301- * @Then /^(\w+) charge is (\S+) +(-?[0-9.]+) ([A-Z]{3})(?: for ([\d.]+)? (\w+)?)?(?: with (.+)?)?$/
302- */
274+ #[\Behat \Step \Then('/^(\w+) charge is (\S+) +(-?[0-9.]+) ([A-Z]{3})(?: for ([\d.]+)? (\w+)?)?(?: with (.+)?)?$/ ' )]
303275 public function chargeWithSum ($ numeral , $ type = null , $ sum = null , $ currency = null , $ qty = null , $ unit = null , $ events = null ): void
304276 {
305277 $ this ->chargeIs ($ numeral , $ type , $ sum , $ currency , null , $ qty , $ unit , $ events );
306278 }
307279
308- /**
309- * @Then /^(\w+) charge is (\S+) +(-?[0-9.]+) ([A-Z]{3}) reason ([\w]+)(?: with (.+)?)?$/
310- */
280+ #[\Behat \Step \Then('/^(\w+) charge is (\S+) +(-?[0-9.]+) ([A-Z]{3}) reason ([\w]+)(?: with (.+)?)?$/ ' )]
311281 public function chargeWithReason ($ numeral , $ type = null , $ sum = null , $ currency = null , $ reason = null , $ events = null ): void
312282 {
313283 $ this ->chargeIs ($ numeral , $ type , $ sum , $ currency , $ reason , null , null , $ events );
@@ -322,12 +292,10 @@ public function chargeIs($numeral, $type = null, $sum = null, $currency = null,
322292 $ this ->assertCharge ($ this ->charges [$ no ] ?? null , $ type , $ sum , $ currency , $ reason , $ qty , $ unit , $ events );
323293 }
324294
325- /**
326- * @When /^calculating charges$/
327- */
295+ #[\Behat \Step \When('/^calculating charges$/ ' )]
328296 public function calculatePrice (): void
329297 {
330- $ this ->expectError (function () {
298+ $ this ->expectError (function (): void {
331299 if ($ this ->formula !== null ) {
332300 $ this ->price ->setModifier ($ this ->getFormulaEngine ()->build ($ this ->formula ));
333301 }
@@ -395,7 +363,7 @@ public function assertCharge($charge, $type, $sum, $currency, $reason, $qty, $un
395363 }
396364 if ($ events !== null ) {
397365 $ storedEvents = $ charge ->releaseEvents ();
398- foreach (array_map (' trim ' , explode (', ' , $ events )) as $ eventClass ) {
366+ foreach (array_map (trim (...) , explode (', ' , $ events )) as $ eventClass ) {
399367 foreach ($ storedEvents as $ storedEvent ) {
400368 $ eventReflection = new \ReflectionObject ($ storedEvent );
401369 if ($ eventReflection ->getShortName () === $ eventClass ) {
@@ -412,16 +380,12 @@ public function assertCharge($charge, $type, $sum, $currency, $reason, $qty, $un
412380
413381 private function normalizeType ($ string ): string
414382 {
415- switch ($ string ) {
416- case 'discount,discount ' :
417- return 'discount ' ;
418- case 'monthly,leasing ' :
419- return 'leasing ' ;
420- case 'monthly,installment ' :
421- return 'installment ' ;
422- default :
423- return $ string ;
424- }
383+ return match ($ string ) {
384+ 'discount,discount ' => 'discount ' ,
385+ 'monthly,leasing ' => 'leasing ' ,
386+ 'monthly,installment ' => 'installment ' ,
387+ default => $ string ,
388+ };
425389 }
426390
427391 private function ensureNo (string $ numeral ): int
@@ -435,9 +399,7 @@ private function ensureNo(string $numeral): int
435399 return --$ result ;
436400 }
437401
438- /**
439- * @Given /^progressive price calculation steps are (.*)$/
440- */
402+ #[\Behat \Step \Given('/^progressive price calculation steps are (.*)$/ ' )]
441403 public function progressivePriceCalculationStepsAre ($ explanation )
442404 {
443405 if (!$ this ->price instanceof ProgressivePrice) {
0 commit comments