Showing 525 of 525 total issues

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

func (request *XMLGeneralMessageRequest) RouteRef() []string {
    if len(request.routeRef) == 0 {
        nodes := request.findNodes("RouteRef")
        for _, routeRef := range nodes {
            request.routeRef = append(request.routeRef, strings.TrimSpace(routeRef.NativeNode().Content()))
Severity: Major
Found in siri/sxml/general_message_request.go and 17 other locations - About 45 mins to fix
siri/sxml/estimated_timetable_request.go on lines 41..49
siri/sxml/general_message_request.go on lines 49..57
siri/sxml/general_message_request.go on lines 69..77
siri/sxml/general_message_request.go on lines 79..87
siri/sxml/general_message_request.go on lines 89..97
siri/sxml/general_message_response.go on lines 202..210
siri/sxml/general_message_response.go on lines 212..220
siri/sxml/general_message_response.go on lines 222..230
siri/sxml/general_message_response.go on lines 232..240
siri/sxml/production_timetable_request.go on lines 17..25
siri/sxml/situation_exchange_reponse.go on lines 437..445
siri/sxml/situation_exchange_reponse.go on lines 502..510
siri/sxml/situation_exchange_reponse.go on lines 534..542
siri/sxml/situation_exchange_subscription_request_entry.go on lines 43..51
siri/sxml/situation_exchange_subscription_request_entry.go on lines 53..61
siri/sxml/stop_points_discovery_response.go on lines 86..94
siri/sxml/vehicle_monitoring_request.go on lines 41..49

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

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 _, partner := range manager.byId {
        dbPartner, err := manager.newDbPartner(partner)
        if err != nil {
            tx.Rollback()
            return http.StatusInternalServerError, fmt.Errorf("internal error: %v", err)
Severity: Minor
Found in core/partner.go and 1 other location - About 45 mins to fix
core/referential.go on lines 425..436

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

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 (line *Line) DiscoveryCode(codeSpace string) (Code, bool) {
    ref, ok := line.Referent()
    if ok {
        _, ok := ref.Code(codeSpace)
        if ok {
Severity: Minor
Found in model/lines.go and 1 other location - About 45 mins to fix
model/stop_area.go on lines 201..214

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

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 _, referential := range manager.byId {
        dbReferential, err := manager.newDbReferential(referential)
        if err != nil {
            tx.Rollback()
            return http.StatusInternalServerError, fmt.Errorf("internal error: %v", err)
Severity: Minor
Found in core/referential.go and 1 other location - About 45 mins to fix
core/partner.go on lines 953..964

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

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 (stopArea *StopArea) SPDCode(codeSpace string) (Code, bool) {
    ref, ok := stopArea.Referent()
    if ok {
        _, ok := ref.Code(codeSpace)
        if ok {
Severity: Minor
Found in model/stop_area.go and 1 other location - About 45 mins to fix
model/lines.go on lines 148..161

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

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 (connector *SIRILiteVehicleMonitoringRequestBroadcaster) handleRef(refType, origin string, references model.References) string {
    reference, ok := references.Get(refType)
    if !ok || reference.Code == nil || (refType == "DestinationRef" && connector.noDestinationRefRewritingFrom(origin)) {
        return ""
    }
Severity: Major
Found in core/siri_lite_vehicle_monitoring_request_broadcaster.go and 2 other locations - About 40 mins to fix
core/siri_vehicle_monitoring_request_broadcaster.go on lines 274..280
core/vehicle_monitoring_broadcaster.go on lines 219..225

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

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 (connector *SIRIVehicleMonitoringRequestBroadcaster) handleRef(refType, origin string, references model.References) string {
    reference, ok := references.Get(refType)
    if !ok || reference.Code == nil || (refType == "DestinationRef" && connector.noDestinationRefRewritingFrom(origin)) {
        return ""
    }
Severity: Major
Found in core/siri_vehicle_monitoring_request_broadcaster.go and 2 other locations - About 40 mins to fix
core/siri_lite_vehicle_monitoring_request_broadcaster.go on lines 151..157
core/vehicle_monitoring_broadcaster.go on lines 219..225

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

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 (connector *SIRIVehicleMonitoringSubscriptionBroadcaster) handleRef(refType, origin string, references model.References) string {
    reference, ok := references.Get(refType)
    if !ok || reference.Code == nil || (refType == "DestinationRef" && connector.noDestinationRefRewritingFrom(origin)) {
        return ""
    }
Severity: Major
Found in core/vehicle_monitoring_broadcaster.go and 2 other locations - About 40 mins to fix
core/siri_lite_vehicle_monitoring_request_broadcaster.go on lines 151..157
core/siri_vehicle_monitoring_request_broadcaster.go on lines 274..280

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

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

Method MemoryStopAreas.Load has 6 return statements (exceeds 4 allowed).
Open

func (manager *MemoryStopAreas) Load(referentialSlug string) error {
    var selectStopAreas []SelectStopArea
    modelName := manager.model.Date()

    sqlQuery := fmt.Sprintf("select * from stop_areas where referential_slug = '%s' and model_name = '%s'", referentialSlug, modelName.String())
Severity: Major
Found in model/stop_area.go - About 40 mins to fix

    Method BroadcastStopMonitoringBuilder.BuildMonitoredStopVisit has 6 return statements (exceeds 4 allowed).
    Open

    func (builder *BroadcastStopMonitoringBuilder) BuildMonitoredStopVisit(stopVisit *model.StopVisit) *siri.SIRIMonitoredStopVisit {
        stopPointRef, stopPointRefCode, ok := builder.stopPointRef(stopVisit.StopAreaId)
        if !ok {
            logger.Log.Printf("Ignore StopVisit %v without StopArea or with StopArea without correct Code", stopVisit.Id())
            return nil
    Severity: Major
    Found in core/broadcast_stop_monitoring_builder.go - About 40 mins to fix

      Method Controller.serve has 6 return statements (exceeds 4 allowed).
      Open

      func (controller *Controller) serve(response http.ResponseWriter, request *http.Request, requestData *RequestData) {
          // Check request body
          if requestData.Method == "PUT" || (requestData.Method == "POST" && requestData.Id != "save" && requestData.Action != "reload") {
              requestData.Body = getRequestBody(response, request)
              if requestData.Body == nil {
      Severity: Major
      Found in api/controller.go - About 40 mins to fix

        Method BroadcastGeneralMessageBuilder.BuildGeneralMessage has 6 return statements (exceeds 4 allowed).
        Open

        func (builder *BroadcastGeneralMessageBuilder) BuildGeneralMessage(situation model.Situation) *siri.SIRIGeneralMessage {
            if !builder.canBroadcast(situation) {
                return nil
            }
        
        
        Severity: Major
        Found in core/broadcast_general_message_builder.go - About 40 mins to fix

          Method VehicleMonitoringUpdateEventBuilder.handleCoordinates has 6 return statements (exceeds 4 allowed).
          Open

          func (builder *VehicleMonitoringUpdateEventBuilder) handleCoordinates(xmlVehicleActivity *sxml.XMLVehicleActivity) (lon, lat float64, e error) {
              longitude, _ := strconv.ParseFloat(xmlVehicleActivity.Longitude(), 64)
              latitude, _ := strconv.ParseFloat(xmlVehicleActivity.Latitude(), 64)
          
              if latitude != 0 || longitude != 0 {
          Severity: Major
          Found in core/vehicle_monitoring_update_event_builder.go - About 40 mins to fix

            Method BroadcastStopMonitoringBuilder.BuildCancelledStopVisit has 6 return statements (exceeds 4 allowed).
            Open

            func (builder *BroadcastStopMonitoringBuilder) BuildCancelledStopVisit(stopVisit *model.StopVisit) *siri.SIRICancelledStopVisit {
                vehicleJourney, ok := builder.partner.Model().VehicleJourneys().Find(stopVisit.VehicleJourneyId)
                if !ok {
                    logger.Log.Printf("Ignore CancelledStopVisit %s without Vehiclejourney", stopVisit.Id())
                    return nil
            Severity: Major
            Found in core/broadcast_stop_monitoring_builder.go - About 40 mins to fix

              Method MemoryStopVisits.Load has 6 return statements (exceeds 4 allowed).
              Open

              func (manager *MemoryStopVisits) Load(referentialSlug string) error {
                  var selectStopVisits []SelectStopVisit
                  modelName := manager.model.Date()
              
                  sqlQuery := fmt.Sprintf("select * from stop_visits where referential_slug = '%s' and model_name = '%s'", referentialSlug, modelName.String())
              Severity: Major
              Found in model/stop_visit.go - About 40 mins to fix

                Method EstimatedTimetableLastChange.Haschanged has 6 return statements (exceeds 4 allowed).
                Open

                func (ettlc *EstimatedTimetableLastChange) Haschanged(stopVisit *model.StopVisit) bool {
                    // Don't send info on cancelled or departed SV
                    if ettlc.departureStatus == model.STOP_VISIT_DEPARTURE_DEPARTED || ettlc.departureStatus == model.STOP_VISIT_DEPARTURE_CANCELLED || ettlc.arrivalStatuts == model.STOP_VISIT_ARRIVAL_ARRIVED || ettlc.arrivalStatuts == model.STOP_VISIT_ARRIVAL_CANCELLED {
                        return false
                    }
                Severity: Major
                Found in core/ls/estimated_timetable_lc.go - About 40 mins to fix

                  Method VehicleMonitoringLastChange.HasChanged has 6 return statements (exceeds 4 allowed).
                  Open

                  func (vmlc *VehicleMonitoringLastChange) HasChanged(v *model.Vehicle) bool {
                      // Check LinkDistance
                      if vmlc.LinkDistance != v.LinkDistance {
                          return true
                      }
                  Severity: Major
                  Found in core/ls/vehicle_monitoring_lc.go - About 40 mins to fix

                    Method GtfsHandler.serve has 6 return statements (exceeds 4 allowed).
                    Open

                    func (handler *GtfsHandler) serve(response http.ResponseWriter, request *http.Request, resource string) {
                        // Find Partner by authorization Key
                        partner, ok := handler.referential.Partners().FindByCredential(handler.token)
                        if !ok {
                            http.Error(response, "Invalid Authorization Token", http.StatusUnauthorized)
                    Severity: Major
                    Found in api/gtfs_handler.go - About 40 mins to fix

                      Method SIRIEstimatedTimetableSubscriptionBroadcaster.stopPointRef has 6 return statements (exceeds 4 allowed).
                      Open

                      func (connector *SIRIEstimatedTimetableSubscriptionBroadcaster) stopPointRef(stopAreaId model.StopAreaId) (*model.StopArea, string, bool) {
                          stopPointRef, ok := connector.Partner().Model().StopAreas().Find(stopAreaId)
                          if !ok {
                              return &model.StopArea{}, "", false
                          }
                      Severity: Major
                      Found in core/estimated_timetable_broadcaster.go - About 40 mins to fix

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

                        func (s *PartnerSettings) VehicleJourneyRemoteCodeSpaceWithFallback(connectorName string) []string {
                            value, ok := s.vehicleJourneyRemoteCodeSpacesByConnector.Load(connectorName)
                            if ok {
                                return value.([]string)
                            }
                        Severity: Minor
                        Found in core/settings/partner_settings.go and 1 other location - About 40 mins to fix
                        core/settings/partner_settings.go on lines 356..367

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

                        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

                        Severity
                        Category
                        Status
                        Source
                        Language