Showing 146 of 546 total issues
Method SIRIClient.prepareAndSendRequest
has 51 lines of code (exceeds 50 allowed). Consider refactoring. Open
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)
Method SIRIGeneralMessageSubscriptionBroadcaster.HandleSubscriptionRequest
has 51 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func (connector *SIRIGeneralMessageSubscriptionBroadcaster) HandleSubscriptionRequest(request *sxml.XMLSubscriptionRequest, message *audit.BigQueryMessage) []siri.SIRIResponseStatus {
resps := []siri.SIRIResponseStatus{}
var subIds []string
Method SIRIStopMonitoringSubscriptionBroadcaster.checkStopAreaEvent
has a Cognitive Complexity of 24 (exceeds 20 allowed). Consider refactoring. Open
Open
func (connector *SIRIStopMonitoringSubscriptionBroadcaster) checkStopAreaEvent(stopArea *model.StopArea) {
obj, ok := stopArea.Code(connector.remoteCodeSpace)
if !ok {
return
}
- Read upRead up
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
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)
Method SIRILiteClient.prepareAndSendRequest
has 9 return statements (exceeds 4 allowed). Open
Open
func (c *SIRILiteClient) prepareAndSendRequest(args siriLiteClientArguments) error {
dest := args.destination
ctx, cncl := context.WithTimeout(context.Background(), getTimeOut(args.requestType))
defer cncl()
Method MemoryReferentials.Load
has a Cognitive Complexity of 24 (exceeds 20 allowed). Consider refactoring. Open
Open
func (manager *MemoryReferentials) Load() error {
selectReferentials := []model.SelectReferential{}
_, err := model.Database.Select(&selectReferentials, "select * from referentials")
if err != nil {
return err
- Read upRead up
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
Open
func (partner *Partner) hasSubscribers() bool {
_, ok := partner.connectors[SIRI_STOP_MONITORING_SUBSCRIPTION_BROADCASTER]
if ok {
return true
}
Method HTTPClient.GTFSRequest
has 8 return statements (exceeds 4 allowed). Open
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)
Method Server.HandleFlow
has 8 return statements (exceeds 4 allowed). Open
Open
func (server *Server) HandleFlow(response http.ResponseWriter, request *http.Request) {
defer monitoring.HandleHttpPanic(response)
path := request.URL.RequestURI()
foundStrings := pathPattern.FindStringSubmatch(path)
Method BigQueryClient.findOrCreateDataset
has 8 return statements (exceeds 4 allowed). Open
Open
func (bq *BigQueryClient) findOrCreateDataset() (*bigquery.Dataset, error) {
it := bq.client.Datasets(bq.ctx)
for {
dataset, err := it.Next()
if err == iterator.Done {
Method SIRIHandler.serve
has 8 return statements (exceeds 4 allowed). Open
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",
Method PushHandler.serve
has 8 return statements (exceeds 4 allowed). Open
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
Method PartnerManager.SaveToDatabase
has 8 return statements (exceeds 4 allowed). Open
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)
Method MemoryReferentials.SaveToDatabase
has 7 return statements (exceeds 4 allowed). Open
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)
Function AffectToProto
has 7 return statements (exceeds 4 allowed). Open
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{}),
}
Function NewAutodetectSIRIEnvelope
has 7 return statements (exceeds 4 allowed). Open
Open
func NewAutodetectSIRIEnvelope(body io.Reader) (*SIRIEnvelope, error) {
// Attempt to read the body
content, err := io.ReadAll(body)
if err != nil {
return nil, err
Method BroadcastStopMonitoringBuilder.BuildCancelledStopVisit
has 6 return statements (exceeds 4 allowed). Open
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
Method EstimatedTimetableLastChange.Haschanged
has 6 return statements (exceeds 4 allowed). Open
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
}
Method VehicleMonitoringLastChange.HasChanged
has 6 return statements (exceeds 4 allowed). Open
Open
func (vmlc *VehicleMonitoringLastChange) HasChanged(v *model.Vehicle) bool {
// Check LinkDistance
if vmlc.LinkDistance != v.LinkDistance {
return true
}
Method GtfsHandler.serve
has 6 return statements (exceeds 4 allowed). Open
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)