From 46c044d448e44a52a04ef4b2d92a1c18896cc6f0 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Mon, 24 Apr 2017 15:39:46 -0400 Subject: [PATCH] Replace cyclomaticComplexity with its algebra. --- src/Language/Ruby/Syntax.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Language/Ruby/Syntax.hs b/src/Language/Ruby/Syntax.hs index 857b61ac1..d7bdb6199 100644 --- a/src/Language/Ruby/Syntax.hs +++ b/src/Language/Ruby/Syntax.hs @@ -121,8 +121,8 @@ identifiable = para $ \ c@(_ :< union) -> case union of newtype CyclomaticComplexity = CyclomaticComplexity Int deriving (Enum, Eq, Num, Ord, Show) -cyclomaticComplexity :: (InUnion fs Statement.Return, InUnion fs Statement.Yield, Foldable (Union fs), Functor (Union fs)) => Term (Union fs) a -> CyclomaticComplexity -cyclomaticComplexity = cata $ \ (_ :< union) -> case union of +cyclomaticComplexityAlg :: (InUnion fs Statement.Return, InUnion fs Statement.Yield, Foldable (Union fs), Functor (Union fs)) => TermF (Union fs) a CyclomaticComplexity -> CyclomaticComplexity +cyclomaticComplexityAlg (_ :< union) = case union of _ | Just Statement.Return{} <- prj union -> succ (sum union) _ | Just Statement.Yield{} <- prj union -> succ (sum union) _ -> sum union