Showing 134 of 525 total issues
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 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 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)
Method SXSubscriber.prepareSIRISituationExchangeSubscriptionRequest
has a Cognitive Complexity of 23 (exceeds 20 allowed). Consider refactoring. Open
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
- 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
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 MemoryStopVisits.Load
has 6 return statements (exceeds 4 allowed). Open
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())
Method VehicleMonitoringUpdateEventBuilder.handleCoordinates
has 6 return statements (exceeds 4 allowed). Open
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 {
Method SIRIEstimatedTimetableSubscriptionBroadcaster.stopPointRef
has 6 return statements (exceeds 4 allowed). Open
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
}
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 BroadcastGeneralMessageBuilder.BuildGeneralMessage
has 6 return statements (exceeds 4 allowed). Open
Open
func (builder *BroadcastGeneralMessageBuilder) BuildGeneralMessage(situation model.Situation) *siri.SIRIGeneralMessage {
if !builder.canBroadcast(situation) {
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 MemoryStopAreas.Load
has 6 return statements (exceeds 4 allowed). Open
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())
Method BroadcastStopMonitoringBuilder.BuildMonitoredStopVisit
has 6 return statements (exceeds 4 allowed). Open
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
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)
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 Controller.serve
has 6 return statements (exceeds 4 allowed). Open
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 {
Method SIRISituationExchangeRequestBroadcaster.canBroadcast
has 5 return statements (exceeds 4 allowed). Open
Open
func (connector *SIRISituationExchangeRequestBroadcaster) canBroadcast(situation model.Situation) bool {
if situation.Origin == string(connector.partner.Slug()) {
return false
}
Method MemoryReferentials.Load
has 5 return statements (exceeds 4 allowed). Open
Open
func (manager *MemoryReferentials) Load() error {
selectReferentials := []model.SelectReferential{}
_, err := model.Database.Select(&selectReferentials, "select * from referentials")
if err != nil {
return err
Method Purifier.Purge
has 5 return statements (exceeds 4 allowed). Open
Open
func (p *Purifier) Purge() error {
if p.date == "" {
return fmt.Errorf("purifier date is empty")
}