/// <summary>
        /// Analyzes the complexity of a document.
        /// </summary>  
        internal ComplexityResult Analyze(Document doc, double avgImpact = 2.0d)
        {
            if (avgImpact <= 1) throw new ArgumentOutOfRangeException(nameof(avgImpact));

            doc.Children.Where(node => node is FragmentDefinition).Apply(node =>
            {
                var fragResult = new FragmentComplexity();
                FragmentIterator(node, fragResult, avgImpact, avgImpact, 1d);
                _fragmentMap[(node as FragmentDefinition)?.Name] = fragResult;
            });

            TreeIterator(doc, _result, avgImpact, avgImpact, 1d);

            // Cleanup in case Analyze is called again
            _loopCounter = 0;
            var retVal = _result;
            _result = new ComplexityResult();

            return retVal;
        }
 private static void RecordFieldComplexity(INode node, ComplexityResult result, double impact)
 {
     result.Complexity += impact;
     if (result.ComplexityMap.ContainsKey(node))
         result.ComplexityMap[node] += impact;
     else
         result.ComplexityMap.Add(node, impact);
 }