dictyBase/modware-user

View on GitHub

Showing 43 of 119 total issues

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

func (s *RoleService) dbToCollResourceWithRel(ctx context.Context, dbrows []*dbRole) (*user.RoleCollection, error) {
    params, ok := ctx.Value(aphgrpc.ContextKeyParams).(*aphgrpc.JSONAPIParams)
    if !ok {
        return &user.RoleCollection{}, fmt.Errorf("no params object found in context")
    }
Severity: Minor
Found in server/role.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 RoleService.UpdateRole has a Cognitive Complexity of 24 (exceeds 20 allowed). Consider refactoring.
Open

func (s *RoleService) UpdateRole(ctx context.Context, r *user.UpdateRoleRequest) (*user.Role, error) {
    result, err := s.existsResource(r.Id)
    if err != nil {
        return &user.Role{}, aphgrpc.HandleError(ctx, err)
    }
Severity: Minor
Found in server/role.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 PermissionService.ListPermissions has 9 return statements (exceeds 4 allowed).
Open

func (s *PermissionService) ListPermissions(ctx context.Context, r *jsonapi.SimpleListRequest) (*user.PermissionCollection, error) {
    params, md, err := aphgrpc.ValidateAndParseSimpleListParams(s, r)
    if err != nil {
        grpc.SetTrailer(ctx, md)
        return &user.PermissionCollection{}, status.Error(codes.InvalidArgument, err.Error())
Severity: Major
Found in server/permission.go - About 55 mins to fix

Method RoleService.CreatePermissionRelationship has 7 return statements (exceeds 4 allowed).
Open

func (s *RoleService) CreatePermissionRelationship(ctx context.Context, r *jsonapi.DataCollection) (*empty.Empty, error) {
    if len(r.Data) == 0 {
        return &empty.Empty{}, aphgrpc.HandleInsertArgError(ctx, fmt.Errorf("no id given"))
    }
    result, err := s.existsResource(r.Id)
Severity: Major
Found in server/role.go - About 45 mins to fix

Method RoleService.CreateUserRelationship has 7 return statements (exceeds 4 allowed).
Open

func (s *RoleService) CreateUserRelationship(ctx context.Context, r *jsonapi.DataCollection) (*empty.Empty, error) {
    if len(r.Data) == 0 {
        return &empty.Empty{}, aphgrpc.HandleInsertArgError(ctx, fmt.Errorf("no id given"))
    }
    result, err := s.existsResource(r.Id)
Severity: Major
Found in server/role.go - About 45 mins to fix

Method UserService.CreateRoleRelationship has 7 return statements (exceeds 4 allowed).
Open

func (s *UserService) CreateRoleRelationship(ctx context.Context, r *jsonapi.DataCollection) (*empty.Empty, error) {
    if len(r.Data) == 0 {
        return &empty.Empty{}, aphgrpc.HandleInsertArgError(ctx, fmt.Errorf("no id given"))
    }
    result, err := s.existsResource(r.Id)
Severity: Major
Found in server/user.go - About 45 mins to fix

Method RoleService.UpdatePermissionRelationship has 6 return statements (exceeds 4 allowed).
Open

func (s *RoleService) UpdatePermissionRelationship(ctx context.Context, r *jsonapi.DataCollection) (*empty.Empty, error) {
    if len(r.Data) == 0 {
        return &empty.Empty{}, aphgrpc.HandleInsertArgError(ctx, fmt.Errorf("no id given"))
    }
    result, err := s.existsResource(r.Id)
Severity: Major
Found in server/role.go - About 40 mins to fix

Method RoleService.dbToCollResourceWithRel has 6 return statements (exceeds 4 allowed).
Open

func (s *RoleService) dbToCollResourceWithRel(ctx context.Context, dbrows []*dbRole) (*user.RoleCollection, error) {
    params, ok := ctx.Value(aphgrpc.ContextKeyParams).(*aphgrpc.JSONAPIParams)
    if !ok {
        return &user.RoleCollection{}, fmt.Errorf("no params object found in context")
    }
Severity: Major
Found in server/role.go - About 40 mins to fix

Method UserService.UpdateUser has 6 return statements (exceeds 4 allowed).
Open

func (s *UserService) UpdateUser(ctx context.Context, r *user.UpdateUserRequest) (*user.User, error) {
    result, err := s.existsResource(r.Id)
    if err != nil {
        return &user.User{}, aphgrpc.HandleError(ctx, err)
    }
Severity: Major
Found in server/user.go - About 40 mins to fix

Function replyUser has 6 return statements (exceeds 4 allowed).
Open

func replyUser(subj string, c message.UserClient, req *pubsub.IdRequest) *pubsub.UserReply {
    switch subj {
    case "UserService.Get":
        u, err := c.Get(req.Id)
        if err != nil {
Severity: Major
Found in commands/reply.go - About 40 mins to fix

Method RoleService.buildResourceRelationships has 6 return statements (exceeds 4 allowed).
Open

func (s *RoleService) buildResourceRelationships(ctx context.Context, id int64, role *user.Role) error {
    params, ok := ctx.Value(aphgrpc.ContextKeyParams).(*aphgrpc.JSONAPIParams)
    if !ok {
        return fmt.Errorf("no params object found in context")
    }
Severity: Major
Found in server/role.go - About 40 mins to fix

Method RoleService.UpdateUserRelationship has 6 return statements (exceeds 4 allowed).
Open

func (s *RoleService) UpdateUserRelationship(ctx context.Context, r *jsonapi.DataCollection) (*empty.Empty, error) {
    if len(r.Data) == 0 {
        return &empty.Empty{}, aphgrpc.HandleInsertArgError(ctx, fmt.Errorf("no id given"))
    }
    result, err := s.existsResource(r.Id)
Severity: Major
Found in server/role.go - About 40 mins to fix

Method UserService.UpdateRoleRelationship has 6 return statements (exceeds 4 allowed).
Open

func (s *UserService) UpdateRoleRelationship(ctx context.Context, r *jsonapi.DataCollection) (*empty.Empty, error) {
    if len(r.Data) == 0 {
        return &empty.Empty{}, aphgrpc.HandleInsertArgError(ctx, fmt.Errorf("no id given"))
    }
    result, err := s.existsResource(r.Id)
Severity: Major
Found in server/user.go - About 40 mins to fix

Method RoleService.UpdateRole has 6 return statements (exceeds 4 allowed).
Open

func (s *RoleService) UpdateRole(ctx context.Context, r *user.UpdateRoleRequest) (*user.Role, error) {
    result, err := s.existsResource(r.Id)
    if err != nil {
        return &user.Role{}, aphgrpc.HandleError(ctx, err)
    }
Severity: Major
Found in server/role.go - About 40 mins to fix

Function NewTestPostgresFromEnv has 5 return statements (exceeds 4 allowed).
Open

func NewTestPostgresFromEnv() (*TestPostgres, error) {
    pg := new(TestPostgres)
    if err := CheckPostgresEnv(); err != nil {
        return pg, err
    }
Severity: Major
Found in testutils/postgres.go - About 35 mins to fix

Method RoleService.DeletePermissionRelationship has 5 return statements (exceeds 4 allowed).
Open

func (s *RoleService) DeletePermissionRelationship(ctx context.Context, r *jsonapi.DataCollection) (*empty.Empty, error) {
    if len(r.Data) == 0 {
        return &empty.Empty{}, aphgrpc.HandleInsertArgError(ctx, fmt.Errorf("no id given"))
    }
    result, err := s.existsResource(r.Id)
Severity: Major
Found in server/role.go - About 35 mins to fix

Function RunUserServer has 5 return statements (exceeds 4 allowed).
Open

func RunUserServer(c *cli.Context) error {
    dbh, err := getPgWrapper(c)
    if err != nil {
        return cli.NewExitError(
            fmt.Sprintf("Unable to create database connection %s", err.Error()),
Severity: Major
Found in commands/server.go - About 35 mins to fix

Method PermissionService.GetPermission has 5 return statements (exceeds 4 allowed).
Open

func (s *PermissionService) GetPermission(ctx context.Context, r *jsonapi.GetRequestWithFields) (*user.Permission, error) {
    getReq := &jsonapi.GetRequest{
        Id:     r.Id,
        Fields: r.Fields,
    }
Severity: Major
Found in server/permission.go - About 35 mins to fix

Method RoleService.CreateRole has a Cognitive Complexity of 22 (exceeds 20 allowed). Consider refactoring.
Open

func (s *RoleService) CreateRole(ctx context.Context, r *user.CreateRoleRequest) (*user.Role, error) {
    dbrole := s.attrTodbRole(r.Data.Attributes)
    rcolumns := aphgrpc.GetDefinedTags(dbrole, "db")
    if len(rcolumns) > 0 {
        err := s.Dbh.InsertInto("auth_role").
Severity: Minor
Found in server/role.go - About 35 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 RunPermissionServer has 5 return statements (exceeds 4 allowed).
Open

func RunPermissionServer(c *cli.Context) error {
    dbh, err := getPgWrapper(c)
    if err != nil {
        return cli.NewExitError(
            fmt.Sprintf("Unable to create database connection %s", err.Error()),
Severity: Major
Found in commands/server.go - About 35 mins to fix
Severity
Category
Status
Source
Language