superdesk/superdesk-client-core

View on GitHub
scripts/apps/search/directives/SavedSearchManageSubscribers.ts

Summary

Maintainability
F
5 days
Test Coverage

Function SavedSearchManageSubscribers has 200 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export function SavedSearchManageSubscribers(asset, userList, api, modal, desks) {
    return {
        scope: {
            savedSearch: '=',
            setIsManagingSubscriptions: '=',
Severity: Major
Found in scripts/apps/search/directives/SavedSearchManageSubscribers.ts - About 1 day to fix

    Function link has 190 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

            link: function(scope: IScope) {
                const getDefaults = (): IModel => ({
                    userSubscribers: [],
                    subscriptionInCreateOrEditMode: null,
                    currentlySelectedInterval: null,
    Severity: Major
    Found in scripts/apps/search/directives/SavedSearchManageSubscribers.ts - About 7 hrs to fix

      Function SavedSearchManageSubscribers has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
      Open

      export function SavedSearchManageSubscribers(asset, userList, api, modal, desks) {
          return {
              scope: {
                  savedSearch: '=',
                  setIsManagingSubscriptions: '=',
      Severity: Minor
      Found in scripts/apps/search/directives/SavedSearchManageSubscribers.ts - About 3 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 saveChanges has 54 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

                  scope.saveChanges = () => {
                      const {user_subscriptions, desk_subscriptions} = scope.savedSearch.subscribers;
                      const {subscriptionInCreateOrEditMode} = scope.wrapper;
      
                      let nextUserSubscriptions = scope.savedSearch.subscribers.user_subscriptions;
      Severity: Major
      Found in scripts/apps/search/directives/SavedSearchManageSubscribers.ts - About 2 hrs to fix

        File SavedSearchManageSubscribers.ts has 254 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        import {
            ISavedSearch,
            updateSubscribers,
            unsubscribeUser,
            unsubscribeDesk,
        Severity: Minor
        Found in scripts/apps/search/directives/SavedSearchManageSubscribers.ts - About 2 hrs to fix

          Function SavedSearchManageSubscribers has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

          export function SavedSearchManageSubscribers(asset, userList, api, modal, desks) {
          Severity: Minor
          Found in scripts/apps/search/directives/SavedSearchManageSubscribers.ts - About 35 mins to fix

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

                            if (isUserSubscription(subscriptionInCreateOrEditMode)) {
                                const userAlreadySubscribed = user_subscriptions.some(
                                    (subscription) => subscription.user === subscriptionInCreateOrEditMode.user,
                                );
            
            
            scripts/apps/search/directives/SavedSearchManageSubscribers.ts on lines 170..190

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

            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

                            if (isDeskSubscription(subscriptionInCreateOrEditMode)) {
                                const deskAlreadySubscribed = desk_subscriptions.some(
                                    (subscription) => subscription.desk === subscriptionInCreateOrEditMode.desk,
                                );
            
            
            scripts/apps/search/directives/SavedSearchManageSubscribers.ts on lines 146..166

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

            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

                        scope.editDeskSubscription = (desk: IDesk) => {
                            scope.wrapper.subscriptionInCreateOrEditMode = scope.savedSearch.subscribers.desk_subscriptions.find(
                                (subscription) => subscription.desk === desk._id,
                            );
                        };
            scripts/apps/search/directives/SavedSearchManageSubscribers.ts on lines 236..240

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

            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

                        scope.editUserSubscription = (user: IUser) => {
                            scope.wrapper.subscriptionInCreateOrEditMode = scope.savedSearch.subscribers.user_subscriptions.find(
                                (subscription) => subscription.user === user._id,
                            );
                        };
            scripts/apps/search/directives/SavedSearchManageSubscribers.ts on lines 242..246

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

            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

            function isDeskSubscription(x: IModel['subscriptionInCreateOrEditMode']): x is IDeskSubscription {
                return x != null && (x as IDeskSubscription).desk !== undefined;
            }
            scripts/apps/search/directives/SavedSearchManageSubscribers.ts on lines 28..30

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

            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

            function isUserSubscription(x: IModel['subscriptionInCreateOrEditMode']): x is IUserSubscription {
                return x != null && (x as IUserSubscription).user !== undefined;
            }
            scripts/apps/search/directives/SavedSearchManageSubscribers.ts on lines 32..34

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

            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

                        scope.subscribeUser = (user: IUser) => {
                            scope.wrapper.subscriptionInCreateOrEditMode = {
                                user: user._id,
                                scheduling: null,
                            };
            Severity: Minor
            Found in scripts/apps/search/directives/SavedSearchManageSubscribers.ts and 1 other location - About 55 mins to fix
            scripts/apps/search/directives/SavedSearchManageSubscribers.ts on lines 133..138

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

            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

                        scope.subscribeDesk = (desk: IDesk) => {
                            scope.wrapper.subscriptionInCreateOrEditMode = {
                                desk: desk._id,
                                scheduling: null,
                            };
            Severity: Minor
            Found in scripts/apps/search/directives/SavedSearchManageSubscribers.ts and 1 other location - About 55 mins to fix
            scripts/apps/search/directives/SavedSearchManageSubscribers.ts on lines 126..131

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

            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

                            modal.confirm(
                                gettext('Are you sure to remove this subscription?'),
                                gettext('Unsubscribe user'),
                            )
                                .then(() =>
            Severity: Minor
            Found in scripts/apps/search/directives/SavedSearchManageSubscribers.ts and 1 other location - About 40 mins to fix
            scripts/apps/search/directives/SavedSearchManageSubscribers.ts on lines 225..234

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

            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

                            modal.confirm(
                                gettext('Are you sure to remove this subscription?'),
                                gettext('Unsubscribe desk'),
                            )
                                .then(() =>
            Severity: Minor
            Found in scripts/apps/search/directives/SavedSearchManageSubscribers.ts and 1 other location - About 40 mins to fix
            scripts/apps/search/directives/SavedSearchManageSubscribers.ts on lines 213..222

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

            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

                                    if (scope.savedSearch.subscribers == null) {
                                        scope.savedSearch.subscribers = {
                                            user_subscriptions: [],
                                            desk_subscriptions: [],
                                        };
            Severity: Minor
            Found in scripts/apps/search/directives/SavedSearchManageSubscribers.ts and 1 other location - About 35 mins to fix
            scripts/apps/search/directives/SavedSearchEditOwnSubscription.ts on lines 76..81

            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

                            if (scope.savedSearch.subscribers.user_subscriptions != null) {
                                count += scope.savedSearch.subscribers.user_subscriptions.length;
                            }
            Severity: Minor
            Found in scripts/apps/search/directives/SavedSearchManageSubscribers.ts and 1 other location - About 35 mins to fix
            scripts/apps/search/directives/SavedSearchManageSubscribers.ts on lines 109..111

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

            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

                            if (scope.savedSearch.subscribers.desk_subscriptions != null) {
                                count += scope.savedSearch.subscribers.desk_subscriptions.length;
                            }
            Severity: Minor
            Found in scripts/apps/search/directives/SavedSearchManageSubscribers.ts and 1 other location - About 35 mins to fix
            scripts/apps/search/directives/SavedSearchManageSubscribers.ts on lines 105..107

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

            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