Showing 150 of 150 total issues
Similar blocks of code found in 2 locations. Consider refactoring. Open
func (e *EtcdStore) DeleteRole(ctx context.Context, ref *core.Reference) error {
ctx, ca := context.WithTimeout(ctx, e.CommandTimeout)
defer ca()
resp, err := e.Client.Delete(ctx, path.Join(e.Prefix, roleKey, ref.Id))
if err != nil {
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 154.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Function To
has 60 lines of code (exceeds 50 allowed). Consider refactoring. Open
func To(addr string, opts ...ForwarderOption) func(*fiber.Ctx) error {
defaultLogger := logger.New(
logger.WithSampling(&zap.SamplingConfig{
Initial: 1,
Thereafter: 0,
Function BuildClustersLabelCmd
has 59 lines of code (exceeds 50 allowed). Consider refactoring. Open
func BuildClustersLabelCmd() *cobra.Command {
overwrite := false
cmd := &cobra.Command{
Use: "label [--overwrite] <cluster-id> <label>=<value> [<label>=<value>...]",
Short: "Add labels to a cluster",
Method PrometheusRuleFinder.findRulesInNamespace
has 58 lines of code (exceeds 50 allowed). Consider refactoring. Open
func (f *PrometheusRuleFinder) findRulesInNamespace(
ctx context.Context,
namespace string,
) ([]rulefmt.RuleGroup, error) {
lg := f.logger
Function ControllerGen
has a Cognitive Complexity of 26 (exceeds 20 allowed). Consider refactoring. Open
func ControllerGen() error {
cmd := exec.Command(mg.GoCmd(), "run", "sigs.k8s.io/controller-tools/cmd/controller-gen",
"crd:maxDescLen=0", "object", "paths=./pkg/sdk/api/...", "output:crd:artifacts:config=pkg/sdk/crd",
)
buf := new(bytes.Buffer)
- 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 rbacProvider.SubjectAccess
has 56 lines of code (exceeds 50 allowed). Consider refactoring. Open
func (p *rbacProvider) SubjectAccess(
ctx context.Context,
req *core.SubjectAccessRequest,
) (*core.ReferenceList, error) {
// Look up all role bindings which exist for this user, then look up the roles
Function LoadServingCertBundle
has 56 lines of code (exceeds 50 allowed). Consider refactoring. Open
func LoadServingCertBundle(certsSpec v1beta1.CertsSpec) (*tls.Certificate, *x509.CertPool, error) {
var caCertData, servingCertData, servingKeyData []byte
switch {
case certsSpec.CACert != nil:
data, err := os.ReadFile(*certsSpec.CACert)
Similar blocks of code found in 3 locations. Consider refactoring. Open
func BuildTokensListCmd() *cobra.Command {
return &cobra.Command{
Use: "list",
Short: "List bootstrap tokens",
Run: func(cmd *cobra.Command, args []string) {
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 144.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 3 locations. Consider refactoring. Open
func BuildRoleBindingsListCmd() *cobra.Command {
return &cobra.Command{
Use: "list",
Short: "List role bindings",
Run: func(cmd *cobra.Command, args []string) {
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 144.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 3 locations. Consider refactoring. Open
func BuildRolesListCmd() *cobra.Command {
return &cobra.Command{
Use: "list",
Short: "List roles",
Run: func(cmd *cobra.Command, args []string) {
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 144.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Function newHandler
has 54 lines of code (exceeds 50 allowed). Consider refactoring. Open
func newHandler(
stub grpcdynamic.Stub,
svcDesc *desc.ServiceDescriptor,
mux *runtime.ServeMux,
rule *HTTPRuleDescriptor,
Function DecodeAuthHeader
has 54 lines of code (exceeds 50 allowed). Consider refactoring. Open
func DecodeAuthHeader(header string) (id []byte, nonce uuid.UUID, mac []byte, err error) {
if !strings.HasPrefix(header, "MAC ") {
return nil, uuid.Nil, nil, errors.New("incorrect authorization type")
}
trimmed := strings.TrimSpace(strings.TrimPrefix(header, "MAC"))
Function BuildAccessMatrixCmd
has 54 lines of code (exceeds 50 allowed). Consider refactoring. Open
func BuildAccessMatrixCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "access-matrix",
Short: "Print an access matrix showing all users and their allowed clusters",
Run: func(cmd *cobra.Command, args []string) {
Method Server.handleUserInfoRequest
has 53 lines of code (exceeds 50 allowed). Consider refactoring. Open
func (s *Server) handleUserInfoRequest(rw http.ResponseWriter, req *http.Request) {
lg := s.Logger.With(
"remote_addr", req.RemoteAddr,
"request", req.RequestURI,
)
Function RenderAccessMatrix
has 53 lines of code (exceeds 50 allowed). Consider refactoring. Open
func RenderAccessMatrix(am AccessMatrix) string {
w := table.NewWriter()
w.SetStyle(table.StyleColoredDark)
w.Style().Format = table.FormatOptions{
Footer: text.FormatUpper,
Method Plugin.Install
has 53 lines of code (exceeds 50 allowed). Consider refactoring. Open
func (p *Plugin) Install(cluster *core.Reference) error {
labels := map[string]string{
resources.OpniClusterID: cluster.Id,
}
loggingClusterList := &opniv1beta2.LoggingClusterList{}
Function BuildAccessMatrixCmd
has a Cognitive Complexity of 25 (exceeds 20 allowed). Consider refactoring. Open
func BuildAccessMatrixCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "access-matrix",
Short: "Print an access matrix showing all users and their allowed clusters",
Run: func(cmd *cobra.Command, args []string) {
- 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 ClientConfig.Bootstrap
has 11 return statements (exceeds 4 allowed). Open
func (c *ClientConfig) Bootstrap(
ctx context.Context,
ident ident.Provider,
) (keyring.Keyring, error) {
if c.Token == nil {
Method OpenidMiddleware.Handle
has 52 lines of code (exceeds 50 allowed). Consider refactoring. Open
func (m *OpenidMiddleware) Handle(c *fiber.Ctx) error {
m.lock.Lock()
if m.wellKnownConfig == nil {
c.Status(http.StatusServiceUnavailable)
m.lock.Unlock()
Method Server.handleAuthorizeRequest
has 52 lines of code (exceeds 50 allowed). Consider refactoring. Open
func (s *Server) handleAuthorizeRequest(w http.ResponseWriter, r *http.Request) {
lg := s.Logger.With(
"remote_addr", r.RemoteAddr,
"request", r.RequestURI,
)