Showing 146 of 546 total issues

Method SIRIClient.prepareAndSendRequest has 51 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func (client *SIRIClient) prepareAndSendRequest(args siriClientArguments) (xml.Node, error) {
    // Wrap the request XML
    buffer := NewSIRIBuffer(client.siriEnvelopeType)

    xml, err := args.request.BuildXML(client.siriEnvelopeType)
Severity: Minor
Found in remote/siri_client.go - About 1 hr to fix

    Method SIRIGeneralMessageSubscriptionBroadcaster.HandleSubscriptionRequest has 51 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func (connector *SIRIGeneralMessageSubscriptionBroadcaster) HandleSubscriptionRequest(request *sxml.XMLSubscriptionRequest, message *audit.BigQueryMessage) []siri.SIRIResponseStatus {
        resps := []siri.SIRIResponseStatus{}
    
        var subIds []string
    
    
    Severity: Minor
    Found in core/siri_general_message_subscription_broadcaster.go - About 1 hr to fix

      Method SIRIStopMonitoringSubscriptionBroadcaster.checkStopAreaEvent has a Cognitive Complexity of 24 (exceeds 20 allowed). Consider refactoring.
      Open

      func (connector *SIRIStopMonitoringSubscriptionBroadcaster) checkStopAreaEvent(stopArea *model.StopArea) {
          obj, ok := stopArea.Code(connector.remoteCodeSpace)
          if !ok {
              return
          }
      Severity: Minor
      Found in core/siri_stop_monitoring_subscription_broadcaster.go - About 55 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

      Method SIRIClient.prepareAndSendRequest has 9 return statements (exceeds 4 allowed).
      Open

      func (client *SIRIClient) prepareAndSendRequest(args siriClientArguments) (xml.Node, error) {
          // Wrap the request XML
          buffer := NewSIRIBuffer(client.siriEnvelopeType)
      
          xml, err := args.request.BuildXML(client.siriEnvelopeType)
      Severity: Major
      Found in remote/siri_client.go - About 55 mins to fix

        Method SIRILiteClient.prepareAndSendRequest has 9 return statements (exceeds 4 allowed).
        Open

        func (c *SIRILiteClient) prepareAndSendRequest(args siriLiteClientArguments) error {
            dest := args.destination
        
            ctx, cncl := context.WithTimeout(context.Background(), getTimeOut(args.requestType))
            defer cncl()
        Severity: Major
        Found in remote/siri_lite_client.go - About 55 mins to fix

          Method MemoryReferentials.Load has a Cognitive Complexity of 24 (exceeds 20 allowed). Consider refactoring.
          Open

          func (manager *MemoryReferentials) Load() error {
              selectReferentials := []model.SelectReferential{}
              _, err := model.Database.Select(&selectReferentials, "select * from referentials")
              if err != nil {
                  return err
          Severity: Minor
          Found in core/referential.go - About 55 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

          Method Partner.hasSubscribers has 8 return statements (exceeds 4 allowed).
          Open

          func (partner *Partner) hasSubscribers() bool {
              _, ok := partner.connectors[SIRI_STOP_MONITORING_SUBSCRIPTION_BROADCASTER]
              if ok {
                  return true
              }
          Severity: Major
          Found in core/partner.go - About 50 mins to fix

            Method HTTPClient.GTFSRequest has 8 return statements (exceeds 4 allowed).
            Open

            func (c *HTTPClient) GTFSRequest() (*gtfs.FeedMessage, error) {
                ctx, cncl := context.WithTimeout(context.Background(), 60*time.Second)
                defer cncl()
            
                httpRequest, err := http.NewRequestWithContext(ctx, http.MethodGet, c.Url, nil)
            Severity: Major
            Found in remote/http_client.go - About 50 mins to fix

              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 BigQueryClient.findOrCreateDataset has 8 return statements (exceeds 4 allowed).
                Open

                func (bq *BigQueryClient) findOrCreateDataset() (*bigquery.Dataset, error) {
                    it := bq.client.Datasets(bq.ctx)
                    for {
                        dataset, err := it.Next()
                        if err == iterator.Done {
                Severity: Major
                Found in audit/bigquery.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 PushHandler.serve has 8 return statements (exceeds 4 allowed).
                    Open

                    func (handler *PushHandler) serve(response http.ResponseWriter, request *http.Request) {
                        // Check if request header is protobuf or return an error
                        if request.Header.Get("Content-Type") != "application/x-protobuf" {
                            http.Error(response, "Expected application/x-protobuf content", http.StatusUnsupportedMediaType)
                            return
                    Severity: Major
                    Found in api/push_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

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

                          func AffectToProto(a Affect, remoteCodeSpace string, m Model) ([]*gtfs.EntitySelector, *AffectRefs, error) {
                              collectedRefs := &AffectRefs{
                                  MonitoringRefs: make(map[string]struct{}),
                                  LineRefs:       make(map[string]struct{}),
                              }
                          Severity: Major
                          Found in model/situation.go - About 45 mins to fix

                            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 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 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
                                      Severity
                                      Category
                                      Status
                                      Source
                                      Language