File handlers.go
has 1196 lines of code (exceeds 500 allowed). Consider refactoring. Open
package api
import (
"database/sql"
"encoding/hex"
Function handleInsert
has a Cognitive Complexity of 112 (exceeds 20 allowed). Consider refactoring. Open
func handleInsert(exec boil.Executor, input interface{}) (*models.Operation, []events.Event, error) {
r := input.(InsertRequest)
log.Infof("Lookup file by SHA1")
file, _, err := FindFileBySHA1(exec, r.File.Sha1)
- 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
Function handleInsert
has 258 lines of code (exceeds 50 allowed). Consider refactoring. Open
func handleInsert(exec boil.Executor, input interface{}) (*models.Operation, []events.Event, error) {
r := input.(InsertRequest)
log.Infof("Lookup file by SHA1")
file, _, err := FindFileBySHA1(exec, r.File.Sha1)
Function handleSend
has 100 lines of code (exceeds 50 allowed). Consider refactoring. Open
func handleSend(exec boil.Executor, input interface{}) (*models.Operation, []events.Event, error) {
r := input.(SendRequest)
// Original
original, _, err := FindFileBySHA1(exec, r.Original.Sha1)
Function handleTranscode
has 94 lines of code (exceeds 50 allowed). Consider refactoring. Open
func handleTranscode(exec boil.Executor, input interface{}) (*models.Operation, []events.Event, error) {
r := input.(TranscodeRequest)
if r.Message != "" {
log.Infof("Transcode Error: %s", r.Message)
Function handleSend
has a Cognitive Complexity of 35 (exceeds 20 allowed). Consider refactoring. Open
func handleSend(exec boil.Executor, input interface{}) (*models.Operation, []events.Event, error) {
r := input.(SendRequest)
// Original
original, _, err := FindFileBySHA1(exec, r.Original.Sha1)
- 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
Function handleInsert
has 25 return statements (exceeds 4 allowed). Open
func handleInsert(exec boil.Executor, input interface{}) (*models.Operation, []events.Event, error) {
r := input.(InsertRequest)
log.Infof("Lookup file by SHA1")
file, _, err := FindFileBySHA1(exec, r.File.Sha1)
Function handleUpload
has 72 lines of code (exceeds 50 allowed). Consider refactoring. Open
func handleUpload(exec boil.Executor, input interface{}) (*models.Operation, []events.Event, error) {
r := input.(UploadRequest)
log.Info("Creating operation")
operation, err := CreateOperation(exec, common.OP_UPLOAD, r.Operation, nil)
Function handleConvert
has a Cognitive Complexity of 28 (exceeds 20 allowed). Consider refactoring. Open
func handleConvert(exec boil.Executor, input interface{}) (*models.Operation, []events.Event, error) {
r := input.(ConvertRequest)
in, _, err := FindFileBySHA1(exec, r.Sha1)
if 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
Function handleConvert
has 59 lines of code (exceeds 50 allowed). Consider refactoring. Open
func handleConvert(exec boil.Executor, input interface{}) (*models.Operation, []events.Event, error) {
r := input.(ConvertRequest)
in, _, err := FindFileBySHA1(exec, r.Sha1)
if err != nil {
Function DescendantUnitsHandler
has 59 lines of code (exceeds 50 allowed). Consider refactoring. Open
func DescendantUnitsHandler(c *gin.Context) {
mdb := c.MustGet("MDB").(*sql.DB)
f, _, err := FindFileBySHA1(mdb, c.Param("sha1"))
if err != nil {
Function handleSend
has 14 return statements (exceeds 4 allowed). Open
func handleSend(exec boil.Executor, input interface{}) (*models.Operation, []events.Event, error) {
r := input.(SendRequest)
// Original
original, _, err := FindFileBySHA1(exec, r.Original.Sha1)
Function handleUpload
has a Cognitive Complexity of 26 (exceeds 20 allowed). Consider refactoring. Open
func handleUpload(exec boil.Executor, input interface{}) (*models.Operation, []events.Event, error) {
r := input.(UploadRequest)
log.Info("Creating operation")
operation, err := CreateOperation(exec, common.OP_UPLOAD, r.Operation, 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
Function handleTranscode
has 13 return statements (exceeds 4 allowed). Open
func handleTranscode(exec boil.Executor, input interface{}) (*models.Operation, []events.Event, error) {
r := input.(TranscodeRequest)
if r.Message != "" {
log.Infof("Transcode Error: %s", r.Message)
Function handleTranscode
has a Cognitive Complexity of 25 (exceeds 20 allowed). Consider refactoring. Open
func handleTranscode(exec boil.Executor, input interface{}) (*models.Operation, []events.Event, error) {
r := input.(TranscodeRequest)
if r.Message != "" {
log.Infof("Transcode Error: %s", r.Message)
- 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
Function handleJoin
has 51 lines of code (exceeds 50 allowed). Consider refactoring. Open
func handleJoin(exec boil.Executor, input interface{}) (*models.Operation, []events.Event, error) {
r := input.(JoinRequest)
// Fetch input files
inOriginals := make([]*models.File, 0)
Function handleUpload
has 10 return statements (exceeds 4 allowed). Open
func handleUpload(exec boil.Executor, input interface{}) (*models.Operation, []events.Event, error) {
r := input.(UploadRequest)
log.Info("Creating operation")
operation, err := CreateOperation(exec, common.OP_UPLOAD, r.Operation, nil)
Function handleReplace
has 9 return statements (exceeds 4 allowed). Open
func handleReplace(exec boil.Executor, input interface{}) (*models.Operation, []events.Event, error) {
r := input.(ReplaceRequest)
opFiles := make([]*models.File, 0)
Function handleConvert
has 8 return statements (exceeds 4 allowed). Open
func handleConvert(exec boil.Executor, input interface{}) (*models.Operation, []events.Event, error) {
r := input.(ConvertRequest)
in, _, err := FindFileBySHA1(exec, r.Sha1)
if err != nil {
Avoid deeply nested control flow statements. Open
if err != nil {
log.Errorf("Error describing content unit: %s", err.Error())
}
Avoid deeply nested control flow statements. Open
if r.Metadata == nil {
return nil, nil, NewBadRequestError(errors.New("Metadata is required"))
}
Avoid deeply nested control flow statements. Open
if r.Metadata.FilmDate != nil {
filmDate = *r.Metadata.FilmDate
}
Avoid deeply nested control flow statements. Open
if err != nil {
return nil, nil, errors.Wrap(err, "Create declamation content unit")
}
Function handleSirtutim
has 6 return statements (exceeds 4 allowed). Open
func handleSirtutim(exec boil.Executor, input interface{}) (*models.Operation, []events.Event, error) {
r := input.(SirtutimRequest)
log.Info("Creating operation")
operation, err := CreateOperation(exec, common.OP_SIRTUTIM, r.Operation, nil)
Function handleTrim
has 6 return statements (exceeds 4 allowed). Open
func handleTrim(exec boil.Executor, input interface{}) (*models.Operation, []events.Event, error) {
r := input.(TrimRequest)
// Fetch parent files
original, _, err := FindFileBySHA1(exec, r.OriginalSha1)
Function handleJoin
has 6 return statements (exceeds 4 allowed). Open
func handleJoin(exec boil.Executor, input interface{}) (*models.Operation, []events.Event, error) {
r := input.(JoinRequest)
// Fetch input files
inOriginals := make([]*models.File, 0)
Function handleDemux
has 5 return statements (exceeds 4 allowed). Open
func handleDemux(exec boil.Executor, input interface{}) (*models.Operation, []events.Event, error) {
r := input.(DemuxRequest)
parent, _, err := FindFileBySHA1(exec, r.Sha1)
if err != nil {
Function DescendantUnitsHandler
has 5 return statements (exceeds 4 allowed). Open
func DescendantUnitsHandler(c *gin.Context) {
mdb := c.MustGet("MDB").(*sql.DB)
f, _, err := FindFileBySHA1(mdb, c.Param("sha1"))
if err != nil {
Function removeDescendants
has 5 return statements (exceeds 4 allowed). Open
func removeDescendants(exec boil.Executor, file *models.File) ([]events.Event, error) {
evnts := make([]events.Event, 0)
if file.RemovedAt.Valid {
return evnts, nil
}
Similar blocks of code found in 2 locations. Consider refactoring. Open
if r.Proxy != nil {
proxy, _, err = FindFileBySHA1(exec, r.Proxy.Sha1)
if err != nil {
return nil, nil, errors.Wrap(err, "Lookup proxy file")
}
- 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 193.
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 2 locations. Consider refactoring. Open
if r.Source != nil {
source, _, err = FindFileBySHA1(exec, r.Source.Sha1)
if err != nil {
return nil, nil, errors.Wrap(err, "Lookup source file")
}
- 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 193.
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 2 locations. Consider refactoring. Open
if r.Proxy != nil {
log.Info("Creating proxy")
props = map[string]interface{}{
"duration": r.Proxy.Duration,
}
- 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 112.
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 2 locations. Consider refactoring. Open
if r.Proxy != nil {
log.Info("Creating joined proxy")
props = map[string]interface{}{
"duration": r.Proxy.Duration,
}
- 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 112.
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