dictyBase/modware-user

View on GitHub

Showing 43 of 119 total issues

Method UserService.ListUsers has a Cognitive Complexity of 113 (exceeds 20 allowed). Consider refactoring.
Open

func (s *UserService) ListUsers(ctx context.Context, r *jsonapi.ListRequest) (*user.UserCollection, error) {
    params, md, err := aphgrpc.ValidateAndParseListParams(s, r)
    if err != nil {
        grpc.SetTrailer(ctx, md)
        return &user.UserCollection{}, status.Error(codes.InvalidArgument, err.Error())
Severity: Minor
Found in server/user.go - About 1 day 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

File user.go has 963 lines of code (exceeds 500 allowed). Consider refactoring.
Open

package server

import (
    "context"
    "fmt"
Severity: Major
Found in server/user.go - About 1 day to fix

File role.go has 868 lines of code (exceeds 500 allowed). Consider refactoring.
Open

package server

import (
    "context"
    "fmt"
Severity: Major
Found in server/role.go - About 1 day to fix

Function main has 235 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func main() {
    app := cli.NewApp()
    app.Name = "modware-user"
    app.Usage = "starts the modware-user microservice with HTTP and grpc backends"
    app.Version = "1.0.0"
Severity: Major
Found in main.go - About 1 day to fix

Method UserService.ListUsers has 202 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func (s *UserService) ListUsers(ctx context.Context, r *jsonapi.ListRequest) (*user.UserCollection, error) {
    params, md, err := aphgrpc.ValidateAndParseListParams(s, r)
    if err != nil {
        grpc.SetTrailer(ctx, md)
        return &user.UserCollection{}, status.Error(codes.InvalidArgument, err.Error())
Severity: Major
Found in server/user.go - About 7 hrs to fix

Method UserService.ListUsers has 57 return statements (exceeds 4 allowed).
Open

func (s *UserService) ListUsers(ctx context.Context, r *jsonapi.ListRequest) (*user.UserCollection, error) {
    params, md, err := aphgrpc.ValidateAndParseListParams(s, r)
    if err != nil {
        grpc.SetTrailer(ctx, md)
        return &user.UserCollection{}, status.Error(codes.InvalidArgument, err.Error())
Severity: Major
Found in server/user.go - About 4 hrs to fix

UserService has 36 methods (exceeds 20 allowed). Consider refactoring.
Open

type UserService struct {
    *aphgrpc.Service
}
Severity: Minor
Found in server/user.go - About 4 hrs to fix

RoleService has 35 methods (exceeds 20 allowed). Consider refactoring.
Open

type RoleService struct {
    *aphgrpc.Service
}
Severity: Minor
Found in server/role.go - About 4 hrs to fix

Function LoadUser has 106 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func LoadUser(c *cli.Context) error {
    conn, err := grpc.Dial(
        fmt.Sprintf("%s:%s", c.String("user-grpc-host"), c.String("user-grpc-port")),
        grpc.WithInsecure(),
    )
Severity: Major
Found in commands/load.go - About 3 hrs to fix

Method RoleService.ListRoles has 78 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func (s *RoleService) ListRoles(ctx context.Context, r *jsonapi.SimpleListRequest) (*user.RoleCollection, error) {
    params, md, err := aphgrpc.ValidateAndParseSimpleListParams(s, r)
    if err != nil {
        grpc.SetTrailer(ctx, md)
        return &user.RoleCollection{}, status.Error(codes.InvalidArgument, err.Error())
Severity: Major
Found in server/role.go - About 2 hrs to fix

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

func (s *RoleService) ListRoles(ctx context.Context, r *jsonapi.SimpleListRequest) (*user.RoleCollection, error) {
    params, md, err := aphgrpc.ValidateAndParseSimpleListParams(s, r)
    if err != nil {
        grpc.SetTrailer(ctx, md)
        return &user.RoleCollection{}, status.Error(codes.InvalidArgument, err.Error())
Severity: Minor
Found in server/role.go - About 1 hr 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.ListRoles has 21 return statements (exceeds 4 allowed).
Open

func (s *RoleService) ListRoles(ctx context.Context, r *jsonapi.SimpleListRequest) (*user.RoleCollection, error) {
    params, md, err := aphgrpc.ValidateAndParseSimpleListParams(s, r)
    if err != nil {
        grpc.SetTrailer(ctx, md)
        return &user.RoleCollection{}, status.Error(codes.InvalidArgument, err.Error())
Severity: Major
Found in server/role.go - About 1 hr to fix

Function RunPermissionServer has 71 lines of code (exceeds 50 allowed). Consider refactoring.
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: Minor
Found in commands/server.go - About 1 hr to fix

Function RunUserServer has 71 lines of code (exceeds 50 allowed). Consider refactoring.
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: Minor
Found in commands/server.go - About 1 hr to fix

Function RunRoleServer has 71 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func RunRoleServer(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: Minor
Found in commands/server.go - About 1 hr to fix

Function newUser has a Cognitive Complexity of 27 (exceeds 20 allowed). Consider refactoring.
Open

func newUser(record []string) *pb.CreateUserRequest {
    attr := &pb.UserAttributes{}
    for i, v := range record {
        switch i {
        case 6:
Severity: Minor
Found in commands/load.go - About 1 hr 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 UserService.UpdateUser has 53 lines of code (exceeds 50 allowed). Consider refactoring.
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: Minor
Found in server/user.go - About 1 hr to fix

Function LoadUser has 11 return statements (exceeds 4 allowed).
Open

func LoadUser(c *cli.Context) error {
    conn, err := grpc.Dial(
        fmt.Sprintf("%s:%s", c.String("user-grpc-host"), c.String("user-grpc-port")),
        grpc.WithInsecure(),
    )
Severity: Major
Found in commands/load.go - About 1 hr to fix

Method UserService.GetUser has 11 return statements (exceeds 4 allowed).
Open

func (s *UserService) GetUser(ctx context.Context, r *jsonapi.GetRequest) (*user.User, error) {
    params, md, err := aphgrpc.ValidateAndParseGetParams(s, r)
    if err != nil {
        grpc.SetTrailer(ctx, md)
        return new(user.User), status.Error(codes.InvalidArgument, err.Error())
Severity: Major
Found in server/user.go - About 1 hr to fix

Method RoleService.GetRole has 11 return statements (exceeds 4 allowed).
Open

func (s *RoleService) GetRole(ctx context.Context, r *jsonapi.GetRequest) (*user.Role, error) {
    params, md, err := aphgrpc.ValidateAndParseGetParams(s, r)
    if err != nil {
        grpc.SetTrailer(ctx, md)
        return &user.Role{}, status.Error(codes.InvalidArgument, err.Error())
Severity: Major
Found in server/role.go - About 1 hr to fix
Severity
Category
Status
Source
Language