Showing 59 of 80 total issues
Avoid deeply nested control flow statements. Open
Open
} else if r.URL.Query().Get("username") == "broken_json" {
w.Write([]byte("{ \"message\": \"broken json!\""))
} else if r.URL.Query().Get("username") == "broken_empty" {
w.WriteHeader(http.StatusForbidden)
} else {
Method mock_server
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
Open
def mock_server(server)
server.mount_proc('/api/v4/internal/discover') do |req, res|
identifier = req.query['key_id'] || req.query['username'] || req.query['user_id']
known_identifiers = %w(10 someuser 100)
if known_identifiers.include?(identifier)
- 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 Client.Batch
has 6 return statements (exceeds 4 allowed). Open
Open
func (c *Client) Batch(operation string, reqObjects []*BatchObject, ref string, reqHashAlgo string) (*BatchResponse, error) {
var bref *batchRef
// FIXME: This causes tests to fail
// if ref == "" {
Method Command.Execute
has 6 return statements (exceeds 4 allowed). Open
Open
func (c *Command) Execute(ctx context.Context) (context.Context, error) {
args := c.Args.SshArgs
if len(args) != 2 {
return ctx, disallowedcommand.Error
}
Method Command.Execute
has 6 return statements (exceeds 4 allowed). Open
Open
func (c *Command) Execute(ctx context.Context) (context.Context, error) {
args := c.Args.SshArgs
if len(args) != 2 {
return ctx, disallowedcommand.Error
}
Function writeCommandArgsAndTextData
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
Open
func writeCommandArgsAndTextData(t *testing.T, pl *pktline.Pktline, command string, args []string, data []string) {
Function Audit
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
Open
func Audit(ctx context.Context, commandType commandargs.CommandType, c *config.Config, response *accessverifier.Response, packfileStats *pb.PackfileNegotiationStatistics) {
Method Client.getRequestBody
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
Open
func (c *Client) getRequestBody(ctx context.Context, args *commandargs.Shell, name string, scopes *[]string, expiresAt string) (*RequestBody, error) {
Function writeCommandArgsAndBinaryData
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
Open
func writeCommandArgsAndBinaryData(t *testing.T, pl *pktline.Pktline, command string, args []string, data [][]byte) {
Method Client.GetPersonalAccessToken
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
Open
func (c *Client) GetPersonalAccessToken(ctx context.Context, args *commandargs.Shell, name string, scopes *[]string, expiresAt string) (*Response, error) {
Method Client.Audit
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
Open
func (c *Client) Audit(ctx context.Context, username string, action commandargs.CommandType, repo string, packfileStats *pb.PackfileNegotiationStatistics) error {
Function newFromFile
has 5 return statements (exceeds 4 allowed). Open
Open
func newFromFile(path string) (*Config, error) {
cfg := &Config{}
*cfg = DefaultConfig
cfg.RootDir = filepath.Dir(path)
Method Client.do
has 5 return statements (exceeds 4 allowed). Open
Open
func (c *Client) do(request *http.Request) (*http.Response, error) {
for k, v := range c.Headers {
request.Header.Add(k, v)
}
Method Command.processAPIEndpoints
has 5 return statements (exceeds 4 allowed). Open
Open
func (c *Command) processAPIEndpoints(ctx context.Context, response *accessverifier.Response) error {
client, err := gitlabnet.GetClient(c.Config)
if err != nil {
return err
Method Command.Execute
has 5 return statements (exceeds 4 allowed). Open
Open
func (c *Command) Execute(ctx context.Context) (context.Context, error) {
args := c.Args.SshArgs
if len(args) < 3 {
return ctx, disallowedcommand.Error
}
Method Command.Execute
has 5 return statements (exceeds 4 allowed). Open
Open
func (c *Command) Execute(ctx context.Context) (context.Context, error) {
args := c.Args.SshArgs
if len(args) != 3 {
return ctx, disallowedcommand.Error
}
Method serverConfig.get
has 5 return statements (exceeds 4 allowed). Open
Open
func (s *serverConfig) get(ctx context.Context) *ssh.ServerConfig {
var gssapiWithMICConfig *ssh.GSSAPIWithMICConfig
if s.cfg.Server.GSSAPI.Enabled {
gssApiServer, _ := NewGSSAPIServer(&s.cfg.Server.GSSAPI)
Method OSGSSAPIServer.AcceptSecContext
has 5 return statements (exceeds 4 allowed). Open
Open
func (server *OSGSSAPIServer) AcceptSecContext(
token []byte,
) (
outputToken []byte,
srcName string,
Method serverConfig.handleUserCertificate
has 5 return statements (exceeds 4 allowed). Open
Open
func (s *serverConfig) handleUserCertificate(ctx context.Context, user string, cert *ssh.Certificate) (*ssh.Permissions, error) {
if os.Getenv("FF_GITLAB_SHELL_SSH_CERTIFICATES") != "1" {
return nil, fmt.Errorf("handleUserCertificate: feature is disabled")
}