CORE-POS/IS4C

View on GitHub
pos/is4c-nf/scale-drivers/drivers/NewMagellan/Newtonsoft.Json/Converters/XmlNodeConverter.cs

Summary

Maintainability
F
1 wk
Test Coverage

File XmlNodeConverter.cs has 1435 lines of code (exceeds 250 allowed). Consider refactoring.
Open

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Xml;
#if !(NET20 || PORTABLE40)

    Method SerializeNode has a Cognitive Complexity of 65 (exceeds 20 allowed). Consider refactoring.
    Open

            private void SerializeNode(JsonWriter writer, IXmlNode node, XmlNamespaceManager manager, bool writePropertyName)
            {
                switch (node.NodeType)
                {
                    case XmlNodeType.Document:

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Method SerializeNode has 126 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

            private void SerializeNode(JsonWriter writer, IXmlNode node, XmlNamespaceManager manager, bool writePropertyName)
            {
                switch (node.NodeType)
                {
                    case XmlNodeType.Document:

      Method ReadAttributeElements has a Cognitive Complexity of 38 (exceeds 20 allowed). Consider refactoring.
      Open

              private Dictionary<string, string> ReadAttributeElements(JsonReader reader, XmlNamespaceManager manager)
              {
                  Dictionary<string, string> attributeNameValues = new Dictionary<string, string>();
                  bool finishedAttributes = false;
                  bool finishedElement = false;

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Method ReadAttributeElements has 76 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

              private Dictionary<string, string> ReadAttributeElements(JsonReader reader, XmlNamespaceManager manager)
              {
                  Dictionary<string, string> attributeNameValues = new Dictionary<string, string>();
                  bool finishedAttributes = false;
                  bool finishedElement = false;

        Method DeserializeNode has a Cognitive Complexity of 36 (exceeds 20 allowed). Consider refactoring.
        Open

                private void DeserializeNode(JsonReader reader, IXmlDocument document, XmlNamespaceManager manager, IXmlNode currentNode)
                {
                    do
                    {
                        switch (reader.TokenType)

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Class XmlNodeConverter has 22 methods (exceeds 20 allowed). Consider refactoring.
        Open

            public class XmlNodeConverter : JsonConverter
            {
                private const string TextName = "#text";
                private const string CommentName = "#comment";
                private const string CDataName = "#cdata-section";

          Method ReadJson has 50 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                  public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
                  {
                      if (reader.TokenType == JsonToken.Null)
                          return null;
          
          

            Method ReadElement has 50 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                    private void ReadElement(JsonReader reader, IXmlDocument document, IXmlNode currentNode, string propertyName, XmlNamespaceManager manager)
                    {
                        if (string.IsNullOrEmpty(propertyName))
                            throw new JsonSerializationException("XmlNodeConverter cannot convert JSON with an empty property name to XML.");
            
            

              Method DeserializeNode has 47 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                      private void DeserializeNode(JsonReader reader, IXmlDocument document, XmlNamespaceManager manager, IXmlNode currentNode)
                      {
                          do
                          {
                              switch (reader.TokenType)

                Method SerializeGroupedNodes has 44 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                        private void SerializeGroupedNodes(JsonWriter writer, IXmlNode node, XmlNamespaceManager manager, bool writePropertyName)
                        {
                            // group nodes together by name
                            Dictionary<string, List<IXmlNode>> nodesGroupedByName = new Dictionary<string, List<IXmlNode>>();
                
                

                  Method ConvertTokenToXmlValue has 43 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                          private string ConvertTokenToXmlValue(JsonReader reader)
                          {
                              if (reader.TokenType == JsonToken.String)
                              {
                                  return reader.Value.ToString();

                    Consider simplifying this complex logical expression.
                    Open

                                if (reader.TokenType != JsonToken.String
                                    && reader.TokenType != JsonToken.Null
                                    && reader.TokenType != JsonToken.Boolean
                                    && reader.TokenType != JsonToken.Integer
                                    && reader.TokenType != JsonToken.Float

                      Method DeserializeValue has 36 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                              private void DeserializeValue(JsonReader reader, IXmlDocument document, XmlNamespaceManager manager, string propertyName, IXmlNode currentNode)
                              {
                                  switch (propertyName)
                                  {
                                      case TextName:

                        Method CreateInstruction has 35 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                                private void CreateInstruction(JsonReader reader, IXmlDocument document, IXmlNode currentNode, string propertyName)
                                {
                                    if (propertyName == DeclarationName)
                                    {
                                        string version = null;

                          Method CreateDocumentType has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                                  private void CreateDocumentType(JsonReader reader, IXmlDocument document, IXmlNode currentNode)
                                  {
                                      string name = null;
                                      string publicId = null;
                                      string systemId = null;

                            Method GetPropertyName has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                                    private string GetPropertyName(IXmlNode node, XmlNamespaceManager manager)
                                    {
                                        switch (node.NodeType)
                                        {
                                            case XmlNodeType.Attribute:

                              Method PushParentNamespaces has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                              Open

                                      private void PushParentNamespaces(IXmlNode node, XmlNamespaceManager manager)
                                      {
                                          List<IXmlNode> parentElements = null;
                              
                                          IXmlNode parent = node;

                                Avoid deeply nested control flow statements.
                                Open

                                                                    case '@':
                                                                        attributeName = attributeName.Substring(1);
                                                                        reader.Read();
                                                                        attributeValue = ConvertTokenToXmlValue(reader);
                                                                        attributeNameValues.Add(attributeName, attributeValue);

                                  Avoid deeply nested control flow statements.
                                  Open

                                                                      default:
                                                                          finishedAttributes = true;
                                                                          break;

                                    Avoid deeply nested control flow statements.
                                    Open

                                                                        case '$':
                                                                            attributeName = attributeName.Substring(1);
                                                                            reader.Read();
                                                                            attributeValue = reader.Value.ToString();
                                    
                                    

                                      Method DeserializeValue has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                      Open

                                              private void DeserializeValue(JsonReader reader, IXmlDocument document, XmlNamespaceManager manager, string propertyName, IXmlNode currentNode)

                                        Method ReadElement has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                        Open

                                                private void ReadElement(JsonReader reader, IXmlDocument document, IXmlNode currentNode, string propertyName, XmlNamespaceManager manager)

                                          Method ReadArrayElements has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                          Open

                                                  private void ReadArrayElements(JsonReader reader, IXmlDocument document, string propertyName, IXmlNode currentNode, XmlNamespaceManager manager)

                                            Avoid too many return statements within this method.
                                            Open

                                                            return new XObjectWrapper(node);

                                              Avoid too many return statements within this method.
                                              Open

                                                              return XmlConvert.ToString(Convert.ToDouble(reader.Value, CultureInfo.InvariantCulture));

                                                Avoid too many return statements within this method.
                                                Open

                                                                return new XDocumentTypeWrapper((XDocumentType)node);

                                                  Avoid too many return statements within this method.
                                                  Open

                                                                  return new XAttributeWrapper((XAttribute)node);

                                                    Avoid too many return statements within this method.
                                                    Open

                                                                    return XmlConvert.ToString(Convert.ToBoolean(reader.Value, CultureInfo.InvariantCulture));

                                                      Avoid too many return statements within this method.
                                                      Open

                                                                      return new XTextWrapper((XText)node);

                                                        Avoid too many return statements within this method.
                                                        Open

                                                                        return XmlConvert.ToString(d, DateTimeUtils.ToSerializationMode(d.Kind));

                                                          Avoid too many return statements within this method.
                                                          Open

                                                                          return new XCommentWrapper((XComment)node);

                                                            Avoid too many return statements within this method.
                                                            Open

                                                                            return null;

                                                              Avoid too many return statements within this method.
                                                              Open

                                                                                  return XmlConvert.ToString((DateTimeOffset)reader.Value);

                                                                Similar blocks of code found in 2 locations. Consider refactoring.
                                                                Open

                                                                    internal class XmlDocumentTypeWrapper : XmlNodeWrapper, IXmlDocumentType
                                                                    {
                                                                        private readonly XmlDocumentType _documentType;
                                                                
                                                                        public XmlDocumentTypeWrapper(XmlDocumentType documentType)
                                                                pos/is4c-nf/scale-drivers/drivers/NewMagellan/Newtonsoft.Json/Converters/XmlNodeConverter.cs on lines 417..451

                                                                Duplicated Code

                                                                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                                                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                                                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                                                Tuning

                                                                This issue has a mass of 110.

                                                                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                                                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                                                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                                                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                                                Refactorings

                                                                Further Reading

                                                                Similar blocks of code found in 2 locations. Consider refactoring.
                                                                Open

                                                                    internal class XDocumentTypeWrapper : XObjectWrapper, IXmlDocumentType
                                                                    {
                                                                        private readonly XDocumentType _documentType;
                                                                
                                                                        public XDocumentTypeWrapper(XDocumentType documentType)
                                                                pos/is4c-nf/scale-drivers/drivers/NewMagellan/Newtonsoft.Json/Converters/XmlNodeConverter.cs on lines 189..223

                                                                Duplicated Code

                                                                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                                                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                                                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                                                Tuning

                                                                This issue has a mass of 110.

                                                                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                                                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                                                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                                                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                                                Refactorings

                                                                Further Reading

                                                                Similar blocks of code found in 2 locations. Consider refactoring.
                                                                Open

                                                                    internal class XCommentWrapper : XObjectWrapper
                                                                    {
                                                                        private XComment Text
                                                                        {
                                                                            get { return (XComment)WrappedNode; }
                                                                pos/is4c-nf/scale-drivers/drivers/NewMagellan/Newtonsoft.Json/Converters/XmlNodeConverter.cs on lines 566..594

                                                                Duplicated Code

                                                                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                                                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                                                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                                                Tuning

                                                                This issue has a mass of 102.

                                                                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                                                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                                                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                                                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                                                Refactorings

                                                                Further Reading

                                                                Similar blocks of code found in 2 locations. Consider refactoring.
                                                                Open

                                                                    internal class XTextWrapper : XObjectWrapper
                                                                    {
                                                                        private XText Text
                                                                        {
                                                                            get { return (XText)WrappedNode; }
                                                                pos/is4c-nf/scale-drivers/drivers/NewMagellan/Newtonsoft.Json/Converters/XmlNodeConverter.cs on lines 596..624

                                                                Duplicated Code

                                                                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                                                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                                                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                                                Tuning

                                                                This issue has a mass of 102.

                                                                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                                                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                                                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                                                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                                                Refactorings

                                                                Further Reading

                                                                Similar blocks of code found in 2 locations. Consider refactoring.
                                                                Open

                                                                                            if (count == 1 && WriteArrayAttribute)
                                                                                            {
                                                                                                IXmlElement arrayElement = currentNode.ChildNodes.OfType<IXmlElement>().Single(n => n.LocalName == propertyName);
                                                                                                AddJsonArrayAttribute(arrayElement, document);
                                                                                            }
                                                                pos/is4c-nf/scale-drivers/drivers/NewMagellan/Newtonsoft.Json/Converters/XmlNodeConverter.cs on lines 1479..1483

                                                                Duplicated Code

                                                                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                                                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                                                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                                                Tuning

                                                                This issue has a mass of 66.

                                                                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                                                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                                                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                                                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                                                Refactorings

                                                                Further Reading

                                                                Similar blocks of code found in 2 locations. Consider refactoring.
                                                                Open

                                                                            if (count == 1 && WriteArrayAttribute)
                                                                            {
                                                                                IXmlElement arrayElement = nestedArrayElement.ChildNodes.OfType<IXmlElement>().Single(n => n.LocalName == propertyName);
                                                                                AddJsonArrayAttribute(arrayElement, document);
                                                                            }
                                                                pos/is4c-nf/scale-drivers/drivers/NewMagellan/Newtonsoft.Json/Converters/XmlNodeConverter.cs on lines 1699..1703

                                                                Duplicated Code

                                                                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                                                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                                                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                                                Tuning

                                                                This issue has a mass of 66.

                                                                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                                                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                                                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                                                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                                                Refactorings

                                                                Further Reading

                                                                There are no issues that match your filters.

                                                                Category
                                                                Status