@@ -237,13 +237,9 @@ public function printAction(Config\Action $action): void
237237 */
238238 public function printConditions (array $ conditions , string $ prefix = '' ): void
239239 {
240- if (empty ($ conditions )) {
240+ if (! $ this -> isConditionToBeDisplayed ($ conditions )) {
241241 return ;
242242 }
243- if (!$ this ->settings ->show (Settings::OPT_CONDITIONS )) {
244- return ;
245- }
246-
247243 if (empty ($ prefix )) {
248244 $ this ->io ->write ($ prefix . ' <comment>Conditions:</comment> ' );
249245 }
@@ -264,7 +260,7 @@ public function printCondition(Config\Condition $condition, string $prefix = '')
264260 $ this ->io ->write ($ prefix . ' - <fg=cyan> ' . $ condition ->getExec () . '</> ' );
265261
266262 // handle logic conditions
267- if (in_array ( strtoupper ( $ condition ->getExec ()), [ ' OR ' , ' AND ' ] )) {
263+ if ($ condition ->isLogicCondition ( )) {
268264 $ conditions = [];
269265 foreach ($ condition ->getArgs () as $ conf ) {
270266 $ conditions [] = new Config \Condition ($ conf ['exec ' ], $ conf ['args ' ] ?? []);
@@ -333,16 +329,11 @@ public function printActionConfig(Config\Action $action): void
333329 return ;
334330 }
335331
336- $ config = [];
337- if ($ action ->getLabel () != $ action ->getAction ()) {
338- $ config ['label ' ] = $ action ->getLabel ();
339- }
340- if ($ action ->isFailureAllowed ()) {
341- $ config ['failureAllowed ' ] = true ;
342- }
332+ $ config = $ this ->extractActionConfig ($ action );
343333 if (empty ($ config )) {
344334 return ;
345335 }
336+
346337 $ this ->io ->write (' <comment>Config:</comment> ' );
347338 foreach ($ config as $ key => $ value ) {
348339 $ this ->io ->write (' - ' . $ key . ': <fg=gray> ' . Util::escapeLineBreaks ((string )$ value ) . '</> ' );
@@ -359,4 +350,39 @@ private function extendedAction(Config\Action $action): bool
359350 {
360351 return $ action ->hasLabel () && $ this ->settings ->show (Settings::OPT_ACTIONS );
361352 }
353+
354+ /**
355+ * Check if conditions should be displayed
356+ *
357+ * @param array<\CaptainHook\App\Config\Condition> $conditions
358+ * @return bool
359+ */
360+ private function isConditionToBeDisplayed (array $ conditions ): bool
361+ {
362+ if (empty ($ conditions )) {
363+ return false ;
364+ }
365+ if (!$ this ->settings ->show (Settings::OPT_CONDITIONS )) {
366+ return false ;
367+ }
368+ return true ;
369+ }
370+
371+ /**
372+ * Extract the action config settings
373+ *
374+ * @param \CaptainHook\App\Config\Action $action
375+ * @return array<string, string|bool>
376+ */
377+ private function extractActionConfig (Config \Action $ action ): array
378+ {
379+ $ config = [];
380+ if ($ action ->hasLabel ()) {
381+ $ config ['label ' ] = $ action ->getLabel ();
382+ }
383+ if ($ action ->isFailureAllowed ()) {
384+ $ config ['failureAllowed ' ] = true ;
385+ }
386+ return $ config ;
387+ }
362388}
0 commit comments