Showing 146 of 546 total issues
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 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 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 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 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 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 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 SIRIProductionTimetableSubscriptionBroadcaster.stopPointRef
has 5 return statements (exceeds 4 allowed). Open
Open
func (connector *SIRIProductionTimetableSubscriptionBroadcaster) stopPointRef(stopAreaId model.StopAreaId) (*model.StopArea, string, bool) {
stopPointRef, ok := connector.Partner().Model().StopAreas().Find(stopAreaId)
if !ok {
return &model.StopArea{}, "", false
}
Method Partner.CanCollectLines
has 5 return statements (exceeds 4 allowed). Open
Open
func (partner *Partner) CanCollectLines(lineIds map[string]struct{}) s.CollectStatus {
if len(lineIds) == 0 {
return s.COLLECT_UNKNOWN
}
Method SIRIEstimatedTimetableRequestBroadcaster.stopPointRef
has 5 return statements (exceeds 4 allowed). Open
Open
func (connector *SIRIEstimatedTimetableRequestBroadcaster) stopPointRef(stopAreaId model.StopAreaId) (*model.StopArea, string, bool) {
stopPointRef, ok := connector.partner.Model().StopAreas().Find(stopAreaId)
if !ok {
return &model.StopArea{}, "", false
}
Method SIRILiteHandler.serve
has 5 return statements (exceeds 4 allowed). Open
Open
func (handler *SIRILiteHandler) serve(response http.ResponseWriter, request *http.Request, requestData *SIRIRequestData) {
if handler.token == "" {
http.Error(response, "No Authorization Token", http.StatusUnauthorized)
return
}
Function AffectFromProto
has 5 return statements (exceeds 4 allowed). Open
Open
func AffectFromProto(value interface{}, remoteCodeSpace string, m Model) (Affect, *AffectRefs, error) {
collectedRefs := &AffectRefs{
MonitoringRefs: make(map[string]struct{}),
LineRefs: make(map[string]struct{}),
}
Method MemoryVehicleJourneys.Load
has 5 return statements (exceeds 4 allowed). Open
Open
func (manager *MemoryVehicleJourneys) Load(referentialSlug string) error {
var selectVehicleJourneys []SelectVehicleJourney
modelName := manager.model.Date()
sqlQuery := fmt.Sprintf("select * from vehicle_journeys where referential_slug = '%s' and model_name = '%s'", referentialSlug, modelName.String())
_, err := Database.Select(&selectVehicleJourneys, sqlQuery)
Method SituationExchangeUpdateEventBuilder.buildSituationExchangeUpdateEvent
has a Cognitive Complexity of 22 (exceeds 20 allowed). Consider refactoring. Open
Open
func (builder *SituationExchangeUpdateEventBuilder) buildSituationExchangeUpdateEvent(event *CollectUpdateEvents, xmlSituation *sxml.XMLPtSituationElement, producerRef string) {
if len(xmlSituation.Affects()) == 0 {
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 StopMonitoringLastChange.Haschanged
has 5 return statements (exceeds 4 allowed). Open
Open
func (smlc *StopMonitoringLastChange) Haschanged(stopVisit *model.StopVisit) bool {
// Don't send info on cancelled or departed SV
if smlc.departureStatus == model.STOP_VISIT_DEPARTURE_DEPARTED || smlc.departureStatus == model.STOP_VISIT_DEPARTURE_CANCELLED || smlc.arrivalStatuts == model.STOP_VISIT_ARRIVAL_CANCELLED {
return false
}
Method TimeController.serve
has 5 return statements (exceeds 4 allowed). Open
Open
func (controller *TimeController) serve(response http.ResponseWriter, request *http.Request, requestData *RequestData) {
switch {
case request.Method == "GET":
if requestData.Resource != "" {
http.Error(response, "Invalid request", http.StatusBadRequest)
Method BroadcastGeneralMessageBuilder.canBroadcast
has 5 return statements (exceeds 4 allowed). Open
Open
func (builder *BroadcastGeneralMessageBuilder) canBroadcast(situation model.Situation) bool {
if situation.Origin == string(builder.partner.Slug()) {
return false
}
Method BroadcastSituationExchangeBuilder.canBroadcast
has 5 return statements (exceeds 4 allowed). Open
Open
func (builder *BroadcastSituationExchangeBuilder) canBroadcast(situation model.Situation) bool {
if situation.Origin == string(builder.partner.Slug()) {
return false
}
Method Loader.Load
has a Cognitive Complexity of 22 (exceeds 20 allowed). Consider refactoring. Open
Open
func (loader Loader) Load(reader io.Reader) Result {
// Config CSV reader
csvReader := csv.NewReader(reader)
csvReader.Comment = '#'
csvReader.FieldsPerRecord = -1
- 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 MemoryLines.Load
has 5 return statements (exceeds 4 allowed). Open
Open
func (manager *MemoryLines) Load(referentialSlug string) error {
var selectLines []SelectLine
modelName := manager.model.Date()
sqlQuery := fmt.Sprintf("select * from lines where referential_slug = '%s' and model_name = '%s'", referentialSlug, modelName.String())
_, err := Database.Select(&selectLines, sqlQuery)