File encoder.go
has 1214 lines of code (exceeds 500 allowed). Consider refactoring. Wontfix
// Copyright (c) 2020-2023 Ozan Hacıbekiroğlu.
// Use of this source code is governed by a MIT License
// that can be found in the LICENSE file.
package encoder
Function DecodeObject
has a Cognitive Complexity of 60 (exceeds 20 allowed). Consider refactoring. Wontfix
func DecodeObject(r io.Reader) (ugo.Object, error) {
btype, err := readByteFrom(r)
if err != nil {
return nil, 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
Function DecodeObject
has 138 lines of code (exceeds 50 allowed). Consider refactoring. Wontfix
func DecodeObject(r io.Reader) (ugo.Object, error) {
btype, err := readByteFrom(r)
if err != nil {
return nil, err
}
Function DecodeObject
has 33 return statements (exceeds 4 allowed). Wontfix
func DecodeObject(r io.Reader) (ugo.Object, error) {
btype, err := readByteFrom(r)
if err != nil {
return nil, err
}
Method CompiledFunction.UnmarshalBinary
has a Cognitive Complexity of 32 (exceeds 20 allowed). Consider refactoring. Wontfix
func (o *CompiledFunction) UnmarshalBinary(data []byte) error {
if len(data) < 2 || data[0] != binCompiledFunctionV1 {
return errors.New("invalid ugo.CompiledFunction data")
}
- 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 Bytecode.bytecodeV1Decoder
has a Cognitive Complexity of 29 (exceeds 20 allowed). Consider refactoring. Wontfix
func (bc *Bytecode) bytecodeV1Decoder(r *bytes.Buffer) error {
for {
field, err := r.ReadByte()
if err != nil {
if err == io.EOF {
- 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 CompiledFunction.UnmarshalBinary
has 64 lines of code (exceeds 50 allowed). Consider refactoring. Wontfix
func (o *CompiledFunction) UnmarshalBinary(data []byte) error {
if len(data) < 2 || data[0] != binCompiledFunctionV1 {
return errors.New("invalid ugo.CompiledFunction data")
}
Method CompiledFunction.UnmarshalBinary
has 11 return statements (exceeds 4 allowed). Wontfix
func (o *CompiledFunction) UnmarshalBinary(data []byte) error {
if len(data) < 2 || data[0] != binCompiledFunctionV1 {
return errors.New("invalid ugo.CompiledFunction data")
}
Method Bytecode.bytecodeV1Encoder
has 10 return statements (exceeds 4 allowed). Wontfix
func (bc *Bytecode) bytecodeV1Encoder(w io.Writer) (err error) {
if err = putBytecodeHeader(w); err != nil {
return
}
Method Bytecode.bytecodeV1Decoder
has 8 return statements (exceeds 4 allowed). Wontfix
func (bc *Bytecode) bytecodeV1Decoder(r *bytes.Buffer) error {
for {
field, err := r.ReadByte()
if err != nil {
if err == io.EOF {
Method Map.UnmarshalBinary
has 8 return statements (exceeds 4 allowed). Wontfix
func (o *Map) UnmarshalBinary(data []byte) error {
if len(data) < 2 || data[0] != binMapV1 {
return errors.New("invalid ugo.Map data")
}
Method SourceFile.UnmarshalBinary
has 7 return statements (exceeds 4 allowed). Wontfix
func (sf *SourceFile) UnmarshalBinary(data []byte) error {
rd := bytes.NewReader(data)
obj, err := DecodeObject(rd)
if err != nil {
Method varintConv.read
has 7 return statements (exceeds 4 allowed). Wontfix
func (vi *varintConv) read() (value int64, err error) {
var n byte
n, err = vi.reader.ReadByte()
if err != nil {
return
Method Char.UnmarshalBinary
has 7 return statements (exceeds 4 allowed). Wontfix
func (o *Char) UnmarshalBinary(data []byte) error {
if len(data) < 2 || data[0] != binCharV1 {
return errors.New("invalid ugo.Char data")
}
Method Array.UnmarshalBinary
has 7 return statements (exceeds 4 allowed). Wontfix
func (o *Array) UnmarshalBinary(data []byte) error {
if len(data) < 2 || data[0] != binArrayV1 {
return errors.New("invalid ugo.Array data")
}
Method varintConv.readBytes
has 7 return statements (exceeds 4 allowed). Wontfix
func (vi *varintConv) readBytes(r io.Reader) (value int64, readBytes []byte, err error) {
var n byte
n, err = readByteFrom(r)
if err != nil {
return
Method BuiltinFunction.UnmarshalBinary
has 7 return statements (exceeds 4 allowed). Wontfix
func (o *BuiltinFunction) UnmarshalBinary(data []byte) error {
if len(data) < 2 || data[0] != binBuiltinFunctionV1 {
return errors.New("invalid ugo.BuiltinFunction data")
}
Method SourceFileSet.UnmarshalBinary
has 7 return statements (exceeds 4 allowed). Wontfix
func (sfs *SourceFileSet) UnmarshalBinary(data []byte) error {
rd := bytes.NewReader(data)
var vi varintConv
vi.reader = rd
v, err := vi.read()
Method Uint.UnmarshalBinary
has 6 return statements (exceeds 4 allowed). Wontfix
func (o *Uint) UnmarshalBinary(data []byte) error {
if len(data) < 2 || data[0] != binUintV1 {
return errors.New("invalid ugo.Uint data")
}
Method Float.UnmarshalBinary
has 6 return statements (exceeds 4 allowed). Wontfix
func (o *Float) UnmarshalBinary(data []byte) error {
if len(data) < 2 || data[0] != binFloatV1 {
return errors.New("invalid ugo.Float data")
}
Method Int.UnmarshalBinary
has 6 return statements (exceeds 4 allowed). Wontfix
func (o *Int) UnmarshalBinary(data []byte) error {
if len(data) < 2 || data[0] != binIntV1 {
return errors.New("invalid ugo.Int data")
}
Function toVarint
has 5 return statements (exceeds 4 allowed). Wontfix
func toVarint(data []byte) (value int64, offset int, err error) {
size := int(data[0])
if size == 0 {
offset = 1
return
Method String.UnmarshalBinary
has 5 return statements (exceeds 4 allowed). Wontfix
func (o *String) UnmarshalBinary(data []byte) error {
if len(data) < 2 || data[0] != binStringV1 {
return errors.New("invalid ugo.String data")
}
Function readByteFrom
has 5 return statements (exceeds 4 allowed). Wontfix
func readByteFrom(r io.Reader) (byte, error) {
if br, ok := r.(io.ByteReader); ok {
return br.ReadByte()
}
Method Bytes.UnmarshalBinary
has 5 return statements (exceeds 4 allowed). Wontfix
func (o *Bytes) UnmarshalBinary(data []byte) error {
if len(data) < 2 || data[0] != binBytesV1 {
return errors.New("invalid ugo.Bytes data")
}
Method Function.UnmarshalBinary
has 5 return statements (exceeds 4 allowed). Wontfix
func (o *Function) UnmarshalBinary(data []byte) error {
if len(data) < 2 || data[0] != binFunctionV1 {
return errors.New("invalid ugo.Function data")
}
Method Bytecode.bytecodeV1Encoder
has a Cognitive Complexity of 21 (exceeds 20 allowed). Consider refactoring. Wontfix
func (bc *Bytecode) bytecodeV1Encoder(w io.Writer) (err error) {
if err = putBytecodeHeader(w); err != nil {
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"
Further reading
Similar blocks of code found in 2 locations. Consider refactoring. Wontfix
func (o *Uint) UnmarshalBinary(data []byte) error {
if len(data) < 2 || data[0] != binUintV1 {
return errors.New("invalid ugo.Uint data")
}
- 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 204.
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. Wontfix
func (o *Int) UnmarshalBinary(data []byte) error {
if len(data) < 2 || data[0] != binIntV1 {
return errors.New("invalid ugo.Int data")
}
- 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 204.
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. Wontfix
func (o *Function) MarshalBinary() ([]byte, error) {
s, err := String(o.Name).MarshalBinary()
if err != nil {
return nil, err
}
- 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 162.
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. Wontfix
func (o *BuiltinFunction) MarshalBinary() ([]byte, error) {
// Note: use string name instead of index of builtin
s, err := String(o.Name).MarshalBinary()
if err != nil {
return nil, err
- 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 162.
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. Wontfix
func (o Char) MarshalBinary() ([]byte, error) {
buf := make([]byte, 2+binary.MaxVarintLen32)
buf[0] = binCharV1
if o == 0 {
buf[1] = 0
- 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 136.
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. Wontfix
func (o Uint) MarshalBinary() ([]byte, error) {
buf := make([]byte, 2+binary.MaxVarintLen64)
buf[0] = binUintV1
if o == 0 {
buf[1] = 0
- 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 136.
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. Wontfix
func (o Int) MarshalBinary() ([]byte, error) {
buf := make([]byte, 2+binary.MaxVarintLen64)
buf[0] = binIntV1
if o == 0 {
- 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 136.
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
Identical blocks of code found in 2 locations. Consider refactoring. Wontfix
if m := marshaler(v); m != nil {
d, err := m.MarshalBinary()
if err != nil {
return nil, err
}
- 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 111.
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
Identical blocks of code found in 2 locations. Consider refactoring. Wontfix
if m := marshaler(v); m != nil {
d, err := m.MarshalBinary()
if err != nil {
return nil, err
}
- 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 111.
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