src/jetstream/plugins/backup/backup_restore.go
Method cnsiTokenBackup.createBackup
has a Cognitive Complexity of 20 (exceeds 8 allowed). Consider refactoring. Open
Open
func (ctb *cnsiTokenBackup) createBackup(data *BackupRequest) (*BackupContent, error) {
log.Debug("createBackup")
allEndpoints, err := ctb.p.ListEndpoints()
if err != nil {
return nil, interfaces.NewHTTPShadowError(http.StatusBadGateway, "Failed to fetch endpoints", "Failed to fetch endpoints: %+v", err)
- 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 cnsiTokenBackup.restoreBackup
has a Cognitive Complexity of 14 (exceeds 8 allowed). Consider refactoring. Open
Open
func (ctb *cnsiTokenBackup) restoreBackup(backup *RestoreRequest) error {
log.Debug("restoreBackup")
data := &BackupContent{}
if err := json.Unmarshal([]byte(backup.Data), data); err != nil {
- 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 cnsiTokenBackup.createBackup
has 53 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func (ctb *cnsiTokenBackup) createBackup(data *BackupRequest) (*BackupContent, error) {
log.Debug("createBackup")
allEndpoints, err := ctb.p.ListEndpoints()
if err != nil {
return nil, interfaces.NewHTTPShadowError(http.StatusBadGateway, "Failed to fetch endpoints", "Failed to fetch endpoints: %+v", err)
Method cnsiTokenBackup.restoreBackup
has 9 return statements (exceeds 4 allowed). Open
Open
func (ctb *cnsiTokenBackup) restoreBackup(backup *RestoreRequest) error {
log.Debug("restoreBackup")
data := &BackupContent{}
if err := json.Unmarshal([]byte(backup.Data), data); err != nil {
Method cnsiTokenBackup.BackupEndpoints
has 6 return statements (exceeds 4 allowed). Open
Open
func (ctb *cnsiTokenBackup) BackupEndpoints(c echo.Context) error {
log.Debug("BackupEndpoints")
// Create the backup request struct from the body
body, err := ioutil.ReadAll(c.Request().Body)
Method cnsiTokenBackup.createBackup
has 5 return statements (exceeds 4 allowed). Open
Open
func (ctb *cnsiTokenBackup) createBackup(data *BackupRequest) (*BackupContent, error) {
log.Debug("createBackup")
allEndpoints, err := ctb.p.ListEndpoints()
if err != nil {
return nil, interfaces.NewHTTPShadowError(http.StatusBadGateway, "Failed to fetch endpoints", "Failed to fetch endpoints: %+v", err)