AndrewWalsh/at-your-service

View on GitHub
demo/public/mockServiceWorker.js

Summary

Maintainability
F
1 wk
Test Coverage

Function getResponse has 62 lines of code (exceeds 25 allowed). Consider refactoring.
Open

async function getResponse(event, client, requestId) {
  const beforeRequestTime = Date.now()
  const { request } = event
  const clonedRequest = request.clone()

Severity: Major
Found in demo/public/mockServiceWorker.js - About 2 hrs to fix

    Function _createPayload has 36 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      async _createPayload(event, response, beforeRequestTime, afterRequestTime, requestBody) {
        const request = event.request
        const requestHeaders = {};
        for (const [key, value] of request.headers) {
          requestHeaders[key] = value;
    Severity: Minor
    Found in demo/public/mockServiceWorker.js - About 1 hr to fix

      Avoid too many return statements within this function.
      Open

            return passthrough()
      Severity: Major
      Found in demo/public/mockServiceWorker.js - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

          return passthrough()
        Severity: Major
        Found in demo/public/mockServiceWorker.js - About 30 mins to fix

          Identical blocks of code found in 2 locations. Consider refactoring.
          Open

          async function getResponse(event, client, requestId) {
            const beforeRequestTime = Date.now()
            const { request } = event
            const clonedRequest = request.clone()
          
          
          Severity: Major
          Found in demo/public/mockServiceWorker.js and 1 other location - About 3 days to fix
          docs/mockServiceWorker.js on lines 299..390

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

          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

          Identical blocks of code found in 2 locations. Consider refactoring.
          Open

          class FetchPayload {
            /**
             * Used as the message payload to the client
             * @param {Event} event - a fetch event
             * @param {Response} response - a response object from a fetch event
          Severity: Major
          Found in demo/public/mockServiceWorker.js and 1 other location - About 2 days to fix
          docs/mockServiceWorker.js on lines 3..86

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

          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

          Identical blocks of code found in 2 locations. Consider refactoring.
          Open

          self.addEventListener('message', async function (event) {
            const clientId = event.source.id
          
            if (!clientId || !self.clients) {
              return
          Severity: Major
          Found in demo/public/mockServiceWorker.js and 1 other location - About 1 day to fix
          docs/mockServiceWorker.js on lines 120..189

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

          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

          Identical blocks of code found in 2 locations. Consider refactoring.
          Open

          self.addEventListener('fetch', function (event) {
            const { request } = event
            const accept = request.headers.get('accept') || ''
          
            // Bypass server-sent events.
          Severity: Major
          Found in demo/public/mockServiceWorker.js and 1 other location - About 1 day to fix
          docs/mockServiceWorker.js on lines 191..242

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

          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

          Identical blocks of code found in 2 locations. Consider refactoring.
          Open

          async function handleRequest(event, requestId) {
            const client = await resolveMainClient(event)
            const response = await getResponse(event, client, requestId)
          
            // Send back the response clone for the "response:*" life-cycle events.
          Severity: Major
          Found in demo/public/mockServiceWorker.js and 1 other location - About 1 day to fix
          docs/mockServiceWorker.js on lines 244..270

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

          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

          Identical blocks of code found in 2 locations. Consider refactoring.
          Open

          async function resolveMainClient(event) {
            const client = await self.clients.get(event.clientId)
          
            if (client?.frameType === 'top-level') {
              return client
          Severity: Major
          Found in demo/public/mockServiceWorker.js and 1 other location - About 5 hrs to fix
          docs/mockServiceWorker.js on lines 276..297

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

          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

          Identical blocks of code found in 2 locations. Consider refactoring.
          Open

          function sendToClient(client, message) {
            return new Promise((resolve, reject) => {
              const channel = new MessageChannel()
          
              channel.port1.onmessage = (event) => {
          Severity: Major
          Found in demo/public/mockServiceWorker.js and 1 other location - About 4 hrs to fix
          docs/mockServiceWorker.js on lines 392..406

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

          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

          Identical blocks of code found in 2 locations. Consider refactoring.
          Open

          async function postMessageToAYS(event, type, payload) {
            const thisClient = await self.clients.get(event.clientId);
            if (thisClient) {
              thisClient.postMessage({ type, payload });
              thisClient
          Severity: Major
          Found in demo/public/mockServiceWorker.js and 1 other location - About 1 hr to fix
          docs/mockServiceWorker.js on lines 94..100

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

          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

          There are no issues that match your filters.

          Category
          Status