44
55use CSlant \TelegramGitNotifier \Constants \EventConstant ;
66use CSlant \TelegramGitNotifier \Constants \SettingConstant ;
7+ use CSlant \TelegramGitNotifier \Enums \Platform ;
78
89trait EventSettingTrait
910{
@@ -12,7 +13,7 @@ trait EventSettingTrait
1213 */
1314 public function eventMarkup (
1415 ?string $ parentEvent = null ,
15- string $ platform = EventConstant:: DEFAULT_PLATFORM ,
16+ string $ platform = Platform:: DEFAULT ,
1617 ?string $ platformFile = null
1718 ): array {
1819 $ replyMarkup = $ replyMarkupItem = [];
@@ -56,9 +57,7 @@ public function getCallbackData(
5657 array |bool $ value = false ,
5758 ?string $ parentEvent = null
5859 ): string {
59- $ platformSeparator = $ platform === EventConstant::DEFAULT_PLATFORM
60- ? EventConstant::GITHUB_EVENT_SEPARATOR
61- : EventConstant::GITLAB_EVENT_SEPARATOR ;
60+ $ platformSeparator = Platform::from ($ platform )->eventSeparator ();
6261 $ prefix = EventConstant::EVENT_PREFIX . $ platformSeparator ;
6362
6463 if (is_array ($ value )) {
@@ -136,14 +135,14 @@ public function getPlatformFromCallback(
136135 }
137136
138137 if ($ callback ) {
139- return match ( true ) {
140- str_contains ($ callback , EventConstant:: GITHUB_EVENT_SEPARATOR ) => ' github ' ,
141- str_contains ( $ callback , EventConstant:: GITLAB_EVENT_SEPARATOR ) => ' gitlab ' ,
142- default => EventConstant:: DEFAULT_PLATFORM ,
143- };
138+ foreach (Platform:: cases () as $ p ) {
139+ if ( str_contains ($ callback , $ p -> eventSeparator ())) {
140+ return $ p -> value ;
141+ }
142+ }
144143 }
145144
146- return EventConstant:: DEFAULT_PLATFORM ;
145+ return Platform:: DEFAULT ;
147146 }
148147
149148 public function sendSettingEventMessage (
@@ -175,11 +174,16 @@ public function getEventFromCallback(?string $callback): string
175174 return '' ;
176175 }
177176
178- return str_replace ([
179- EventConstant::EVENT_PREFIX ,
180- EventConstant::GITHUB_EVENT_SEPARATOR ,
181- EventConstant::GITLAB_EVENT_SEPARATOR ,
182- ], '' , $ callback );
177+ $ separators = array_map (
178+ fn (Platform $ p ) => $ p ->eventSeparator (),
179+ Platform::cases (),
180+ );
181+
182+ return str_replace (
183+ [EventConstant::EVENT_PREFIX , ...$ separators ],
184+ '' ,
185+ $ callback ,
186+ );
183187 }
184188
185189 public function handleEventWithActions (
@@ -235,7 +239,7 @@ public function eventUpdateHandle(
235239 $ this ->event ->updateEvent ($ event , $ action );
236240 $ this ->eventHandle (
237241 $ action
238- ? EventConstant:: PLATFORM_EVENT_SEPARATOR [ $ platform]
242+ ? Platform:: from ( $ platform)-> eventSeparator ()
239243 . EventConstant::EVENT_HAS_ACTION_SEPARATOR . $ event
240244 : null ,
241245 $ platform
0 commit comments