src/services/google/oauth.ts

Summary

Maintainability
B
5 hrs
Test Coverage
F
4%

Function fetchRefreshToken has 50 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function fetchRefreshToken(): Promise<boolean> {
  Log.d('fetchRefreshToken')
  return new Promise(async (resolve) => {
    const S = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
    const state = Array.from(crypto.getRandomValues(new Uint8Array(12)))
Severity: Minor
Found in src/services/google/oauth.ts - About 2 hrs to fix

    Function logout has 28 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      async logout(): Promise<boolean> {
        let logoutResult
    
        const tokenType = await Storage.get(STORAGE_KEY.TOKEN_TYPE)
        if (tokenType === TOKEN_TYPE.WEB) {
    Severity: Minor
    Found in src/services/google/oauth.ts - About 1 hr to fix

      Function ensureToken has 26 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        async ensureToken(): Promise<string> {
          const token = (await Storage.get(STORAGE_KEY.ACCESS_TOKEN)) as string
          try {
            const response = await fetch(
              `https://oauth2.googleapis.com/tokeninfo?access_token=${token}`,
      Severity: Minor
      Found in src/services/google/oauth.ts - About 1 hr to fix

        Function updateToken has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

          async updateToken(): Promise<boolean> {
            try {
              // Remove cached AuthToken if exists.
              const tokenType = await Storage.get(STORAGE_KEY.TOKEN_TYPE)
              const token = (await Storage.get(STORAGE_KEY.ACCESS_TOKEN)) as string
        Severity: Minor
        Found in src/services/google/oauth.ts - About 45 mins 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 ensureToken has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

          async ensureToken(): Promise<string> {
            const token = (await Storage.get(STORAGE_KEY.ACCESS_TOKEN)) as string
            try {
              const response = await fetch(
                `https://oauth2.googleapis.com/tokeninfo?access_token=${token}`,
        Severity: Minor
        Found in src/services/google/oauth.ts - About 25 mins 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

        There are no issues that match your filters.

        Category
        Status