meifamily/ptt-alertor

View on GitHub
ptt/web/crawler.go

Summary

Maintainability
C
1 day
Test Coverage

Function FetchArticle has a Cognitive Complexity of 36 (exceeds 20 allowed). Consider refactoring.
Open

func FetchArticle(board, articleCode string) (article.Article, error) {
    reqURL := makeArticleURL(board, articleCode)
    htmlNodes, err := fetchHTML(reqURL)
    if err != nil {
        return article.Article{}, err
Severity: Minor
Found in ptt/web/crawler.go - About 2 hrs 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

Function FetchArticles has a Cognitive Complexity of 34 (exceeds 20 allowed). Consider refactoring.
Open

func FetchArticles(board string, page int) (articles article.Articles, err error) {
    reqURL := makeBoardURL(board, page)
    htmlNodes, err := fetchHTML(reqURL)
    if err != nil {
        return nil, err
Severity: Minor
Found in ptt/web/crawler.go - About 2 hrs 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

Function FetchArticle has 66 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func FetchArticle(board, articleCode string) (article.Article, error) {
    reqURL := makeArticleURL(board, articleCode)
    htmlNodes, err := fetchHTML(reqURL)
    if err != nil {
        return article.Article{}, err
Severity: Minor
Found in ptt/web/crawler.go - About 1 hr to fix

    Function fetchHTML has 6 return statements (exceeds 4 allowed).
    Open

    func fetchHTML(reqURL string) (doc *html.Node, err error) {
        req, err := pttHttp.HttpRequest(reqURL)
        if err != nil {
            return nil, err
        }
    Severity: Major
    Found in ptt/web/crawler.go - About 40 mins to fix

      Function CurrentPage has 5 return statements (exceeds 4 allowed).
      Open

      func CurrentPage(board string) (int, error) {
          url := makeBoardURL(board, -1)
          htmlNodes, err := fetchHTML(url)
          if err != nil {
              return 0, err
      Severity: Major
      Found in ptt/web/crawler.go - About 35 mins to fix

        There are no issues that match your filters.

        Category
        Status