core/broadcast_situation_exchange_builder.go

Summary

Maintainability
F
3 days
Test Coverage

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

func (builder *BroadcastSituationExchangeBuilder) BuildSituationExchange(situation model.Situation) (situationExchangeDelivery *siri.SIRISituationExchangeDelivery) {
    if !builder.canBroadcast(situation) {
        return nil
    }

Severity: Minor
Found in core/broadcast_situation_exchange_builder.go - About 3 hrs to fix

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 BroadcastSituationExchangeBuilder.BuildSituationExchange has 94 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func (builder *BroadcastSituationExchangeBuilder) BuildSituationExchange(situation model.Situation) (situationExchangeDelivery *siri.SIRISituationExchangeDelivery) {
    if !builder.canBroadcast(situation) {
        return nil
    }

Severity: Major
Found in core/broadcast_situation_exchange_builder.go - About 2 hrs to fix

    Method BroadcastSituationExchangeBuilder.buildAffectedLine has 59 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func (builder *BroadcastSituationExchangeBuilder) buildAffectedLine(affect model.Affect, ptSituationElement *siri.SIRIPtSituationElement, delivery *siri.SIRISituationExchangeDelivery) (*siri.AffectedLine, bool) {
        affect, _ = affect.(*model.AffectedLine)
        line, ok := builder.partner.Model().Lines().Find(model.LineId(affect.GetId()))
        if !ok {
            logger.Log.Debugf("Unknown Line %s", affect.GetId())
    Severity: Minor
    Found in core/broadcast_situation_exchange_builder.go - About 1 hr to fix

      Method BroadcastSituationExchangeBuilder.canBroadcast has 5 return statements (exceeds 4 allowed).
      Open

      func (builder *BroadcastSituationExchangeBuilder) canBroadcast(situation model.Situation) bool {
          if situation.Origin == string(builder.partner.Slug()) {
              return false
          }
      
      
      Severity: Major
      Found in core/broadcast_situation_exchange_builder.go - About 35 mins to fix

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

        func (builder *BroadcastSituationExchangeBuilder) buildAffectedLine(affect model.Affect, ptSituationElement *siri.SIRIPtSituationElement, delivery *siri.SIRISituationExchangeDelivery) (*siri.AffectedLine, bool) {
            affect, _ = affect.(*model.AffectedLine)
            line, ok := builder.partner.Model().Lines().Find(model.LineId(affect.GetId()))
            if !ok {
                logger.Log.Debugf("Unknown Line %s", affect.GetId())
        Severity: Major
        Found in core/broadcast_situation_exchange_builder.go and 1 other location - About 1 day to fix
        core/siri_situation_exchange_request_broadcaster.go on lines 199..265

        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 729.

        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

        func (builder *BroadcastSituationExchangeBuilder) buildAffectedStopArea(affect model.Affect, ptSituationElement *siri.SIRIPtSituationElement, delivery *siri.SIRISituationExchangeDelivery) (*siri.AffectedStopPoint, bool) {
            affect, _ = affect.(*model.AffectedStopArea)
        
            affectedStopAreaRef, ok := builder.resolveStopAreaRef(model.StopAreaId(affect.GetId()))
            if !ok {
        Severity: Major
        Found in core/broadcast_situation_exchange_builder.go and 1 other location - About 4 hrs to fix
        core/siri_situation_exchange_request_broadcaster.go on lines 169..197

        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 341.

        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

            for _, consequence := range situation.Consequences {
                c := &siri.Consequence{
                    Periods:  consequence.Periods,
                    Severity: consequence.Severity,
                }
        Severity: Major
        Found in core/broadcast_situation_exchange_builder.go and 1 other location - About 3 hrs to fix
        core/siri_situation_exchange_request_broadcaster.go on lines 136..164

        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 248.

        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

        func (builder *BroadcastSituationExchangeBuilder) canBroadcast(situation model.Situation) bool {
            if situation.Origin == string(builder.partner.Slug()) {
                return false
            }
        
        
        Severity: Major
        Found in core/broadcast_situation_exchange_builder.go and 1 other location - About 1 hr to fix
        core/siri_situation_exchange_request_broadcaster.go on lines 279..300

        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 187.

        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

            for _, affect := range situation.Affects {
                switch affect.GetType() {
                case model.SituationTypeStopArea:
                    affectedStopArea, ok := builder.buildAffectedStopArea(affect, ptSituationElement, delivery)
                    if ok {
        Severity: Major
        Found in core/broadcast_situation_exchange_builder.go and 1 other location - About 1 hr to fix
        core/siri_situation_exchange_request_broadcaster.go on lines 112..134

        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 157.

        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

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

            ptSituationElement := &siri.SIRIPtSituationElement{
                SituationNumber:    situationNumber,
                CreationTime:       situation.RecordedAt,
                Version:            situation.Version,
                ValidityPeriods:    situation.ValidityPeriods,
        Severity: Major
        Found in core/broadcast_situation_exchange_builder.go and 1 other location - About 1 hr to fix
        core/siri_situation_exchange_request_broadcaster.go on lines 88..102

        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 136.

        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 3 locations. Consider refactoring.
        Open

        func (builder *BroadcastSituationExchangeBuilder) resolveStopAreaRef(stopAreaId model.StopAreaId) (string, bool) {
            stopArea, ok := builder.partner.Model().StopAreas().Find(stopAreaId)
            if !ok {
                return "", false
            }
        Severity: Major
        Found in core/broadcast_situation_exchange_builder.go and 2 other locations - About 50 mins to fix
        core/broadcast_general_message_builder.go on lines 220..230
        core/siri_situation_exchange_request_broadcaster.go on lines 267..277

        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 121.

        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