Showing 134 of 525 total issues

Method Server.HandleFlow has 8 return statements (exceeds 4 allowed).
Open

func (server *Server) HandleFlow(response http.ResponseWriter, request *http.Request) {
    defer monitoring.HandleHttpPanic(response)

    path := request.URL.RequestURI()
    foundStrings := pathPattern.FindStringSubmatch(path)
Severity: Major
Found in api/server.go - About 50 mins to fix

    Method SIRIHandler.serve has 8 return statements (exceeds 4 allowed).
    Open

    func (handler *SIRIHandler) serve(response http.ResponseWriter, request *http.Request) {
        response.Header().Set("Content-Type", "text/xml; charset=utf-8")
    
        m := &audit.BigQueryMessage{
            Protocol:    "siri",
    Severity: Major
    Found in api/siri_handler.go - About 50 mins to fix

      Method PartnerManager.SaveToDatabase has 8 return statements (exceeds 4 allowed).
      Open

      func (manager *PartnerManager) SaveToDatabase() (int, error) {
          // Check presence of Referential
          selectReferentials := []model.SelectReferential{}
          sqlQuery := fmt.Sprintf("select * from referentials where referential_id = '%s'", manager.referential.Id())
          _, err := model.Database.Select(&selectReferentials, sqlQuery)
      Severity: Major
      Found in core/partner.go - About 50 mins to fix

        Method MemoryReferentials.SaveToDatabase has 7 return statements (exceeds 4 allowed).
        Open

        func (manager *MemoryReferentials) SaveToDatabase() (int, error) {
            // Begin transaction
            tx, err := model.Database.Begin()
            if err != nil {
                return http.StatusInternalServerError, fmt.Errorf("database error: %v", err)
        Severity: Major
        Found in core/referential.go - About 45 mins to fix

          Method SXSubscriber.prepareSIRISituationExchangeSubscriptionRequest has a Cognitive Complexity of 23 (exceeds 20 allowed). Consider refactoring.
          Open

          func (subscriber *SXSubscriber) prepareSIRISituationExchangeSubscriptionRequest() {
              subscriptions := subscriber.connector.partner.Subscriptions().FindSubscriptionsByKind(SituationExchangeCollect)
              if len(subscriptions) == 0 {
                  logger.Log.Debugf("SituationExchangeSubscriber visit without SituationExchangeCollect subscriptions")
                  return
          Severity: Minor
          Found in core/siri_situation_exchange_subscriber.go - About 45 mins 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

          Function NewAutodetectSIRIEnvelope has 7 return statements (exceeds 4 allowed).
          Open

          func NewAutodetectSIRIEnvelope(body io.Reader) (*SIRIEnvelope, error) {
              // Attempt to read the body
              content, err := io.ReadAll(body)
              if err != nil {
                  return nil, err
          Severity: Major
          Found in remote/siri_envelope.go - About 45 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 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 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

                  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 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 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 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 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 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 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 SIRISituationExchangeRequestBroadcaster.canBroadcast has 5 return statements (exceeds 4 allowed).
                                  Open

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

                                    Method MemoryReferentials.Load has 5 return statements (exceeds 4 allowed).
                                    Open

                                    func (manager *MemoryReferentials) Load() error {
                                        selectReferentials := []model.SelectReferential{}
                                        _, err := model.Database.Select(&selectReferentials, "select * from referentials")
                                        if err != nil {
                                            return err
                                    Severity: Major
                                    Found in core/referential.go - About 35 mins to fix

                                      Method Purifier.Purge has 5 return statements (exceeds 4 allowed).
                                      Open

                                      func (p *Purifier) Purge() error {
                                          if p.date == "" {
                                              return fmt.Errorf("purifier date is empty")
                                          }
                                      
                                      
                                      Severity: Major
                                      Found in model/purge.go - About 35 mins to fix
                                        Severity
                                        Category
                                        Status
                                        Source
                                        Language