sahat/satellizer

View on GitHub
examples/server/python/app.py

Summary

Maintainability
F
1 wk
Test Coverage

File app.py has 350 lines of code (exceeds 250 allowed). Consider refactoring.
Open

from datetime import datetime, timedelta
import os
import jwt
import json
import requests
Severity: Minor
Found in examples/server/python/app.py - About 4 hrs to fix

    Function __init__ has 9 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def __init__(self, email=None, password=None, display_name=None,
    Severity: Major
    Found in examples/server/python/app.py - About 1 hr to fix

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

          def __init__(self, email=None, password=None, display_name=None,
                       facebook=None, github=None, google=None, linkedin=None,
                       twitter=None, bitbucket=None):
              if email:
                  self.email = email.lower()
      Severity: Minor
      Found in examples/server/python/app.py - 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 bitbucket has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

      def bitbucket():
          access_token_url = 'https://bitbucket.org/site/oauth2/access_token'
          users_api_url = 'https://api.bitbucket.org/2.0/user'
          auth_encoded = base64.b64encode(
              "{0}:{1}".format(request.json['clientId'],
      Severity: Minor
      Found in examples/server/python/app.py - 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 google has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

      def google():
          access_token_url = 'https://accounts.google.com/o/oauth2/token'
          people_api_url = 'https://www.googleapis.com/plus/v1/people/me/openIdConnect'
      
          payload = dict(client_id=request.json['clientId'],
      Severity: Minor
      Found in examples/server/python/app.py - About 35 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 github has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

      def github():
          access_token_url = 'https://github.com/login/oauth/access_token'
          users_api_url = 'https://api.github.com/user'
      
          params = {
      Severity: Minor
      Found in examples/server/python/app.py - About 35 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 facebook has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

      def facebook():
          access_token_url = 'https://graph.facebook.com/v2.3/oauth/access_token'
          graph_api_url = 'https://graph.facebook.com/v2.3/me'
      
          params = {
      Severity: Minor
      Found in examples/server/python/app.py - About 35 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 linkedin has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

      def linkedin():
          access_token_url = 'https://www.linkedin.com/uas/oauth2/accessToken'
          people_api_url = 'https://api.linkedin.com/v1/people/~:(id,first-name,last-name,email-address)'
      
          payload = dict(client_id=request.json['clientId'],
      Severity: Minor
      Found in examples/server/python/app.py - About 35 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

      Avoid too many return statements within this function.
      Open

          return jsonify(token=token)
      Severity: Major
      Found in examples/server/python/app.py - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

            return jsonify(token=token)
        Severity: Major
        Found in examples/server/python/app.py - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

              return jsonify(token=token)
          Severity: Major
          Found in examples/server/python/app.py - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                return jsonify(token=token)
            Severity: Major
            Found in examples/server/python/app.py - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                  return jsonify(token=token)
              Severity: Major
              Found in examples/server/python/app.py - About 30 mins to fix

                Function twitter has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                def twitter():
                    request_token_url = 'https://api.twitter.com/oauth/request_token'
                    access_token_url = 'https://api.twitter.com/oauth/access_token'
                
                    if request.json.get('oauth_token') and request.json.get('oauth_verifier'):
                Severity: Minor
                Found in examples/server/python/app.py - 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

                Function login_required has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                def login_required(f):
                    @wraps(f)
                    def decorated_function(*args, **kwargs):
                        if not request.headers.get('Authorization'):
                            response = jsonify(message='Missing authorization header')
                Severity: Minor
                Found in examples/server/python/app.py - 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

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

                    if request.headers.get('Authorization'):
                        user = User.query.filter_by(bitbucket=profile['uuid']).first()
                        if user:
                            response = jsonify(message='There is already a Bitbucket account that belongs to you')
                            response.status_code = 409
                Severity: Major
                Found in examples/server/python/app.py and 2 other locations - About 1 day to fix
                examples/server/python/app.py on lines 171..190
                examples/server/python/app.py on lines 282..300

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

                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

                    if request.headers.get('Authorization'):
                        user = User.query.filter_by(google=profile['sub']).first()
                        if user:
                            response = jsonify(message='There is already a Google account that belongs to you')
                            response.status_code = 409
                Severity: Major
                Found in examples/server/python/app.py and 2 other locations - About 1 day to fix
                examples/server/python/app.py on lines 171..190
                examples/server/python/app.py on lines 427..446

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

                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

                    if request.headers.get('Authorization'):
                        user = User.query.filter_by(facebook=profile['id']).first()
                        if user:
                            response = jsonify(message='There is already a Facebook account that belongs to you')
                            response.status_code = 409
                Severity: Major
                Found in examples/server/python/app.py and 2 other locations - About 1 day to fix
                examples/server/python/app.py on lines 282..300
                examples/server/python/app.py on lines 427..446

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

                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 2 locations. Consider refactoring.
                Open

                    payload = dict(client_id=request.json['clientId'],
                                   redirect_uri=request.json['redirectUri'],
                                   client_secret=app.config['LINKEDIN_SECRET'],
                                   code=request.json['code'],
                Severity: Major
                Found in examples/server/python/app.py and 1 other location - About 2 hrs to fix
                examples/server/python/app.py on lines 266..269

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

                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 2 locations. Consider refactoring.
                Open

                    payload = dict(client_id=request.json['clientId'],
                                   redirect_uri=request.json['redirectUri'],
                                   client_secret=app.config['GOOGLE_SECRET'],
                                   code=request.json['code'],
                Severity: Major
                Found in examples/server/python/app.py and 1 other location - About 2 hrs to fix
                examples/server/python/app.py on lines 321..324

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

                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 2 locations. Consider refactoring.
                Open

                    params = {
                        'client_id': request.json['clientId'],
                        'redirect_uri': request.json['redirectUri'],
                        'client_secret': app.config['GITHUB_SECRET'],
                        'code': request.json['code']
                Severity: Major
                Found in examples/server/python/app.py and 1 other location - About 1 hr to fix
                examples/server/python/app.py on lines 155..159

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

                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 2 locations. Consider refactoring.
                Open

                    params = {
                        'client_id': request.json['clientId'],
                        'redirect_uri': request.json['redirectUri'],
                        'client_secret': app.config['FACEBOOK_SECRET'],
                        'code': request.json['code']
                Severity: Major
                Found in examples/server/python/app.py and 1 other location - About 1 hr to fix
                examples/server/python/app.py on lines 209..213

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

                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