type/encoding/encoding.go
Method qiDecoder.value
has a Cognitive Complexity of 44 (exceeds 20 allowed). Consider refactoring. Open
Open
func (q qiDecoder) value(v reflect.Value) error {
switch v.Kind() {
case reflect.Interface:
i := v.Interface()
b, ok := i.(BinaryDecoder)
- 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 qiDecoder.value
has 112 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func (q qiDecoder) value(v reflect.Value) error {
switch v.Kind() {
case reflect.Interface:
i := v.Interface()
b, ok := i.(BinaryDecoder)
Method qiEncoder.value
has a Cognitive Complexity of 32 (exceeds 20 allowed). Consider refactoring. Open
Open
func (q qiEncoder) value(v reflect.Value) error {
switch v.Kind() {
case reflect.Interface:
i := v.Interface()
w, ok := i.(BinaryEncoder)
- 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 qiDecoder.value
has 21 return statements (exceeds 4 allowed). Open
Open
func (q qiDecoder) value(v reflect.Value) error {
switch v.Kind() {
case reflect.Interface:
i := v.Interface()
b, ok := i.(BinaryDecoder)
Method qiEncoder.value
has 71 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func (q qiEncoder) value(v reflect.Value) error {
switch v.Kind() {
case reflect.Interface:
i := v.Interface()
w, ok := i.(BinaryEncoder)
Method qiDecoder.Decode
has 13 return statements (exceeds 4 allowed). Open
Open
func (q qiDecoder) Decode(x interface{}) (err error) {
switch v := x.(type) {
case CustomDecoder:
return v.Decode(q)
case BinaryDecoder:
Method qiDecoder.Decode
has 55 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func (q qiDecoder) Decode(x interface{}) (err error) {
switch v := x.(type) {
case CustomDecoder:
return v.Decode(q)
case BinaryDecoder:
Method qiEncoder.value
has 10 return statements (exceeds 4 allowed). Open
Open
func (q qiEncoder) value(v reflect.Value) error {
switch v.Kind() {
case reflect.Interface:
i := v.Interface()
w, ok := i.(BinaryEncoder)
Method qiDecoder.mapValue
has 8 return statements (exceeds 4 allowed). Open
Open
func (q qiDecoder) mapValue(v reflect.Value) error {
length, err := basic.ReadInt32(q.r)
if err != nil {
return fmt.Errorf("failed to read vector size: %w", err)
}
Method qiDecoder.sliceValue
has 8 return statements (exceeds 4 allowed). Open
Open
func (q qiDecoder) sliceValue(v reflect.Value) error {
length, err := basic.ReadInt32(q.r)
if err != nil {
return fmt.Errorf("failed to read vector size: %w", err)
}
Avoid deeply nested control flow statements. Open
Open
if err != nil {
return fmt.Errorf("read %v: %w",
v.Type().Name(), err)
}
Method qiDecoder.readValue
has 5 return statements (exceeds 4 allowed). Open
Open
func (q qiDecoder) readValue(typ reflect.Type) (v reflect.Value, err error) {
if typ.Kind() == reflect.Interface {
// not much we can do here. let's handle the
// special case of value.Value
if typ.Name() == "Value" {
exported type Decoder should have comment or be unexported Open
Open
type Decoder interface {
- Exclude checks
if block ends with a return statement, so drop this else and outdent its block Open
Open
} else {
- Exclude checks
exported type BinaryDecoder should have comment or be unexported Open
Open
type BinaryDecoder interface {
- Exclude checks
exported type Writer should have comment or be unexported Open
Open
type Writer interface {
- Exclude checks
exported type BinaryEncoder should have comment or be unexported Open
Open
type BinaryEncoder interface {
- Exclude checks
exported type Encoder should have comment or be unexported Open
Open
type Encoder interface {
- Exclude checks
exported function NewEncoder should have comment or be unexported Open
Open
func NewEncoder(c Capability, w io.Writer) Encoder {
- Exclude checks
exported type CustomDecoder should have comment or be unexported Open
Open
type CustomDecoder interface {
- Exclude checks
exported type CustomEncoder should have comment or be unexported Open
Open
type CustomEncoder interface {
- Exclude checks
exported function NewDecoder should have comment or be unexported Open
Open
func NewDecoder(c Capability, r io.Reader) Decoder {
- Exclude checks