Showing 9 of 21 total issues
goPgDB
has 21 methods (exceeds 20 allowed). Consider refactoring. Open
Open
type goPgDB struct {
sqlMock *SQLMock
}
Function NewServices
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
Open
func NewServices(DB *pg.DB, Log *zap.Logger, JWT *mw.JWT, Mail mail.Service, Mobile mobile.Service, R *gin.Engine) *Services {
Method Service.Authenticate
has 6 return statements (exceeds 4 allowed). Open
Open
func (s *Service) Authenticate(c context.Context, email, password string) (*model.AuthToken, error) {
u, err := s.userRepo.FindByEmail(email)
if err != nil {
return nil, apperr.Unauthorized
}
Method Service.MobileVerify
has 6 return statements (exceeds 4 allowed). Open
Open
func (s *Service) MobileVerify(c context.Context, countryCode, mobile, code string, signup bool) (*model.AuthToken, error) {
// send code to twilio
err := s.mob.CheckCode(countryCode, mobile, code)
if err != nil {
return nil, err
Method AccountRepo.CreateWithMobile
has 6 return statements (exceeds 4 allowed). Open
Open
func (a *AccountRepo) CreateWithMobile(u *model.User) error {
user := new(model.User)
sql := `SELECT id FROM users WHERE username = ? OR email = ? OR (country_code = ? AND mobile = ?) AND deleted_at IS NULL`
res, err := a.db.Query(user, sql, u.Username, u.Email, u.CountryCode, u.Mobile)
if err == apperr.DB {
Function NewAuthService
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
Open
func NewAuthService(userRepo model.UserRepo, accountRepo model.AccountRepo, jwt JWT, m mail.Service, mob mobile.Service) *Service {
Method AccountRepo.CreateAndVerify
has 5 return statements (exceeds 4 allowed). Open
Open
func (a *AccountRepo) CreateAndVerify(u *model.User) (*model.Verification, error) {
user := new(model.User)
sql := `SELECT id FROM users WHERE username = ? OR email = ? OR (country_code = ? AND mobile = ?) AND deleted_at IS NULL`
res, err := a.db.Query(user, sql, u.Username, u.Email, u.CountryCode, u.Mobile)
if err == apperr.DB {
Method goPgDB.doQuery
has 5 return statements (exceeds 4 allowed). Open
Open
func (p *goPgDB) doQuery(ctx context.Context, dst interface{}, query string, params ...interface{}) (orm.Result, error) {
// replace duplicate space
space := regexp.MustCompile(`\s+`)
for k, v := range p.sqlMock.queries {
Function Merge
has a Cognitive Complexity of 21 (exceeds 20 allowed). Consider refactoring. Open
Open
func Merge(dst, src interface{}) {
s := reflect.ValueOf(src)
d := reflect.ValueOf(dst)
if s.Kind() != reflect.Ptr || d.Kind() != reflect.Ptr {
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"