wechaty/go-wechaty

View on GitHub
wechaty/user/message.go

Summary

Maintainability
C
1 day
Test Coverage
F
0%

Method Message.MentionList has a Cognitive Complexity of 23 (exceeds 14 allowed). Consider refactoring.
Open

func (m *Message) MentionList() []_interface.IContact {
    room := m.Room()
    if m.Type() != schemas.MessageTypeText || room == nil {
        return nil
    }
Severity: Minor
Found in wechaty/user/message.go - About 1 hr to fix

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 Message.MentionList has 52 lines of code (exceeds 45 allowed). Consider refactoring.
Open

func (m *Message) MentionList() []_interface.IContact {
    room := m.Room()
    if m.Type() != schemas.MessageTypeText || room == nil {
        return nil
    }
Severity: Minor
Found in wechaty/user/message.go - About 1 hr to fix

    Similar blocks of code found in 3 locations. Consider refactoring.
    Open

    func (m *Message) ToUrlLink() (*UrlLink, error) {
        if m.Type() != schemas.MessageTypeURL {
            return nil, errors.New("message not a Url Link")
        }
        urlPayload, err := m.GetPuppet().MessageURL(m.id)
    Severity: Major
    Found in wechaty/user/message.go and 2 other locations - About 1 hr to fix
    wechaty/user/message.go on lines 422..431
    wechaty/user/message.go on lines 433..443

    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 109.

    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

    Further Reading

    Similar blocks of code found in 3 locations. Consider refactoring.
    Open

    func (m *Message) ToMiniProgram() (*MiniProgram, error) {
        if m.Type() != schemas.MessageTypeMiniProgram {
            return nil, errors.New("message not a MiniProgram")
        }
        miniProgramPayload, err := m.GetPuppet().MessageMiniProgram(m.id)
    Severity: Major
    Found in wechaty/user/message.go and 2 other locations - About 1 hr to fix
    wechaty/user/message.go on lines 411..420
    wechaty/user/message.go on lines 433..443

    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 109.

    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

    Further Reading

    Similar blocks of code found in 3 locations. Consider refactoring.
    Open

    func (m *Message) ToLocation() (*Location, error) {
        if m.Type() != schemas.MessageTypeLocation {
            return nil, errors.New("message not a Location")
        }
    
    
    Severity: Major
    Found in wechaty/user/message.go and 2 other locations - About 1 hr to fix
    wechaty/user/message.go on lines 411..420
    wechaty/user/message.go on lines 422..431

    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 109.

    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

    Further Reading

    Similar blocks of code found in 3 locations. Consider refactoring.
    Open

    func (m *Message) Listener() _interface.IContact {
        if m.payload.ListenerId == "" {
            return nil
        }
        return m.GetWechaty().Contact().Load(m.payload.ListenerId)
    Severity: Major
    Found in wechaty/user/message.go and 2 other locations - About 45 mins to fix
    wechaty/user/message.go on lines 117..122
    wechaty/user/room.go on lines 266..271

    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 86.

    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

    Further Reading

    Similar blocks of code found in 3 locations. Consider refactoring.
    Open

    func (m *Message) Talker() _interface.IContact {
        if m.payload.TalkerId == "" {
            return nil
        }
        return m.GetWechaty().Contact().Load(m.payload.TalkerId)
    Severity: Major
    Found in wechaty/user/message.go and 2 other locations - About 45 mins to fix
    wechaty/user/message.go on lines 216..221
    wechaty/user/room.go on lines 266..271

    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 86.

    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

    Further Reading

    var listenerId should be listenerID
    Open

        listenerId := m.payload.ListenerId
    Severity: Minor
    Found in wechaty/user/message.go by golint

    method sayId should be sayID
    Open

    func (m *Message) sayId() (string, error) {
    Severity: Minor
    Found in wechaty/user/message.go by golint

    exported method Message.Ready should have comment or be unexported
    Open

    func (m *Message) Ready() (err error) {
    Severity: Minor
    Found in wechaty/user/message.go by golint

    exported method Message.MentionSelf should have comment or be unexported
    Open

    func (m *Message) MentionSelf() bool {
    Severity: Minor
    Found in wechaty/user/message.go by golint

    exported method Message.MentionText should have comment or be unexported
    Open

    func (m *Message) MentionText() string {
    Severity: Minor
    Found in wechaty/user/message.go by golint

    exported type Message should have comment or be unexported
    Open

    type Message struct {
    Severity: Minor
    Found in wechaty/user/message.go by golint

    exported method Message.Age should have comment or be unexported
    Open

    func (m *Message) Age() time.Duration {
    Severity: Minor
    Found in wechaty/user/message.go by golint

    method ToUrlLink should be ToURLLink
    Open

    func (m *Message) ToUrlLink() (*UrlLink, error) {
    Severity: Minor
    Found in wechaty/user/message.go by golint

    exported method Message.ToMiniProgram should have comment or be unexported
    Open

    func (m *Message) ToMiniProgram() (*MiniProgram, error) {
    Severity: Minor
    Found in wechaty/user/message.go by golint

    var talkerId should be talkerID
    Open

        talkerId := m.payload.TalkerId
    Severity: Minor
    Found in wechaty/user/message.go by golint

    var roomId should be roomID
    Open

        roomId := m.payload.RoomId
    Severity: Minor
    Found in wechaty/user/message.go by golint

    exported method Message.ToLocation should have comment or be unexported
    Open

    func (m *Message) ToLocation() (*Location, error) {
    Severity: Minor
    Found in wechaty/user/message.go by golint

    var roomId should be roomID
    Open

        roomId := m.payload.RoomId
    Severity: Minor
    Found in wechaty/user/message.go by golint

    exported method Message.IsReady should have comment or be unexported
    Open

    func (m *Message) IsReady() bool {
    Severity: Minor
    Found in wechaty/user/message.go by golint

    method parameter contactOrRoomId should be contactOrRoomID
    Open

    func (m *Message) Forward(contactOrRoomId string) error {
    Severity: Minor
    Found in wechaty/user/message.go by golint

    var originalMessageId should be originalMessageID
    Open

        originalMessageId := m.Text()
    Severity: Minor
    Found in wechaty/user/message.go by golint

    exported method Message.ToUrlLink should have comment or be unexported
    Open

    func (m *Message) ToUrlLink() (*UrlLink, error) {
    Severity: Minor
    Found in wechaty/user/message.go by golint

    var conversationId should be conversationID
    Open

        conversationId, err := m.sayId()
    Severity: Minor
    Found in wechaty/user/message.go by golint

    There are no issues that match your filters.

    Category
    Status